From 9da3e92a0e3f6b29b7dbec1819cbc4b2a4549f27 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Tue, 9 Oct 2018 22:05:48 +0800 Subject: [PATCH] Add support for snooze --- README.md | 12 ++++++++++ .../main/java/io/intercom/api/AdminReply.java | 18 ++++++++++++++ .../java/io/intercom/api/Conversation.java | 24 ++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c414bd9c..a969b98e 100644 --- a/README.md +++ b/README.md @@ -565,6 +565,18 @@ AdminReply adminReply = new AdminReply(admin); adminReply.setMessageType("close"); Conversation.reply("66", adminReply); +// admin snooze +Admin admin = new Admin().setId("1"); +AdminReply adminReply = new AdminReply(admin); +adminReply.setSnoozedUntil(1549092382); +Conversation.reply("66", adminReply); + +// admin open / unsnooze +Admin admin = new Admin().setId("1"); +AdminReply adminReply = new AdminReply(admin); +adminReply.setMessageType("open"); +Conversation.reply("66", adminReply); + // user reply User user1 = new User().setId("5310d8e8598c9a0b24000005"); UserReply userReply = new UserReply(user1); diff --git a/intercom-java/src/main/java/io/intercom/api/AdminReply.java b/intercom-java/src/main/java/io/intercom/api/AdminReply.java index fc93b3dd..f2040ad6 100644 --- a/intercom-java/src/main/java/io/intercom/api/AdminReply.java +++ b/intercom-java/src/main/java/io/intercom/api/AdminReply.java @@ -32,6 +32,11 @@ public String getMessageType() { return reply.getMessageType(); } + @JsonProperty("snoozed_until") + public long getSnoozedUntil() { + return reply.getSnoozedUntil(); + } + @JsonProperty("body") public String getBody() { return reply.getBody(); @@ -56,6 +61,9 @@ private String[] getAttachmentUrls() { @JsonProperty("assignee_id") private String assigneeID; + @JsonProperty("snoozed_until") + private long snoozedUntil; + public AdminReply(Admin admin) { this.from = admin; } @@ -74,6 +82,16 @@ public Reply setAssigneeID(String assigneeID) { return this; } + public long getSnoozedUntil() { + return snoozedUntil; + } + + public Reply setSnoozedUntil(long snoozedUntil) { + this.snoozedUntil = snoozedUntil; + this.setMessageType(Conversation.MESSAGE_TYPE_SNOOZED); + return this; + } + @Override public String toString() { return "AdminReply{} " + super.toString(); diff --git a/intercom-java/src/main/java/io/intercom/api/Conversation.java b/intercom-java/src/main/java/io/intercom/api/Conversation.java index a7ea3016..5b3f8278 100644 --- a/intercom-java/src/main/java/io/intercom/api/Conversation.java +++ b/intercom-java/src/main/java/io/intercom/api/Conversation.java @@ -24,12 +24,14 @@ public class Conversation extends TypedData { static final String MESSAGE_TYPE_NOTE = "note"; static final String MESSAGE_TYPE_CLOSE = "close"; static final String MESSAGE_TYPE_OPEN = "open"; + static final String MESSAGE_TYPE_SNOOZED = "snoozed"; static final List MESSAGE_TYPES = Lists.newArrayList( MESSAGE_TYPE_ASSIGNMENT, MESSAGE_TYPE_COMMENT, MESSAGE_TYPE_NOTE, MESSAGE_TYPE_CLOSE, - MESSAGE_TYPE_OPEN + MESSAGE_TYPE_OPEN, + MESSAGE_TYPE_SNOOZED ); public static Conversation find(String id) throws InvalidException, AuthorizationException { @@ -196,6 +198,9 @@ private static boolean isAdminQuery(Map params) { @JsonProperty("waiting_since") private long waitingSince; + @JsonProperty("snoozed_until") + private long snoozedUntil; + @JsonProperty("conversation_parts") private ConversationPartCollection conversationPartCollection; @@ -208,6 +213,9 @@ private static boolean isAdminQuery(Map params) { @JsonProperty("read") private boolean read; + @JsonProperty("state") + private String state; + @JsonProperty("links") private Map links; @@ -271,6 +279,10 @@ public long getWaitingSince() { return waitingSince; } + public long getSnoozedUntil() { + return snoozedUntil; + } + public ConversationPartCollection getConversationPartCollection() { if (conversationPartCollection == null) { conversationPartCollection = find(this.getId()).getConversationPartCollection(); @@ -295,6 +307,10 @@ public boolean getRead() { return read; } + public String getState() { + return state; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -307,6 +323,7 @@ public boolean equals(Object o) { if (read != that.read) return false; if (updatedAt != that.updatedAt) return false; if (waitingSince != that.waitingSince) return false; + if (snoozedUntil != that.snoozedUntil) return false; if (assignee != null ? !assignee.equals(that.assignee) : that.assignee != null) return false; if (conversationMessage != null ? !conversationMessage.equals(that.conversationMessage) : that.conversationMessage != null) return false; @@ -316,6 +333,7 @@ public boolean equals(Object o) { return false; if (id != null ? !id.equals(that.id) : that.id != null) return false; if (links != null ? !links.equals(that.links) : that.links != null) return false; + if (!state.equals(that.state)) return false; if (!type.equals(that.type)) return false; //noinspection RedundantIfStatement if (user != null ? !user.equals(that.user) : that.user != null) return false; @@ -327,12 +345,14 @@ public boolean equals(Object o) { public int hashCode() { int result = type.hashCode(); result = 31 * result + (id != null ? id.hashCode() : 0); + result = 31 * result + (state != null ? state.hashCode() : 0); result = 31 * result + (conversationMessage != null ? conversationMessage.hashCode() : 0); result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (assignee != null ? assignee.hashCode() : 0); result = 31 * result + (int) (createdAt ^ (createdAt >>> 32)); result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32)); result = 31 * result + (int) (waitingSince ^ (waitingSince >>> 32)); + result = 31 * result + (int) (snoozedUntil ^ (snoozedUntil >>> 32)); result = 31 * result + (conversationPartCollection != null ? conversationPartCollection.hashCode() : 0); result = 31 * result + (tagCollection != null ? tagCollection.hashCode() : 0); result = 31 * result + (open ? 1 : 0); @@ -352,9 +372,11 @@ public String toString() { ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", waitingSince=" + waitingSince + + ", snoozedUntil=" + snoozedUntil + ", conversationPartCollection=" + conversationPartCollection + ", tagCollection=" + tagCollection + ", open=" + open + + ", state=" + state + ", read=" + read + ", links=" + links + "} " + super.toString();