From f42aa1d30aa441f5f2eeb2d2619591c39935b2a9 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Sat, 27 Oct 2018 16:48:53 +0800 Subject: [PATCH] Add support for replying to last conversation --- README.md | 17 +++ .../java/io/intercom/api/Conversation.java | 10 ++ .../io/intercom/api/ReplyToLastReply.java | 120 ++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 intercom-java/src/main/java/io/intercom/api/ReplyToLastReply.java diff --git a/README.md b/README.md index 27ca8fc0..4c4ad92c 100644 --- a/README.md +++ b/README.md @@ -572,6 +572,23 @@ userReply.setBody("Mighty fine shindig"); userReply.setAttachmentUrls(new String[]{"http://www.example.com/attachment.jpg"}); // optional - list of attachments System.out.println(MapperSupport.objectMapper().writeValueAsString(userReply)); Conversation.reply("66", userReply); + +// reply to last users' conversation as an admin +ReplyToLastReply replyToLastReplay = new ReplyToLastReply(); +replyToLastReplay.setIntercomUserID("5310d8e8598c9a0b24000005"); +replyToLastReplay.setAdminId("1"); +replyToLastReplay.setBody("These apples are healthsome"); +replyToLastReplay.setMessageType("comment"); +replyToLastReplay.setType("admin"); +Conversation.replyToLastConversation(replyToLastReplay); + +// reply to last users' conversation as a user +ReplyToLastReply replyToLastReplay = new ReplyToLastReply(); +replyToLastReplay.setIntercomUserID("5310d8e8598c9a0b24000005"); +replyToLastReplay.setBody("Mighty fine shindig"); +replyToLastReplay.setMessageType("comment"); +replyToLastReplay.setType("user"); +Conversation.replyToLastConversation(replyToLastReplay); ``` ### Webhooks 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..b76b25a7 100644 --- a/intercom-java/src/main/java/io/intercom/api/Conversation.java +++ b/intercom-java/src/main/java/io/intercom/api/Conversation.java @@ -71,6 +71,16 @@ public static Conversation reply(String id, AdminReply reply) { .post(Conversation.class, new AdminReply.AdminStringReply(reply)); } + public static Conversation replyToLastConversation(ReplyToLastReply reply) { + final URI uri = UriBuilder.newBuilder() + .path("conversations") + .path("last") + .path("reply") + .build(); + return new HttpClient(uri) + .post(Conversation.class, reply); + } + public static UserMessage create(UserMessage message) { return DataResource.create(message, "messages", UserMessage.class); } diff --git a/intercom-java/src/main/java/io/intercom/api/ReplyToLastReply.java b/intercom-java/src/main/java/io/intercom/api/ReplyToLastReply.java new file mode 100644 index 00000000..e4884e97 --- /dev/null +++ b/intercom-java/src/main/java/io/intercom/api/ReplyToLastReply.java @@ -0,0 +1,120 @@ +package io.intercom.api; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@SuppressWarnings("UnusedDeclaration") +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class ReplyToLastReply { + + @JsonProperty("message_type") + private String messageType; + + @JsonProperty("body") + private String body; + + @JsonProperty("attachment_urls") + private String[] attachmentUrls; + + @JsonProperty("type") + private String type; + + @JsonProperty("admin_id") + private String adminId; + + @JsonProperty("intercom_user_id") + public String intercomUserId; + + @JsonProperty("user_id") + public String userId; + + @JsonProperty("email") + public String email; + + + public String getMessageType() { + return this.messageType; + } + public ReplyToLastReply setMessageType(String messageType) { + this.messageType = messageType; + return this; + } + + public String getBody() { + return this.body ; + } + public ReplyToLastReply setBody(String body) { + this.body = body; + return this; + } + + public String getType() { + return this.type; + } + + public ReplyToLastReply setType(String type) { + this.type = type; + return this; + } + + public String getAdminId() { + return this.adminId; + } + + public ReplyToLastReply setAdminId(String adminId) { + this.adminId = adminId; + return this; + } + + public String getIntercomUserID(){ + return this.intercomUserId; + } + + public ReplyToLastReply setIntercomUserID(String intercomUserId){ + this.intercomUserId = intercomUserId; + return this; + } + + public String getUserID() { + return this.userId; + } + + public ReplyToLastReply setUserID(String userId) { + this.userId = userId; + return this; + } + public String getEmail(){ + return this.email; + } + + public ReplyToLastReply setEmail(String email){ + this.email = email; + return this; + } + + public String[] getAttachmentUrls() { + return this.attachmentUrls; + } + + public ReplyToLastReply setAttachmentUrls(String[] attachmentUrls) { + this.attachmentUrls = attachmentUrls; + return this; + } + + @Override + public String toString() { + return "ReplyToLast{ " + + " messageType='" + messageType + '\'' + + ", body='" + body + '\'' + + ", attachmentUrls='" + (attachmentUrls == null ? attachmentUrls : attachmentUrls.toString()) + '\'' + + ", type='" + type + '\'' + + ", adminId='" + adminId + '\'' + + ", intercomUserId='" + intercomUserId + '\'' + + ", userId='" + userId + '\'' + + ", email='" + email + '\'' + + "} " + super.toString(); + + } +}