Skip to content

Commit 7f3b37f

Browse files
committed
contact initiated messaging
1 parent 621a39f commit 7f3b37f

File tree

4 files changed

+148
-99
lines changed

4 files changed

+148
-99
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.intercom.api;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
7+
8+
@SuppressWarnings("UnusedDeclaration")
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
11+
public class ContactMessage extends TypedMessage<Contact, ContactMessage> {
12+
13+
public ContactMessage() {
14+
}
15+
16+
@Override
17+
public String toString() {
18+
return "ContactMessage{} " + super.toString();
19+
}
20+
21+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public static UserMessage create(UserMessage message) {
7171
return DataResource.create(message, "messages", UserMessage.class);
7272
}
7373

74+
public static ContactMessage create(ContactMessage message) {
75+
return DataResource.create(message, "messages", ContactMessage.class);
76+
}
77+
7478
public static AdminMessage create(AdminMessage message) throws InvalidException {
7579
if ((!message.getTemplate().equals("plain")) && (!message.getTemplate().equals("personal"))) {
7680
throw new InvalidException("The template must be either personal or plain");
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
9+
@SuppressWarnings("UnusedDeclaration")
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
12+
abstract class TypedMessage<F, T extends TypedMessage> extends TypedData {
13+
14+
@SuppressWarnings("FieldCanBeLocal")
15+
@JsonProperty("type")
16+
protected final String type = "user_message";
17+
18+
@JsonProperty("message_type")
19+
protected String messageType;
20+
21+
@JsonProperty("id")
22+
protected String id;
23+
24+
@JsonProperty("body")
25+
protected String body;
26+
27+
@JsonProperty("created_at")
28+
protected long createdAt;
29+
30+
protected F from;
31+
32+
public TypedMessage() {
33+
}
34+
35+
public String getType() {
36+
return type;
37+
}
38+
39+
public F getFrom() {
40+
return from;
41+
}
42+
43+
public T setFrom(F from) {
44+
this.from = from;
45+
return (T)this;
46+
}
47+
48+
public String getMessageType() {
49+
return messageType;
50+
}
51+
52+
public void setMessageType(String messageType) {
53+
this.messageType = messageType;
54+
}
55+
56+
public String getId() {
57+
return id;
58+
}
59+
60+
public String getBody() {
61+
return body;
62+
}
63+
64+
public T setBody(String body) {
65+
this.body = body;
66+
return (T)this;
67+
}
68+
69+
public long getCreatedAt() {
70+
return createdAt;
71+
}
72+
73+
public T setCreatedAt(long createdAt) {
74+
this.createdAt = createdAt;
75+
return (T)this;
76+
}
77+
78+
@Override
79+
public String toString() {
80+
return "TypedMessage{" +
81+
"type='" + type + '\'' +
82+
", messageType='" + messageType + '\'' +
83+
", id='" + id + '\'' +
84+
", body='" + body + '\'' +
85+
", createdAt=" + createdAt +
86+
", from=" + from +
87+
"} " + super.toString();
88+
}
89+
90+
@Override
91+
public boolean equals(Object o) {
92+
if (this == o) return true;
93+
if (o == null || getClass() != o.getClass()) return false;
94+
95+
TypedMessage<?, ?> that = (TypedMessage<?, ?>) o;
96+
97+
if (createdAt != that.createdAt) return false;
98+
if (type != null ? !type.equals(that.type) : that.type != null) return false;
99+
if (messageType != null ? !messageType.equals(that.messageType) : that.messageType != null) return false;
100+
if (id != null ? !id.equals(that.id) : that.id != null) return false;
101+
if (body != null ? !body.equals(that.body) : that.body != null) return false;
102+
return !(from != null ? !from.equals(that.from) : that.from != null);
103+
104+
}
105+
106+
@Override
107+
public int hashCode() {
108+
int result = type != null ? type.hashCode() : 0;
109+
result = 31 * result + (messageType != null ? messageType.hashCode() : 0);
110+
result = 31 * result + (id != null ? id.hashCode() : 0);
111+
result = 31 * result + (body != null ? body.hashCode() : 0);
112+
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
113+
result = 31 * result + (from != null ? from.hashCode() : 0);
114+
return result;
115+
}
116+
}
Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,28 @@
11
package io.intercom.api;
22

33

4+
import com.fasterxml.jackson.annotation.JsonIgnore;
45
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
56
import com.fasterxml.jackson.annotation.JsonInclude;
6-
import com.fasterxml.jackson.annotation.JsonProperty;
77

88

99
@SuppressWarnings("UnusedDeclaration")
1010
@JsonIgnoreProperties(ignoreUnknown = true)
11-
@JsonInclude(JsonInclude.Include.NON_EMPTY)
12-
public class UserMessage extends TypedData {
13-
14-
@SuppressWarnings("FieldCanBeLocal")
15-
@JsonProperty("type")
16-
private final String type = "user_message";
17-
18-
@JsonProperty("message_type")
19-
private String messageType;
20-
21-
@JsonProperty("id")
22-
private String id;
23-
24-
@JsonProperty("body")
25-
private String body;
26-
27-
@JsonProperty("created_at")
28-
private long createdAt;
29-
30-
@JsonProperty("from")
31-
private User user;
11+
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
12+
public class UserMessage extends TypedMessage<User, UserMessage> {
3213

3314
public UserMessage() {
3415
}
3516

36-
public String getType() {
37-
return type;
38-
}
39-
40-
public String getId() {
41-
return id;
42-
}
43-
44-
UserMessage setId(String id) {
45-
this.id = id;
46-
return this;
47-
}
48-
49-
public String getBody() {
50-
return body;
51-
}
52-
53-
public UserMessage setBody(String body) {
54-
this.body = body;
55-
return this;
56-
}
57-
58-
public long getCreatedAt() {
59-
return createdAt;
60-
}
61-
62-
public UserMessage setCreatedAt(long createdAt) {
63-
this.createdAt = createdAt;
64-
return this;
65-
}
66-
67-
public User getUser() {
68-
return user;
69-
}
70-
17+
@JsonIgnore
18+
@Deprecated
7119
public UserMessage setUser(User user) {
72-
this.user = user;
20+
this.from = user;
7321
return this;
7422
}
7523

76-
public String getMessageType() {
77-
return messageType;
78-
}
79-
80-
@Override
81-
public boolean equals(Object o) {
82-
if (this == o) return true;
83-
if (o == null || getClass() != o.getClass()) return false;
84-
85-
UserMessage that = (UserMessage) o;
86-
87-
if (createdAt != that.createdAt) return false;
88-
if (body != null ? !body.equals(that.body) : that.body != null) return false;
89-
if (id != null ? !id.equals(that.id) : that.id != null) return false;
90-
if (!messageType.equals(that.messageType)) return false;
91-
if (!type.equals(that.type)) return false;
92-
//noinspection RedundantIfStatement
93-
if (user != null ? !user.equals(that.user) : that.user != null) return false;
94-
95-
return true;
96-
}
97-
98-
@Override
99-
public int hashCode() {
100-
int result = type.hashCode();
101-
result = 31 * result + (messageType.hashCode());
102-
result = 31 * result + (id != null ? id.hashCode() : 0);
103-
result = 31 * result + (body != null ? body.hashCode() : 0);
104-
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
105-
result = 31 * result + (user != null ? user.hashCode() : 0);
106-
return result;
107-
}
108-
10924
@Override
11025
public String toString() {
111-
return "UserMessage{" +
112-
"id='" + id + '\'' +
113-
", body='" + body + '\'' +
114-
", messageType='" + messageType + '\'' +
115-
", createdAt=" + createdAt +
116-
", user=" + user +
117-
"} " + super.toString();
26+
return "UserMessage{} " + super.toString();
11827
}
119-
12028
}

0 commit comments

Comments
 (0)