Skip to content

Commit aa627da

Browse files
author
Timothy Lim
committed
Update webhook topics and add ping
1 parent 0ec97e7 commit aa627da

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,34 @@ Subscription subscription = new Subscription();
582582
subscription.setUrl(new URI("https://example.org/webhooks/1"));
583583
subscription.addTopic(Subscription.Topic.USER_CREATED);
584584
subscription.addTopic(Subscription.Topic.USER_TAG_CREATED);
585-
subscription.addTopic(Subscription.Topic.COMPANY);
586-
subscription.setAppID("pi3243fa");
587585
Subscription.create(subscription);
588586

587+
// create a subscribtion and subscribe to events
588+
Subscription subscription = new Subscription();
589+
subscription.addTopic(Subscription.Topic.EVENT_CREATED);
590+
Map<String,ArrayList<String>> metadata = new HashMap<String, ArrayList<String>>();
591+
ArrayList<String> events = new ArrayList<String>(Arrays.asList("cart"));
592+
metadata.put("event_names", events);
593+
subscription.setMetadata(metadata);
594+
subscription.setMetadata(metadata);
595+
Subscription.create(subscription);
596+
597+
// update a subscription
598+
Subscription subscription = Subscription.find("nsub_60ca7690-4020-11e4-b789-4961958e51bd");
599+
subscription.addTopic(Subscription.Topic.COMPANY_CREATED);
600+
Subscription updatedSubscription = Subscription.update(subscription);
601+
602+
// delete a subscription
603+
Subscription subscription = new Subscription();
604+
subscription.setId("nsub_83793feb-8394-4cb6-91d6-68ef4dd08a8e");
605+
Subscription deletedSubscription = Subscription.delete(subscription);
606+
589607
// find a subscription
590608
subscription = Subscription.find("nsub_60ca7690-4020-11e4-b789-4961958e51bd");
591609

610+
// ping a subscription
611+
Subscription.ping("nsub_60ca7690-4020-11e4-b789-4961958e51bd");
612+
592613
// list subscriptions
593614
SubscriptionCollection list = Subscription.list();
594615
while(list.hasNext()) {

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public static SubscriptionCollection list() throws InvalidException, Authorizati
4242
return DataResource.list(SENTINEL, "subscriptions", SubscriptionCollection.class);
4343
}
4444

45+
public static Subscription ping(String id) throws InvalidException, AuthorizationException {
46+
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path("subscriptions").path(id).path("ping").build());
47+
return resource.post(Subscription.class, null);
48+
}
49+
4550
public static NotificationCollection sentFeed(String id) throws InvalidException, AuthorizationException {
4651
final URI feedURI = UriBuilder.newBuilder()
4752
.path("subscriptions")
@@ -72,8 +77,16 @@ public static class Topic {
7277

7378
private final static String CONVERSATION_NAME = "conversation";
7479

80+
private final static String CONVERSATION_PART_NAME = "conversation_part";
81+
7582
private static final String USER_NAME = "user";
7683

84+
private static final String CONTACT_NAME = "contact";
85+
86+
private static final String VISITOR_NAME = "visitor";
87+
88+
private static final String EVENT_NAME = "event";
89+
7790
public static final Topic PING = new Topic("ping", SUBTYPE_WILDCARD);
7891

7992
public static final Topic COMPANY = new Topic(COMPANY_NAME, SUBTYPE_WILDCARD);
@@ -92,20 +105,42 @@ public static class Topic {
92105

93106
public static final Topic CONVERSATION_ADMIN_CLOSED = new Topic(CONVERSATION_NAME, "admin.closed");
94107

95-
public static final Topic CONVERSATION_ADMIN_OPEN = new Topic(CONVERSATION_NAME, "admin.open");
108+
public static final Topic CONVERSATION_ADMIN_OPEN = new Topic(CONVERSATION_NAME, "admin.opened");
96109

97110
public static final Topic CONVERSATION_ADMIN_NOTED = new Topic(CONVERSATION_NAME, "admin.noted");
98111

112+
public static final Topic CONVERSATION_ADMIN_SINGLE_CREATED = new Topic(CONVERSATION_NAME, "admin.single.created");
113+
114+
public static final Topic CONVERSATION_PART_TAG_CREATED= new Topic(CONVERSATION_PART_NAME, "tag.created");
115+
99116
public static final Topic USER = new Topic(USER_NAME, SUBTYPE_WILDCARD);
100117

101118
public static final Topic USER_CREATED = new Topic(USER_NAME, "created");
102119

120+
public static final Topic USER_DELETED = new Topic(USER_NAME, "deleted");
121+
122+
public static final Topic USER_EMAIL_UPDATED = new Topic(USER_NAME, "email.updated");
123+
103124
public static final Topic USER_UNSUBSCRIBED = new Topic(USER_NAME, "unsubscribed");
104125

105126
public static final Topic USER_TAG_CREATED = new Topic(USER_NAME, "tag.created");
106127

107128
public static final Topic USER_TAG_DELETED = new Topic(USER_NAME, "tag.deleted");
108129

130+
public static final Topic CONTACT = new Topic(CONTACT_NAME, SUBTYPE_WILDCARD);
131+
132+
public static final Topic CONTACT_ADDED_EMAIL = new Topic(CONTACT_NAME, "added_email");
133+
134+
public static final Topic CONTACT_CREATED= new Topic(CONTACT_NAME, "created");
135+
136+
public static final Topic CONTACT_SIGNED_UP = new Topic(CONTACT_NAME, "signed_up");
137+
138+
public static final Topic VISITOR = new Topic(VISITOR_NAME, SUBTYPE_WILDCARD);
139+
140+
public static final Topic VISITOR_SIGNED_UP = new Topic(VISITOR_NAME, "signed_up");
141+
142+
public static final Topic EVENT_CREATED = new Topic(EVENT_NAME, "created");
143+
109144
public static final Topic ALL_TOPIC = valueOf("all");
110145

111146
public static Topic valueOf(String type) throws IllegalArgumentException {

0 commit comments

Comments
 (0)