Skip to content

Commit 4b63f9e

Browse files
author
Timothy Lim
committed
Add conversation participants support
1 parent c3ddbda commit 4b63f9e

8 files changed

+286
-0
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,29 @@ Conversation.runAssignmentRules("19240007891");
603603

604604
// mark conversation as read
605605
Conversation.markAsRead("66");
606+
607+
// admin adding participant to conversation
608+
AdminAddParticipant adminAddParticipant = new AdminAddParticipant();
609+
adminAddParticipant.setAdminId("248698");
610+
Participant participant = new Participant();
611+
participant.setIntercomUserId("5310d8e8598c9a0b24000005");
612+
// participant.setUserId("2"); // or find by user_id
613+
// participant.setEmail("[email protected]"); // or find by user_id
614+
adminAddParticipant.setParticipant(participant);
615+
ParticipantResponse participantResponse = Conversation.addParticipant("19240007891", adminAddParticipant);
616+
617+
// user adding participant to conversation
618+
UserAddParticipant userAddParticipant = new UserAddParticipant();
619+
userAddParticipant.setIntercomUserId("575b4dbbd7f9c87f240008c5");
620+
Participant participant = new Participant();
621+
participant.setIntercomUserId("5310d8e8598c9a0b24000005");
622+
// participant.setUserId("2"); // or find by user_id
623+
// participant.setEmail("[email protected]"); // or find by user_id
624+
userAddParticipant.setParticipant(participant);
625+
ParticipantResponse participantResponse = Conversation.addParticipant("19240007891", userAddParticipant);
626+
627+
// removing participant from conversation
628+
ParticipantResponse participantResponse = Conversation.removeParticipant("19240007891", "248698", "564320845c88872b60000012");
606629
```
607630

608631
### Webhooks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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_EMPTY)
12+
public class AdminAddParticipant {
13+
14+
@JsonProperty("admin_id")
15+
public String adminId;
16+
17+
@JsonProperty("customer")
18+
private Participant participant;
19+
20+
public String getAdminId() {
21+
return adminId;
22+
}
23+
24+
public AdminAddParticipant setAdminId(String adminId) {
25+
this.adminId = adminId;
26+
return this;
27+
}
28+
29+
private Participant getParticipant(){
30+
return participant;
31+
}
32+
33+
public AdminAddParticipant setParticipant(Participant participant){
34+
this.participant = participant;
35+
return this;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "AdminAddParticipant{" +
41+
"adminId='" + adminId + "\'" +
42+
",participant=" + participant +
43+
"} " + super.toString();
44+
}
45+
}

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

+32
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,38 @@ public static Conversation markAsRead(String id) {
100100
.put(Conversation.class, new ConversationRead());
101101
}
102102

103+
public static ParticipantResponse addParticipant(String id, AdminAddParticipant adminAddParticipant) {
104+
final URI uri = UriBuilder.newBuilder()
105+
.path("conversations")
106+
.path(id)
107+
.path("customers")
108+
.build();
109+
return new HttpClient(uri)
110+
.post(ParticipantResponse.class, adminAddParticipant);
111+
}
112+
113+
public static ParticipantResponse addParticipant(String id, UserAddParticipant userAddParticipant) {
114+
final URI uri = UriBuilder.newBuilder()
115+
.path("conversations")
116+
.path(id)
117+
.path("customers")
118+
.build();
119+
return new HttpClient(uri)
120+
.post(ParticipantResponse.class, userAddParticipant);
121+
}
122+
123+
public static ParticipantResponse removeParticipant(String id, String admin_id, String participantIntercomId) {
124+
Map<String, String> params = new HashMap<String,String>();
125+
params.put("admin_id", admin_id);
126+
final URI uri = UriBuilder.newBuilder()
127+
.path("conversations")
128+
.path(id)
129+
.path("customers")
130+
.path(participantIntercomId)
131+
.build();
132+
return DataResource.delete(params, uri, ParticipantResponse.class);
133+
}
134+
103135
public static UserMessage create(UserMessage message) {
104136
return DataResource.create(message, "messages", UserMessage.class);
105137
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public static <T> T delete(Map<String, String> params, String collectionPath, Cl
6161
return resource.delete(c);
6262
}
6363

64+
public static <T> T delete(Map<String, String> params, URI uri, Class<T> c) {
65+
final HttpClient resource = new HttpClient(uri);
66+
return resource.delete(c, params);
67+
}
68+
6469
public static <C> C list(Map<String, String> params, String collectionPath, Class<C> c) {
6570
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).query(params).build());
6671
return resource.get(c);

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

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public <T> T delete(Class<T> reqres) {
9090
return executeHttpMethod("DELETE", null, getJavaType(reqres));
9191
}
9292

93+
public <T, E> T delete(Class<T> reqres, E entity) {
94+
headers.put("Content-Type", APPLICATION_JSON);
95+
return executeHttpMethod("DELETE", entity, getJavaType(reqres));
96+
}
97+
9398
public <T, E> T put(Class<T> reqres, E entity) {
9499
headers.put("Content-Type", APPLICATION_JSON);
95100
return executeHttpMethod("PUT", (E) entity, getJavaType(reqres));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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_EMPTY)
11+
public class Participant {
12+
13+
@JsonProperty("intercom_user_id")
14+
private String intercomUserId;
15+
16+
@JsonProperty("user_id")
17+
private String userId;
18+
19+
@JsonProperty("email")
20+
private String email;
21+
22+
public Participant() {
23+
}
24+
25+
public String getIntercomUserId() {
26+
return intercomUserId;
27+
}
28+
29+
public Participant setIntercomUserId(String intercomUserId) {
30+
this.intercomUserId = intercomUserId;;
31+
return this;
32+
}
33+
34+
public String getUserId() {
35+
return userId;
36+
}
37+
38+
public Participant setUserId(String userId) {
39+
this.userId = userId;
40+
return this;
41+
}
42+
43+
public String getEmail() {
44+
return email;
45+
}
46+
47+
public Participant setEmail(String email) {
48+
this.email = email;
49+
return this;
50+
}
51+
52+
@Override
53+
public int hashCode() {
54+
int result = intercomUserId != null ? intercomUserId.hashCode() : 0;
55+
result = 31 * result + (userId != null ? userId.hashCode() : 0);
56+
result = 31 * result + (email != null ? email.hashCode() : 0);
57+
return result;
58+
}
59+
60+
@Override
61+
public boolean equals(Object o) {
62+
if (this == o) return true;
63+
if (o == null || getClass() != o.getClass()) return false;
64+
65+
Participant customer = (Participant) o;
66+
67+
if (intercomUserId != null ? !intercomUserId.equals(customer.intercomUserId) : customer.intercomUserId != null) return false;
68+
if (userId != null ? !userId.equals(customer.userId) : customer.userId != null) return false;
69+
if (email != null ? !email.equals(customer.email) : customer.email != null) return false;
70+
return true;
71+
}
72+
73+
@Override
74+
public String toString() {
75+
return "Participant{" +
76+
", intercomUserId='" + intercomUserId+ '\'' +
77+
", userId='" + userId+ '\'' +
78+
", email='" + email+ '\'' +
79+
"} " + super.toString();
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
import java.util.List;
9+
10+
@SuppressWarnings("UnusedDeclaration")
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
13+
public class ParticipantResponse {
14+
15+
@JsonProperty("customers")
16+
private List<Customer> customers;
17+
18+
public ParticipantResponse() {
19+
}
20+
21+
public List<Customer> getCustomers(){
22+
return customers;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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_EMPTY)
12+
public class UserAddParticipant {
13+
14+
@JsonProperty("intercom_user_id")
15+
public String intercomUserId;
16+
17+
@JsonProperty("user_id")
18+
public String userId;
19+
20+
@JsonProperty("email")
21+
public String email;
22+
23+
@JsonProperty("customer")
24+
private Participant participant;
25+
26+
public String getIntercomUserId() {
27+
return intercomUserId;
28+
}
29+
30+
public UserAddParticipant setIntercomUserId(String intercomUserId) {
31+
this.intercomUserId = intercomUserId;
32+
return this;
33+
}
34+
35+
public String getUserID() {
36+
return userId;
37+
}
38+
39+
public UserAddParticipant setUserID(String userId) {
40+
this.userId = userId;
41+
return this;
42+
}
43+
44+
public String getEmail() {
45+
return email;
46+
}
47+
48+
public UserAddParticipant setEmail(String email) {
49+
this.email = email;
50+
return this;
51+
}
52+
53+
private Participant getParticipant(){
54+
return participant;
55+
}
56+
57+
public UserAddParticipant setParticipant(Participant participant){
58+
this.participant = participant;
59+
return this;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return "UserAddParticipant{" +
65+
"intercomUserId='" + intercomUserId + "\'" +
66+
"userId='" + userId + "\'" +
67+
"email='" + email + "\'" +
68+
",participant=" + participant +
69+
"} " + super.toString();
70+
}
71+
}

0 commit comments

Comments
 (0)