Skip to content

Commit a4891c0

Browse files
thewheatchoran
authored andcommitted
Add support for more message attributes (#177)
1 parent 158818f commit a4891c0

File tree

5 files changed

+297
-4
lines changed

5 files changed

+297
-4
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package io.intercom.api;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
8+
@SuppressWarnings("UnusedDeclaration")
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
11+
public class Attachment extends TypedData {
12+
13+
@JsonProperty("type")
14+
private final String type = "upload";
15+
@JsonProperty("name")
16+
private String name;
17+
@JsonProperty("url")
18+
private String url;
19+
@JsonProperty("content_type")
20+
private String contentType;
21+
@JsonProperty("filesize")
22+
private long filesize;
23+
@JsonProperty("width")
24+
private long width;
25+
@JsonProperty("height")
26+
private long height;
27+
28+
public Attachment() {
29+
}
30+
31+
public String getType() {
32+
return type;
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public String getUrl() {
40+
return url;
41+
}
42+
43+
public String getContentType() {
44+
return contentType;
45+
}
46+
47+
public long getFilesize() {
48+
return filesize;
49+
}
50+
51+
public long getWidth() {
52+
return width;
53+
}
54+
55+
public long getHeight() {
56+
return height;
57+
}
58+
59+
@Override
60+
public boolean equals(Object o) {
61+
if (this == o) return true;
62+
if (o == null || getClass() != o.getClass()) return false;
63+
64+
Attachment attachment = (Attachment) o;
65+
66+
if (name != null ? !name.equals(attachment.name) : attachment.name != null) return false;
67+
if (url != null ? !url.equals(attachment.url) : attachment.url != null) return false;
68+
if (contentType != null ? !contentType.equals(attachment.contentType) : attachment.contentType != null) return false;
69+
if (filesize != attachment.filesize) return false;
70+
if (height != attachment.height) return false;
71+
if (width != attachment.width) return false;
72+
73+
return true;
74+
}
75+
76+
@Override
77+
public int hashCode() {
78+
int result = type.hashCode();
79+
result = 31 * result + (name != null ? name.hashCode() : 0);
80+
result = 31 * result + (url != null ? url.hashCode() : 0);
81+
result = 31 * result + (contentType != null ? contentType.hashCode() : 0);
82+
result = 31 * result + (int) (filesize ^ (filesize >>> 32));
83+
result = 31 * result + (int) (height ^ (height>>> 32));
84+
result = 31 * result + (int) (width ^ (width>>> 32));
85+
return result;
86+
}
87+
88+
@Override
89+
public String toString() {
90+
return "Avatar{" +
91+
"type='" + type + '\'' +
92+
", name='" + name + '\'' +
93+
", url='" + url + '\'' +
94+
", content_type'=" + contentType + '\'' +
95+
", filesize=" + filesize +
96+
", height=" + height +
97+
", widht=" + width +
98+
"} " + super.toString();
99+
}
100+
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonProperty;
55

6+
import java.util.List;
7+
68
@SuppressWarnings("UnusedDeclaration")
79
@JsonIgnoreProperties(ignoreUnknown = true)
810
public class ConversationMessage extends TypedData {
@@ -11,6 +13,9 @@ public class ConversationMessage extends TypedData {
1113
@JsonProperty("type")
1214
private final String type = "conversation_message";
1315

16+
@JsonProperty
17+
private String id;
18+
1419
@JsonProperty
1520
private String subject;
1621

@@ -20,13 +25,23 @@ public class ConversationMessage extends TypedData {
2025
@JsonProperty
2126
private Author author;
2227

28+
@JsonProperty
29+
private String url;
30+
31+
@JsonProperty("attachments")
32+
private List<Attachment> attachments;
33+
2334
public ConversationMessage() {
2435
}
2536

2637
public String getType() {
2738
return type;
2839
}
2940

41+
public String getId() {
42+
return id;
43+
}
44+
3045
public String getSubject() {
3146
return subject;
3247
}
@@ -39,11 +54,23 @@ public Author getAuthor() {
3954
return author;
4055
}
4156

57+
public String getUrl() {
58+
return url;
59+
}
60+
61+
public List<Attachment> getAttachments() {
62+
return attachments;
63+
}
64+
4265
@Override
4366
public int hashCode() {
4467
int result = subject != null ? subject.hashCode() : 0;
4568
result = 31 * result + (body != null ? body.hashCode() : 0);
4669
result = 31 * result + (author != null ? author.hashCode() : 0);
70+
result = 31 * result + (id != null ? id.hashCode() : 0);
71+
result = 31 * result + (url != null ? url.hashCode() : 0);
72+
result = 31 * result + (attachments != null ? attachments.hashCode() : 0);
73+
4774
return result;
4875
}
4976

@@ -58,6 +85,9 @@ public boolean equals(Object o) {
5885
if (body != null ? !body.equals(that.body) : that.body != null) return false;
5986
//noinspection RedundantIfStatement
6087
if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false;
88+
if (id != null ? !id.equals(that.id) : that.id != null) return false;
89+
if (url != null ? !url.equals(that.url) : that.url != null) return false;
90+
if (attachments != null ? !attachments.equals(that.attachments) : that.attachments != null) return false;
6191

6292
return true;
6393
}
@@ -66,9 +96,12 @@ public boolean equals(Object o) {
6696
public String toString() {
6797
return "ConversationMessage{" +
6898
"type='" + type + '\'' +
99+
", id='" + id + '\'' +
69100
", subject='" + subject + '\'' +
70101
", body='" + body + '\'' +
71102
", author=" + author +
103+
", url=" + url +
104+
", attachments=" + attachments +
72105
"} " + super.toString();
73106
}
74107
}

intercom-java/src/test/java/io/intercom/api/ConversationTest.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,68 @@ public void testDisplayAs() {
109109
}
110110
}
111111

112+
@Test
113+
public void testGetConversationMessageDetailsFromConversation() throws IOException {
114+
PowerMockito.mockStatic(Conversation.class);
115+
116+
String json = load("conversation.json");
117+
final Conversation conversation = objectMapper.readValue(json, Conversation.class);
118+
final ConversationMessage conversationMessage = conversation.getConversationMessage();
119+
120+
assertEquals("33954111", conversationMessage.getId());
121+
assertEquals("<p>test</p>", conversationMessage.getBody());
122+
assertEquals("Email subject", conversationMessage.getSubject());
123+
assertEquals("https://intercom.com/", conversationMessage.getUrl());
124+
125+
assertEquals("lead", conversationMessage.getAuthor().getType());
126+
assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId());
127+
128+
assertEquals(2, conversationMessage.getAttachments().size());
129+
130+
final Attachment firstAttachment = conversationMessage.getAttachments().get(0);
131+
final Attachment lastAttachment = conversationMessage.getAttachments().get(1);
132+
assertEquals("upload", firstAttachment.getType());
133+
assertEquals("123.csv", firstAttachment.getName());
134+
assertEquals("https://downloads.intercomcdn.com/123.csv", firstAttachment.getUrl());
135+
assertEquals("text/csv", firstAttachment.getContentType());
136+
assertEquals(147, firstAttachment.getFilesize());
137+
assertEquals(0, firstAttachment.getWidth());
138+
assertEquals(0, firstAttachment.getHeight());
139+
140+
assertEquals("upload", lastAttachment.getType());
141+
assertEquals("abc.txt", lastAttachment.getName());
142+
assertEquals("https://downloads.intercomcdn.com/txt", lastAttachment.getUrl());
143+
assertEquals("text/csv", lastAttachment.getContentType());
144+
assertEquals(100, lastAttachment.getFilesize());
145+
assertEquals(1, lastAttachment.getWidth());
146+
assertEquals(2, lastAttachment.getHeight());
147+
148+
PowerMockito.verifyStatic(Mockito.never());
149+
Conversation.find(conversation.getId());
150+
}
151+
152+
@Test
153+
public void testGetConversationMessageDetailsFromConversationNoAttachments() throws IOException {
154+
PowerMockito.mockStatic(Conversation.class);
155+
156+
String json = load("conversation_no_attachments.json");
157+
final Conversation conversation = objectMapper.readValue(json, Conversation.class);
158+
final ConversationMessage conversationMessage = conversation.getConversationMessage();
159+
160+
assertEquals("33954111", conversationMessage.getId());
161+
assertEquals("<p>test</p>", conversationMessage.getBody());
162+
assertEquals("Email subject", conversationMessage.getSubject());
163+
assertEquals("https://intercom.com/", conversationMessage.getUrl());
164+
165+
assertEquals("lead", conversationMessage.getAuthor().getType());
166+
assertEquals("576c1a139d0baad1010011111", conversationMessage.getAuthor().getId());
167+
168+
assertEquals(0, conversationMessage.getAttachments().size());
169+
170+
PowerMockito.verifyStatic(Mockito.never());
171+
Conversation.find(conversation.getId());
172+
}
173+
112174
@Test
113175
public void testGetConversationsPartFromConversation() throws IOException {
114176
PowerMockito.mockStatic(Conversation.class);
@@ -207,4 +269,4 @@ private Map<String, String> buildRequestParameters(String html) {
207269
params2.put("display_as", html);
208270
return params2;
209271
}
210-
}
272+
}

intercom-java/src/test/resources/conversation.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,30 @@
77
"conversation_message": {
88
"type": "conversation_message",
99
"id": "33954111",
10-
"subject": "",
10+
"subject": "Email subject",
1111
"body": "<p>test</p>",
1212
"author": {
1313
"type": "lead",
1414
"id": "576c1a139d0baad1010011111"
1515
},
16-
"attachments": [],
17-
"url": null
16+
"attachments": [{
17+
"type": "upload",
18+
"name": "123.csv",
19+
"url": "https://downloads.intercomcdn.com/123.csv",
20+
"content_type": "text/csv",
21+
"filesize": 147,
22+
"width": null,
23+
"height": null
24+
},{
25+
"type": "upload",
26+
"name": "abc.txt",
27+
"url": "https://downloads.intercomcdn.com/txt",
28+
"content_type": "text/csv",
29+
"filesize": 100,
30+
"width": 1,
31+
"height": 2
32+
}],
33+
"url": "https://intercom.com/"
1834
},
1935
"user": {
2036
"type": "user",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"type": "conversation",
3+
"id": "5143511111",
4+
"created_at": 1466703132,
5+
"updated_at": 1468236397,
6+
"waiting_since": 1468236397,
7+
"conversation_message": {
8+
"type": "conversation_message",
9+
"id": "33954111",
10+
"subject": "Email subject",
11+
"body": "<p>test</p>",
12+
"author": {
13+
"type": "lead",
14+
"id": "576c1a139d0baad1010011111"
15+
},
16+
"attachments": [],
17+
"url": "https://intercom.com/"
18+
},
19+
"user": {
20+
"type": "user",
21+
"id": "576c1a139d0baad1010001111"
22+
},
23+
"assignee": {
24+
"type": "admin",
25+
"id": "358111"
26+
},
27+
"conversation_parts": {
28+
"type": "conversation_part.list",
29+
"conversation_parts": [
30+
{
31+
"type": "conversation_part",
32+
"id": "142533411",
33+
"part_type": "comment",
34+
"body": "<p>dm-9187dba8-fb3b-cb99-da05-37a932d3d678</p>",
35+
"created_at": 1468031160,
36+
"updated_at": 1468031160,
37+
"notified_at": 1468031160,
38+
"assigned_to": null,
39+
"author": {
40+
"type": "user",
41+
"id": "576c1a139d0baad1010001111"
42+
},
43+
"attachments": [],
44+
"external_id": null
45+
},
46+
{
47+
"type": "conversation_part",
48+
"id": "142533511",
49+
"part_type": "comment",
50+
"body": "<p>im-99a3a78f-5105-449d-a114-a7b5eb7e5b80</p>",
51+
"created_at": 1468031171,
52+
"updated_at": 1468031171,
53+
"notified_at": 1468031171,
54+
"assigned_to": null,
55+
"author": {
56+
"type": "admin",
57+
"id": "358111"
58+
},
59+
"attachments": [],
60+
"external_id": null
61+
}
62+
],
63+
"total_count": 2
64+
},
65+
"open": true,
66+
"read": false,
67+
"tags": {
68+
"type": "tag.list",
69+
"tags": [
70+
{
71+
"type": "tag",
72+
"id": "123",
73+
"name": "Tag 1"
74+
},
75+
{
76+
"type": "tag",
77+
"id": "456",
78+
"name": "Tag 2"
79+
}
80+
]
81+
}
82+
}

0 commit comments

Comments
 (0)