Skip to content

Commit

Permalink
Add conversation participants support
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Lim committed Nov 13, 2018
1 parent c3ddbda commit 4b63f9e
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,29 @@ Conversation.runAssignmentRules("19240007891");

// mark conversation as read
Conversation.markAsRead("66");

// admin adding participant to conversation
AdminAddParticipant adminAddParticipant = new AdminAddParticipant();
adminAddParticipant.setAdminId("248698");
Participant participant = new Participant();
participant.setIntercomUserId("5310d8e8598c9a0b24000005");
// participant.setUserId("2"); // or find by user_id
// participant.setEmail("[email protected]"); // or find by user_id
adminAddParticipant.setParticipant(participant);
ParticipantResponse participantResponse = Conversation.addParticipant("19240007891", adminAddParticipant);

// user adding participant to conversation
UserAddParticipant userAddParticipant = new UserAddParticipant();
userAddParticipant.setIntercomUserId("575b4dbbd7f9c87f240008c5");
Participant participant = new Participant();
participant.setIntercomUserId("5310d8e8598c9a0b24000005");
// participant.setUserId("2"); // or find by user_id
// participant.setEmail("[email protected]"); // or find by user_id
userAddParticipant.setParticipant(participant);
ParticipantResponse participantResponse = Conversation.addParticipant("19240007891", userAddParticipant);

// removing participant from conversation
ParticipantResponse participantResponse = Conversation.removeParticipant("19240007891", "248698", "564320845c88872b60000012");
```

### Webhooks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 AdminAddParticipant {

@JsonProperty("admin_id")
public String adminId;

@JsonProperty("customer")
private Participant participant;

public String getAdminId() {
return adminId;
}

public AdminAddParticipant setAdminId(String adminId) {
this.adminId = adminId;
return this;
}

private Participant getParticipant(){
return participant;
}

public AdminAddParticipant setParticipant(Participant participant){
this.participant = participant;
return this;
}

@Override
public String toString() {
return "AdminAddParticipant{" +
"adminId='" + adminId + "\'" +
",participant=" + participant +
"} " + super.toString();
}
}
32 changes: 32 additions & 0 deletions intercom-java/src/main/java/io/intercom/api/Conversation.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ public static Conversation markAsRead(String id) {
.put(Conversation.class, new ConversationRead());
}

public static ParticipantResponse addParticipant(String id, AdminAddParticipant adminAddParticipant) {
final URI uri = UriBuilder.newBuilder()
.path("conversations")
.path(id)
.path("customers")
.build();
return new HttpClient(uri)
.post(ParticipantResponse.class, adminAddParticipant);
}

public static ParticipantResponse addParticipant(String id, UserAddParticipant userAddParticipant) {
final URI uri = UriBuilder.newBuilder()
.path("conversations")
.path(id)
.path("customers")
.build();
return new HttpClient(uri)
.post(ParticipantResponse.class, userAddParticipant);
}

public static ParticipantResponse removeParticipant(String id, String admin_id, String participantIntercomId) {
Map<String, String> params = new HashMap<String,String>();
params.put("admin_id", admin_id);
final URI uri = UriBuilder.newBuilder()
.path("conversations")
.path(id)
.path("customers")
.path(participantIntercomId)
.build();
return DataResource.delete(params, uri, ParticipantResponse.class);
}

public static UserMessage create(UserMessage message) {
return DataResource.create(message, "messages", UserMessage.class);
}
Expand Down
5 changes: 5 additions & 0 deletions intercom-java/src/main/java/io/intercom/api/DataResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public static <T> T delete(Map<String, String> params, String collectionPath, Cl
return resource.delete(c);
}

public static <T> T delete(Map<String, String> params, URI uri, Class<T> c) {
final HttpClient resource = new HttpClient(uri);
return resource.delete(c, params);
}

public static <C> C list(Map<String, String> params, String collectionPath, Class<C> c) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).query(params).build());
return resource.get(c);
Expand Down
5 changes: 5 additions & 0 deletions intercom-java/src/main/java/io/intercom/api/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public <T> T delete(Class<T> reqres) {
return executeHttpMethod("DELETE", null, getJavaType(reqres));
}

public <T, E> T delete(Class<T> reqres, E entity) {
headers.put("Content-Type", APPLICATION_JSON);
return executeHttpMethod("DELETE", entity, getJavaType(reqres));
}

public <T, E> T put(Class<T> reqres, E entity) {
headers.put("Content-Type", APPLICATION_JSON);
return executeHttpMethod("PUT", (E) entity, getJavaType(reqres));
Expand Down
81 changes: 81 additions & 0 deletions intercom-java/src/main/java/io/intercom/api/Participant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 Participant {

@JsonProperty("intercom_user_id")
private String intercomUserId;

@JsonProperty("user_id")
private String userId;

@JsonProperty("email")
private String email;

public Participant() {
}

public String getIntercomUserId() {
return intercomUserId;
}

public Participant setIntercomUserId(String intercomUserId) {
this.intercomUserId = intercomUserId;;
return this;
}

public String getUserId() {
return userId;
}

public Participant setUserId(String userId) {
this.userId = userId;
return this;
}

public String getEmail() {
return email;
}

public Participant setEmail(String email) {
this.email = email;
return this;
}

@Override
public int hashCode() {
int result = intercomUserId != null ? intercomUserId.hashCode() : 0;
result = 31 * result + (userId != null ? userId.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Participant customer = (Participant) o;

if (intercomUserId != null ? !intercomUserId.equals(customer.intercomUserId) : customer.intercomUserId != null) return false;
if (userId != null ? !userId.equals(customer.userId) : customer.userId != null) return false;
if (email != null ? !email.equals(customer.email) : customer.email != null) return false;
return true;
}

@Override
public String toString() {
return "Participant{" +
", intercomUserId='" + intercomUserId+ '\'' +
", userId='" + userId+ '\'' +
", email='" + email+ '\'' +
"} " + super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.intercom.api;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ParticipantResponse {

@JsonProperty("customers")
private List<Customer> customers;

public ParticipantResponse() {
}

public List<Customer> getCustomers(){
return customers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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 UserAddParticipant {

@JsonProperty("intercom_user_id")
public String intercomUserId;

@JsonProperty("user_id")
public String userId;

@JsonProperty("email")
public String email;

@JsonProperty("customer")
private Participant participant;

public String getIntercomUserId() {
return intercomUserId;
}

public UserAddParticipant setIntercomUserId(String intercomUserId) {
this.intercomUserId = intercomUserId;
return this;
}

public String getUserID() {
return userId;
}

public UserAddParticipant setUserID(String userId) {
this.userId = userId;
return this;
}

public String getEmail() {
return email;
}

public UserAddParticipant setEmail(String email) {
this.email = email;
return this;
}

private Participant getParticipant(){
return participant;
}

public UserAddParticipant setParticipant(Participant participant){
this.participant = participant;
return this;
}

@Override
public String toString() {
return "UserAddParticipant{" +
"intercomUserId='" + intercomUserId + "\'" +
"userId='" + userId + "\'" +
"email='" + email + "\'" +
",participant=" + participant +
"} " + super.toString();
}
}

0 comments on commit 4b63f9e

Please sign in to comment.