Skip to content

Commit 8584257

Browse files
thewheatchoran
authored andcommitted
Add support for snooze (#236)
1 parent 0ec97e7 commit 8584257

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,18 @@ AdminReply adminReply = new AdminReply(admin);
565565
adminReply.setMessageType("close");
566566
Conversation.reply("66", adminReply);
567567

568+
// admin snooze
569+
Admin admin = new Admin().setId("1");
570+
AdminReply adminReply = new AdminReply(admin);
571+
adminReply.setSnoozedUntil(1549092382);
572+
Conversation.reply("66", adminReply);
573+
574+
// admin open / unsnooze
575+
Admin admin = new Admin().setId("1");
576+
AdminReply adminReply = new AdminReply(admin);
577+
adminReply.setMessageType("open");
578+
Conversation.reply("66", adminReply);
579+
568580
// user reply
569581
User user1 = new User().setId("5310d8e8598c9a0b24000005");
570582
UserReply userReply = new UserReply(user1);

intercom-java/src/main/java/io/intercom/api/AdminReply.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public String getMessageType() {
3232
return reply.getMessageType();
3333
}
3434

35+
@JsonProperty("snoozed_until")
36+
public long getSnoozedUntil() {
37+
return reply.getSnoozedUntil();
38+
}
39+
3540
@JsonProperty("body")
3641
public String getBody() {
3742
return reply.getBody();
@@ -56,6 +61,9 @@ private String[] getAttachmentUrls() {
5661
@JsonProperty("assignee_id")
5762
private String assigneeID;
5863

64+
@JsonProperty("snoozed_until")
65+
private long snoozedUntil;
66+
5967
public AdminReply(Admin admin) {
6068
this.from = admin;
6169
}
@@ -74,6 +82,16 @@ public Reply<Admin> setAssigneeID(String assigneeID) {
7482
return this;
7583
}
7684

85+
public long getSnoozedUntil() {
86+
return snoozedUntil;
87+
}
88+
89+
public Reply<Admin> setSnoozedUntil(long snoozedUntil) {
90+
this.snoozedUntil = snoozedUntil;
91+
this.setMessageType(Conversation.MESSAGE_TYPE_SNOOZED);
92+
return this;
93+
}
94+
7795
@Override
7896
public String toString() {
7997
return "AdminReply{} " + super.toString();

intercom-java/src/main/java/io/intercom/api/Conversation.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public class Conversation extends TypedData {
2424
static final String MESSAGE_TYPE_NOTE = "note";
2525
static final String MESSAGE_TYPE_CLOSE = "close";
2626
static final String MESSAGE_TYPE_OPEN = "open";
27+
static final String MESSAGE_TYPE_SNOOZED = "snoozed";
2728
static final List<String> MESSAGE_TYPES = Lists.newArrayList(
2829
MESSAGE_TYPE_ASSIGNMENT,
2930
MESSAGE_TYPE_COMMENT,
3031
MESSAGE_TYPE_NOTE,
3132
MESSAGE_TYPE_CLOSE,
32-
MESSAGE_TYPE_OPEN
33+
MESSAGE_TYPE_OPEN,
34+
MESSAGE_TYPE_SNOOZED
3335
);
3436

3537
public static Conversation find(String id) throws InvalidException, AuthorizationException {
@@ -196,6 +198,9 @@ private static boolean isAdminQuery(Map<String, String> params) {
196198
@JsonProperty("waiting_since")
197199
private long waitingSince;
198200

201+
@JsonProperty("snoozed_until")
202+
private long snoozedUntil;
203+
199204
@JsonProperty("conversation_parts")
200205
private ConversationPartCollection conversationPartCollection;
201206

@@ -208,6 +213,9 @@ private static boolean isAdminQuery(Map<String, String> params) {
208213
@JsonProperty("read")
209214
private boolean read;
210215

216+
@JsonProperty("state")
217+
private String state;
218+
211219
@JsonProperty("links")
212220
private Map<String, URI> links;
213221

@@ -271,6 +279,10 @@ public long getWaitingSince() {
271279
return waitingSince;
272280
}
273281

282+
public long getSnoozedUntil() {
283+
return snoozedUntil;
284+
}
285+
274286
public ConversationPartCollection getConversationPartCollection() {
275287
if (conversationPartCollection == null) {
276288
conversationPartCollection = find(this.getId()).getConversationPartCollection();
@@ -295,6 +307,10 @@ public boolean getRead() {
295307
return read;
296308
}
297309

310+
public String getState() {
311+
return state;
312+
}
313+
298314
@Override
299315
public boolean equals(Object o) {
300316
if (this == o) return true;
@@ -307,6 +323,7 @@ public boolean equals(Object o) {
307323
if (read != that.read) return false;
308324
if (updatedAt != that.updatedAt) return false;
309325
if (waitingSince != that.waitingSince) return false;
326+
if (snoozedUntil != that.snoozedUntil) return false;
310327
if (assignee != null ? !assignee.equals(that.assignee) : that.assignee != null) return false;
311328
if (conversationMessage != null ? !conversationMessage.equals(that.conversationMessage) : that.conversationMessage != null)
312329
return false;
@@ -316,6 +333,7 @@ public boolean equals(Object o) {
316333
return false;
317334
if (id != null ? !id.equals(that.id) : that.id != null) return false;
318335
if (links != null ? !links.equals(that.links) : that.links != null) return false;
336+
if (!state.equals(that.state)) return false;
319337
if (!type.equals(that.type)) return false;
320338
//noinspection RedundantIfStatement
321339
if (user != null ? !user.equals(that.user) : that.user != null) return false;
@@ -327,12 +345,14 @@ public boolean equals(Object o) {
327345
public int hashCode() {
328346
int result = type.hashCode();
329347
result = 31 * result + (id != null ? id.hashCode() : 0);
348+
result = 31 * result + (state != null ? state.hashCode() : 0);
330349
result = 31 * result + (conversationMessage != null ? conversationMessage.hashCode() : 0);
331350
result = 31 * result + (user != null ? user.hashCode() : 0);
332351
result = 31 * result + (assignee != null ? assignee.hashCode() : 0);
333352
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
334353
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
335354
result = 31 * result + (int) (waitingSince ^ (waitingSince >>> 32));
355+
result = 31 * result + (int) (snoozedUntil ^ (snoozedUntil >>> 32));
336356
result = 31 * result + (conversationPartCollection != null ? conversationPartCollection.hashCode() : 0);
337357
result = 31 * result + (tagCollection != null ? tagCollection.hashCode() : 0);
338358
result = 31 * result + (open ? 1 : 0);
@@ -352,9 +372,11 @@ public String toString() {
352372
", createdAt=" + createdAt +
353373
", updatedAt=" + updatedAt +
354374
", waitingSince=" + waitingSince +
375+
", snoozedUntil=" + snoozedUntil +
355376
", conversationPartCollection=" + conversationPartCollection +
356377
", tagCollection=" + tagCollection +
357378
", open=" + open +
379+
", state=" + state +
358380
", read=" + read +
359381
", links=" + links +
360382
"} " + super.toString();

0 commit comments

Comments
 (0)