From 8f63ddac9646ecc7f1911fc0cdd860c94b08a7ed Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Tue, 9 Oct 2018 22:41:48 +0800 Subject: [PATCH] Add support for marking conversation as read --- README.md | 3 +++ .../java/io/intercom/api/Conversation.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 27ca8fc0..1373a571 100644 --- a/README.md +++ b/README.md @@ -572,6 +572,9 @@ 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); + +// mark conversation as read +Conversation.markAsRead("66"); ``` ### 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..30fe9420 100644 --- a/intercom-java/src/main/java/io/intercom/api/Conversation.java +++ b/intercom-java/src/main/java/io/intercom/api/Conversation.java @@ -17,6 +17,18 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class Conversation extends TypedData { + @SuppressWarnings("UnusedDeclaration") + @JsonIgnoreProperties(ignoreUnknown = true) + private static class ConversationRead extends TypedData { + + @JsonProperty("read") + private boolean read; + + public ConversationRead() { + this.read = true; + } + } + private static final HashMap SENTINEL = Maps.newHashMap(); private static final List DISPLAY_AS_FORMATS = Lists.newArrayList("plaintext", "html"); static final String MESSAGE_TYPE_ASSIGNMENT = "assignment"; @@ -71,6 +83,16 @@ public static Conversation reply(String id, AdminReply reply) { .post(Conversation.class, new AdminReply.AdminStringReply(reply)); } + public static Conversation markAsRead(String id) { + final URI uri = UriBuilder.newBuilder() + .path("conversations") + .path(id) + .build(); + + return new HttpClient(uri) + .put(Conversation.class, new ConversationRead()); + } + public static UserMessage create(UserMessage message) { return DataResource.create(message, "messages", UserMessage.class); }