Skip to content

Allow admin message to contacts #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -498,10 +498,16 @@ while(notes.hasNext()) {
```java
// send a message to a user
User user = new User().setId("5310d8e8598c9a0b24000005");
// Alternatively identify user by user_id or email
// User user = new User().setUserId("1")
// User user = new User().setEmail("malcolm@serenity.io")
Contact contact = new Contact().setId("5ab313046e4997e35bc13e7c");
// Alternatively identify contact by user_id
// Contact contact = new Contact().setUserId("697ea3e0-227d-4d70-b776-1652e94f9583");
Admin admin = new Admin().setId("1");
AdminMessage adminMessage = new AdminMessage()
.setAdmin(admin)
.setUser(user)
.setUser(user) // or .setContact(contact)
.setSubject("This Land")
.setBody("Har har har! Mine is an evil laugh!")
.setMessageType("email")
20 changes: 20 additions & 0 deletions intercom-java/src/main/java/io/intercom/api/AdminMessage.java
Original file line number Diff line number Diff line change
@@ -37,8 +37,16 @@ public class AdminMessage extends TypedData {
private Admin admin;

@JsonProperty("to")
private TypedData to(){
if(user != null) return user;
if(contact != null) return contact;
return null;
};

private User user;

private Contact contact;

public AdminMessage() {
}

@@ -121,6 +129,15 @@ public AdminMessage setUser(User user) {
return this;
}

public Contact getContact() {
return contact;
}

public AdminMessage setContact(Contact contact) {
this.contact = contact;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -138,6 +155,7 @@ public boolean equals(Object o) {
if (!type.equals(message.type)) return false;
//noinspection RedundantIfStatement
if (user != null ? !user.equals(message.user) : message.user != null) return false;
if (contact != null ? !contact.equals(message.contact) : message.contact != null) return false;

return true;
}
@@ -153,6 +171,7 @@ public int hashCode() {
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (admin != null ? admin.hashCode() : 0);
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + (contact != null ? contact.hashCode() : 0);
return result;
}

@@ -167,6 +186,7 @@ public String toString() {
", createdAt=" + createdAt +
", admin=" + admin +
", user=" + user +
", contact=" + contact +
"} " + super.toString();
}