intercom-client 2.11.2 → 3.0.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Circle CI](https://circleci.com/gh/intercom/intercom-node.png?style=shield)](https://circleci.com/gh/intercom/intercom-node)
4
4
  [![npm](https://img.shields.io/npm/v/intercom-client)](https://www.npmjs.com/package/intercom-client)
5
- ![Intercom API Version](https://img.shields.io/badge/Intercom%20API%20Version-1.3-blue)
5
+ ![Intercom API Version](https://img.shields.io/badge/Intercom%20API%20Version-2.4-blue)
6
+ ![Typescript Supported](https://img.shields.io/badge/Typescript-Supported-lightgrey)
6
7
 
7
8
  > Official Node bindings to the [Intercom API](https://api.intercom.io/docs)
8
9
 
@@ -10,11 +11,7 @@
10
11
 
11
12
  ### Maintenance
12
13
 
13
- We're currently building a new team to provide in-depth and dedicated SDK support.
14
-
15
- In the meantime, we'll be operating on limited capacity, meaning all pull requests will be evaluated on a best effort basis and will be limited to critical issues.
16
-
17
- We'll communicate all relevant updates as we build this new team and support strategy in the coming months.
14
+ Current repository is a new WIP version of Node SDK, that supports latest API version (v2.4 as of 14/01/2022)
18
15
 
19
16
  ## Installation
20
17
 
@@ -35,590 +32,870 @@ yarn test
35
32
  Compile using babel:
36
33
 
37
34
  ```bash
38
- yarn gulp babel
39
- ```
40
-
41
- Require Intercom:
42
-
43
- ```node
44
- var Intercom = require('./dist/index');
35
+ yarn prepublish
45
36
  ```
46
37
 
47
38
  ## Usage
48
39
 
49
- Require Intercom:
40
+ Import Intercom:
50
41
 
51
- ```node
52
- var Intercom = require('intercom-client');
42
+ ```typescript
43
+ import { Client } from './dist/index';
53
44
  ```
54
45
 
55
46
  Create a client using access tokens:
56
47
 
57
- ```node
58
- var client = new Intercom.Client({ token: 'my_token' });
48
+ ```typescript
49
+ const client = new Client({ tokenAuth: { token: 'my_token' } });
59
50
  ```
60
51
 
61
- ## Callbacks
52
+ ## Request Options
62
53
 
63
- This client library supports two kinds of callbacks:
54
+ This client library also supports passing in [`request` options](https://github.com/axios/axios#request-config):
64
55
 
65
- ```node
66
- client.users.list(function (d) {
67
- // d is the response from the server
56
+ ```typescript
57
+ const client = new Client({ tokenAuth: { token: 'my_token' } });
58
+ client.useRequestOpts({
59
+ baseURL: 'http://local.test-server.com',
68
60
  });
69
61
  ```
70
62
 
71
- Or
63
+ Note that certain request options (such as `json`, and certain `headers` names cannot be overriden).
72
64
 
73
- ```node
74
- client.users.list(function (err, d) {
75
- // err is an error response object, or null
76
- // d is a successful response object, or null
65
+ ### Setting the API version
66
+
67
+ We version our API (see the "Choose Version" section of the [API & Webhooks Reference](https://developers.intercom.com/intercom-api-reference/reference) for details). You can specify which version of the API to use when performing API requests using request options:
68
+
69
+ ```typescript
70
+ const client = new Client({ tokenAuth: { token: 'my_token' } });
71
+ client.useRequestOpts({
72
+ headers: {
73
+ 'Intercom-Version': 2.4,
74
+ },
77
75
  });
78
76
  ```
79
77
 
80
- ## Promises
78
+ ## Examples
81
79
 
82
- This client library also supports using Promises instead of callbacks:
80
+ ### Admins
83
81
 
84
- ```node
85
- client.users.create({ email: 'foo@bar.com' }).then(function (r) {
86
- // ...
87
- });
82
+ #### [Retrieve admin](https://developers.intercom.com/intercom-api-reference/reference/view-an-admin)
83
+
84
+ ```typescript
85
+ const admin = await client.admins.find({ id: '123' });
88
86
  ```
89
87
 
90
- ## Request Options
88
+ #### [Set Admin away](https://developers.intercom.com/intercom-api-reference/reference/set-admin-away-mode)
91
89
 
92
- This client library also supports passing in [`request` options](https://github.com/request/request#requestoptions-callback):
90
+ ```typescript
91
+ await client.admins.away({
92
+ adminId: '123',
93
+ enableAwayMode: true,
94
+ enableReassignMode: false,
95
+ });
96
+ ```
93
97
 
94
- ```node
95
- var client = new Intercom.Client({ token: 'my_token' });
96
- client.useRequestOpts({
97
- baseUrl: 'http://local.test-server.com',
98
- // Uses the forever-agent / http(s).Agent({keepAlive:true})
99
- forever: true
98
+ #### [List all activity logs](https://developers.intercom.com/intercom-api-reference/reference/view-admin-activity-logs)
99
+
100
+ ```typescript
101
+ await client.admins.listAllActivityLogs({
102
+ before: new Date('Fri, 17 Dec 2021 18:02:18 GMT');,
103
+ after: new Date('Fri, 17 Dec 2021 18:02:18 GMT');,
100
104
  });
101
105
  ```
102
106
 
103
- Note that certain request options (such as `json`, and certain `headers` names cannot be overriden).
107
+ #### [List all admins](https://developers.intercom.com/intercom-api-reference/reference/list-admins)
104
108
 
105
- ### Setting the API version
109
+ ```typescript
110
+ const admins = await client.admins.list();
111
+ ```
106
112
 
107
- We version our API (see the "Choose Version" section of the [API & Webhooks Reference](https://developers.intercom.com/intercom-api-reference/reference) for details). You can specify which version of the API to use when performing API requests using request options:
113
+ ### Companies
108
114
 
109
- ```node
110
- var client = new Intercom.Client({ token: 'my_token' });
111
- client.useRequestOpts({
112
- headers: {
113
- 'Intercom-Version': 1.2
114
- }
115
+ #### [Create a company](https://developers.intercom.com/intercom-api-reference/reference/create-or-update-company)
116
+
117
+ ```typescript
118
+ const company = await client.companies.create({
119
+ createdAt: dateToUnixTimestamp(new Date()),
120
+ companyId: '46029',
121
+ name: 'BestCompanyInc.',
122
+ monthlySpend: 9001,
123
+ plan: '1. Get pizzaid',
124
+ size: 62049,
125
+ website: 'http://the-best.one',
126
+ industry: 'The Best One',
127
+ customAttributes: {},
115
128
  });
116
129
  ```
117
130
 
118
- ## Users
131
+ #### [Update a company](https://developers.intercom.com/intercom-api-reference/reference/update-a-company)
119
132
 
120
- ```node
121
- // Create a user
122
- client.users.create({
123
- email: 'jayne@serenity.io',
124
- custom_attributes: {
125
- foo: 'bar'
126
- }
127
- }, callback);
128
-
129
- // Update a user
130
- client.users.update({
131
- email: 'jayne@serenity.io',
132
- custom_attributes: {
133
- foo: 'bar'
134
- }
135
- }, callback);
133
+ ```typescript
134
+ const company = await client.companies.create({
135
+ createdAt: dateToUnixTimestamp(new Date()),
136
+ companyId: '46029',
137
+ name: 'BestCompanyInc.',
138
+ monthlySpend: 9001,
139
+ plan: '1. Get pizzaid',
140
+ size: 62049,
141
+ website: 'http://the-best.one',
142
+ industry: 'The Best One',
143
+ customAttributes: {},
144
+ });
136
145
  ```
137
146
 
138
- ```node
139
- // Create/update a user with custom attributes
140
- client.users.create({ email: 'jayne@serenity.io', custom_attributes: { invited_friend: true } }, callback);
147
+ #### [Retrieve a company](https://developers.intercom.com/intercom-api-reference/reference/view-a-company)
148
+
149
+ ##### By id
150
+
151
+ ```typescript
152
+ const company = await client.companies.find({
153
+ companyId: 123,
154
+ });
141
155
  ```
142
156
 
143
- ```node
144
- // List users
145
- client.users.list(callback);
157
+ ##### By name
158
+
159
+ ```typescript
160
+ const company = await client.companies.find({
161
+ name: 'bruh moment inc.',
162
+ });
146
163
  ```
147
164
 
148
- ```node
149
- // List users by tag or segment
150
- client.users.listBy({ tag_id: 'haven' }, callback);
165
+ #### [Delete a company](https://developers.intercom.com/intercom-api-reference/reference/delete-a-company)
166
+
167
+ ```typescript
168
+ const company = await client.companies.delete({
169
+ id: 62049,
170
+ });
151
171
  ```
152
172
 
153
- ```node
154
- // Scroll through users list
155
- client.users.scroll.each({}, function(res) {
156
- // if you return a promise from your callback, the client will only scroll
157
- // after this promise has resolved
158
- new Bluebird((resolve) => {
159
- setTimeout(() => {
160
- console.log(res.body.users.length);
161
- // Your custom logic
162
- resolve();
163
- }, 500)
164
- })
173
+ #### [List all companies](https://developers.intercom.com/intercom-api-reference/reference/list-companies)
174
+
175
+ ##### With pagination
176
+
177
+ ```typescript
178
+ const companies = await client.companies.list({
179
+ page: 1,
180
+ perPage: 35,
181
+ order: Order.DESC,
165
182
  });
183
+ ```
184
+
185
+ ##### With TagId and SegmentId
166
186
 
187
+ ```typescript
188
+ const companies = await client.companies.list({
189
+ tagId: '1234',
190
+ segmentId: '4567',
191
+ });
167
192
  ```
168
193
 
169
- ```node
170
- // Find user by id
171
- client.users.find({ id: '55b9eaf' }, callback);
194
+ #### [Scroll over companies](https://developers.intercom.com/intercom-api-reference/reference/iterating-over-all-companies)
172
195
 
173
- // Find user by user_id
174
- client.users.find({ user_id: 'foobar' }, callback);
196
+ ##### Using infinite scroll
175
197
 
176
- // Find user by email
177
- client.users.find({ email: 'jayne@serenity.io' }, callback);
198
+ ```typescript
199
+ const companies = await client.companies.scroll.each({});
178
200
  ```
179
201
 
180
- ```node
181
- // Archive user by id (https://developers.intercom.com/intercom-api-reference/reference#archive-a-user)
182
- client.users.archive({ id: '1234' }, callback);
202
+ ##### Using manual scroll
203
+
204
+ ```typescript
205
+ const companies = await client.companies.scroll.next({
206
+ scrollParam: '123_soleil',
207
+ });
183
208
  ```
184
209
 
185
- ```node
186
- // Permanently delete a user by id (https://developers.intercom.com/intercom-api-reference/reference#delete-users)
187
- const intercomUserId = '123'
188
- client.users.requestPermanentDeletion(intercomUserId, callback);
210
+ #### [Attach a contact](https://developers.intercom.com/intercom-api-reference/reference/attach-contact-to-company)
211
+
212
+ ```typescript
213
+ const response = await client.companies.attachContact({
214
+ contactId: '123',
215
+ companyId: '234',
216
+ });
189
217
  ```
190
218
 
191
- ```node
192
- // Permanently delete a user by id in params
193
- client.users.requestPermanentDeletionByParams({ id: '55b9eaf' }, callback);
219
+ #### [Detach a contact](https://developers.intercom.com/intercom-api-reference/reference/detach-contact-from-company)
220
+
221
+ ```typescript
222
+ const response = await client.companies.detachContact({
223
+ contactId: '123',
224
+ companyId: '234',
225
+ });
226
+ ```
194
227
 
195
- // Permanently delete a user by user_id
196
- client.users.requestPermanentDeletionByParams({ user_id: 'foobar' }, callback);
228
+ #### [List attached contacts](https://developers.intercom.com/intercom-api-reference/reference/list-company-contacts)
197
229
 
198
- // Permanently delete a user by email
199
- client.users.requestPermanentDeletionByParams({ email: 'jayne@serenity.io' }, callback);
230
+ ```typescript
231
+ const response = await client.companies.listAttachedContacts({
232
+ companyId: '123',
233
+ page: 1,
234
+ perPage: 15,
235
+ });
200
236
  ```
201
237
 
202
- ## Leads
238
+ #### [List attached segments](https://developers.intercom.com/intercom-api-reference/reference/list-attached-segments-1)
203
239
 
204
- ```node
205
- // Create a contact
206
- client.leads.create(function (r) {
207
- console.log(r);
240
+ ```typescript
241
+ const response = await client.companies.listAttachedSegments({
242
+ companyId: '123',
208
243
  });
244
+ ```
245
+
246
+ ### Contacts
209
247
 
210
- // Create a contact with attributes
211
- client.leads.create({ email: 'jayne@serenity.io' }, function (r) {
212
- console.log(r);
248
+ #### [Create Contact](https://developers.intercom.com/intercom-api-reference/reference/create-contact)
249
+
250
+ ##### With User Role
251
+
252
+ ```typescript
253
+ const user = await client.contacts.createUser({
254
+ externalId: '536e564f316c83104c000020',
255
+ phone: '+48370044567',
256
+ name: 'Niko Bellic',
257
+ avatar: 'https://nico-from-gta-iv.com/lets_go_bowling.jpg',
258
+ signedUpAt: 1638203719,
259
+ lastSeenAt: 1638203720,
260
+ ownerId: '536e564f316c83104c000021',
261
+ isUnsubscribedFromEmails: true,
213
262
  });
214
263
  ```
215
264
 
216
- ```node
217
- // Update a contact by id
218
- client.leads.update({ id: '5435345', email: 'wash@serenity.io' }, callback);
265
+ ##### With Lead Role
266
+
267
+ ```typescript
268
+ const lead = await client.contacts.createLead({
269
+ phone: '+48370044567',
270
+ name: 'Roman Bellic',
271
+ avatar: 'https://nico-from-gta-iv.com/lets_go_bowling_yey.jpg',
272
+ signedUpAt: 1638203719,
273
+ lastSeenAt: 1638203720,
274
+ ownerId: '536e564f316c83104c000021',
275
+ isUnsubscribedFromEmails: true,
276
+ });
219
277
  ```
220
278
 
221
- ```node
222
- // List contacts
223
- client.leads.list(callback);
279
+ #### [Retrieve a Contact](https://developers.intercom.com/intercom-api-reference/reference/get-contact)
280
+
281
+ ```typescript
282
+ const response = await client.contacts.find({ id: '123' });
224
283
  ```
225
284
 
226
- ```node
227
- // Scroll through contacts list
228
- client.leads.scroll.each({}, function(res) {
229
- // if you return a promise from your callback, the client will only scroll
230
- // after this promise has resolved
231
- new Bluebird((resolve) => {
232
- setTimeout(() => {
233
- console.log(res.body.contacts.length);
234
- // Your custom logic
235
- resolve();
236
- }, 500)
237
- })
285
+ #### [Update a Contact](https://developers.intercom.com/intercom-api-reference/reference/update-contact)
286
+
287
+ ```typescript
288
+ const response = await client.contacts.update({
289
+ id: '123',
290
+ role: Role.USER,
291
+ name: 'Roman The Bowling Fan',
292
+ customAttributes: {
293
+ callBrother: "Hey Niko, it's me – Roman. Let's go bowling!",
294
+ },
238
295
  });
239
296
  ```
240
297
 
241
- ```node
242
- // List contacts by email
243
- client.leads.listBy({ email: 'wash@serenity.io' }, callback);
298
+ #### [Delete a Contact](https://developers.intercom.com/intercom-api-reference/reference/delete-contact)
299
+
300
+ ```typescript
301
+ const response = await client.contacts.delete({ id: '123' });
244
302
  ```
245
303
 
246
- ```node
247
- // Find contact by id
248
- client.leads.find({ id: '5342423' }, callback);
304
+ #### [Archive a Contact](https://developers.intercom.com/intercom-api-reference/reference/archive-a-contact)
305
+
306
+ ```typescript
307
+ const response = await client.contacts.archive({ id: '123' });
249
308
  ```
250
309
 
251
- ```node
252
- // Delete contact by id
253
- client.leads.delete({ id: '5342423' }, callback);
310
+ #### [Unarchive a Contact](https://developers.intercom.com/intercom-api-reference/reference/unarchive-a-contact)
311
+
312
+ ```typescript
313
+ const response = await client.contacts.unarchive({ id: '123' });
254
314
  ```
255
315
 
256
- ```node
257
- // Convert Leads into Users
258
- var conversion = {
259
- contact: { user_id: '1234-5678-9876' },
260
- user: { email: 'mal@serenity.io' }
261
- };
262
- client.leads.convert(conversion, callback);
316
+ #### [Merge two Contacts](https://developers.intercom.com/intercom-api-reference/reference/merge-contact)
317
+
318
+ ```typescript
319
+ const response = await client.contacts.mergeLeadInUser({
320
+ leadId: '123',
321
+ userId: '234',
322
+ });
323
+ ```
324
+
325
+ #### [Search for contacts](https://developers.intercom.com/intercom-api-reference/reference/search-for-contacts)
326
+
327
+ ```typescript
328
+ const response = await client.contacts.search({
329
+ data: {
330
+ query: {
331
+ operator: Operators.AND,
332
+ value: [
333
+ {
334
+ operator: Operators.AND,
335
+ value: [
336
+ {
337
+ field: 'updated_at',
338
+ operator: Operators.GREATER_THAN,
339
+ value: 1560436650,
340
+ },
341
+ {
342
+ field: 'conversation_rating.rating',
343
+ operator: Operators.EQUALS,
344
+ value: 1,
345
+ },
346
+ ],
347
+ },
348
+ {
349
+ operator: Operators.OR,
350
+ value: [
351
+ {
352
+ field: 'updated_at',
353
+ operator: Operators.GREATER_THAN,
354
+ value: 1560436650,
355
+ },
356
+ {
357
+ field: 'conversation_rating.rating',
358
+ operator: Operators.EQUALS,
359
+ value: 2,
360
+ },
361
+ ],
362
+ },
363
+ ],
364
+ },
365
+ pagination: {
366
+ per_page: 5,
367
+ starting_after:
368
+ 'WzE2MzU4NjA2NDgwMDAsIjYxODJiNjJlNDM4YjdhM2EwMWE4YWYxNSIsMl0=',
369
+ },
370
+ sort: { field: 'name', order: SearchContactOrderBy.ASC },
371
+ },
372
+ });
263
373
  ```
264
374
 
265
- ## Customers
375
+ #### [List all Contacts](https://developers.intercom.com/intercom-api-reference/reference/list-contacts)
266
376
 
267
- ```node
268
- // Search for customers
269
- client.customers.search({
270
- query: { field: 'name', operator: '=', name: 'Alice'},
271
- sort: { field: 'name', order: 'ascending'},
272
- pagination: { per_page: 10 }
273
- }, callback);
377
+ ##### With cursor
378
+
379
+ ```typescript
380
+ const response = await client.contacts.list({
381
+ perPage: 5,
382
+ startingAfter:
383
+ 'WzE2MzU3NzU4NjkwMDAsIjYxODJiNjJhMDMwZTk4OTBkZWU4NGM5YiIsMl0=',
384
+ });
274
385
  ```
275
386
 
276
- ## Visitors
387
+ ##### Without a cursor
277
388
 
278
- ```node
279
- // Update a visitor by id
280
- client.visitors.update({ id: '5435345', email: 'wash@serenity.io' }, callback);
389
+ ```typescript
390
+ const response = await client.contacts.list();
281
391
  ```
282
392
 
283
- ```node
284
- // Find visitor by id or user_id
285
- client.visitors.find({ id: '5342423' }, callback);
286
- client.visitors.find({ user_id: '5b868511-ca3b-4eac-8d26-cfd82a83ac76' }, callback);
393
+ #### [List attached companies](https://developers.intercom.com/intercom-api-reference/reference/list-companies-of-contact)
394
+
395
+ ```typescript
396
+ const response = await client.contacts.listAttachedCompanies({
397
+ id: '123',
398
+ perPage: 5,
399
+ page: 1,
400
+ });
287
401
  ```
288
402
 
289
- ```node
290
- // Delete visitor by id
291
- client.visitors.delete({ id: '5342423' }, callback);
403
+ #### [List attached tags](https://developers.intercom.com/intercom-api-reference/reference/list-tags-of-contact)
404
+
405
+ ```typescript
406
+ const response = await client.contacts.listAttachedTags({ id: '123' });
292
407
  ```
293
408
 
294
- ```node
295
- // Convert visitors into Users
296
- var conversion = {
297
- visitor: { user_id: '1234-5678-9876' },
298
- user: { email: 'mal@serenity.io' },
299
- type: "user"
300
- };
301
- client.visitors.convert(conversion, callback);
409
+ #### [List attached segments](https://developers.intercom.com/intercom-api-reference/reference/list-attached-segments)
410
+
411
+ ```typescript
412
+ const response = await client.contacts.listAttachedSegments({ id: '123' });
302
413
  ```
303
414
 
304
- ```node
305
- // Convert visitors into Lead
306
- var conversion = {
307
- visitor: { user_id: '1234-5678-9876' },
308
- type: "lead"
309
- };
310
- client.visitors.convert(conversion, callback);
415
+ #### [List attached email subscriptions](https://developers.intercom.com/intercom-api-reference/reference/list-attached-email-subscriptions)
416
+
417
+ ```typescript
418
+ const response = await client.contacts.listAttachedEmailSubscriptions({
419
+ id: '123',
420
+ });
311
421
  ```
312
422
 
313
- ## Companies
423
+ ### Conversations
314
424
 
315
- ```node
316
- // Create/update a company
317
- client.companies.create({ company_id: '1234', name: 'serenity' }, function (r) {
318
- console.log(r);
425
+ #### [Create a conversation](https://developers.intercom.com/intercom-api-reference/reference/create-a-conversation)
426
+
427
+ ```typescript
428
+ const response = await client.conversations.create({
429
+ userId: '123',
430
+ body: 'Hello darkness my old friend',
319
431
  });
320
432
  ```
321
433
 
322
- ```node
323
- // List companies
324
- client.companies.list(callback);
434
+ #### [Retrieve a conversation](https://developers.intercom.com/intercom-api-reference/reference/retrieve-a-conversation)
435
+
436
+ ##### Formatted text
437
+
438
+ ```typescript
439
+ const response = await client.conversations.find({
440
+ id: '123',
441
+ });
325
442
  ```
326
443
 
327
- ```node
328
- // List companies by tag or segment
329
- client.companies.listBy({ tag_id: 'haven' }, callback);
444
+ ##### As plain text
445
+
446
+ ```typescript
447
+ const response = await client.conversations.find({
448
+ id: '123',
449
+ inPlainText: true,
450
+ });
330
451
  ```
331
452
 
332
- ```node
333
- // Scroll through companies list
334
- client.companies.scroll.each({}, function(res) {
335
- // if you return a promise from your callback, the client will only scroll
336
- // after this promise has resolved
337
- new Bluebird((resolve) => {
338
- setTimeout(() => {
339
- console.log(res.body.companies.length);
340
- // Your custom logic
341
- resolve();
342
- }, 500)
343
- })
453
+ #### [Update a conversation](https://developers.intercom.com/intercom-api-reference/reference/update-a-conversation)
454
+
455
+ ```typescript
456
+ const response = await client.conversations.update({
457
+ id,
458
+ markRead: true,
459
+ customAttributes: {
460
+ anything: 'you want',
461
+ },
344
462
  });
345
463
  ```
346
464
 
347
- ```node
348
- // Find company by id
349
- client.companies.find({ id: '1234' }, callback);
465
+ #### [Reply to a conversation](https://developers.intercom.com/intercom-api-reference/reference/reply-to-a-conversation)
466
+
467
+ ##### By id
468
+
469
+ ###### As user
470
+
471
+ ```typescript
472
+ const response = await client.conversations.replyByIdAsUser({
473
+ id: '098',
474
+ body: 'blablbalba',
475
+ intercomUserId: '123',
476
+ attachmentUrls: '345',
477
+ });
350
478
  ```
351
479
 
352
- ```node
353
- // List company users by id or company_id
354
- client.companies.listUsers({ id: '1234' }, callback);
355
- client.companies.listUsers({ company_id: '1234' }, callback);
480
+ ###### As admin
481
+
482
+ ```typescript
483
+ const response = await client.conversations.replyByIdAsAdmin({
484
+ id: '098',
485
+ adminId: '458',
486
+ messageType: ReplyToConversationMessageType.NOTE,
487
+ body: '<b>Bee C</b>',
488
+ attachmentUrls: ['https://site.org/bebra.jpg'],
489
+ });
356
490
  ```
357
491
 
358
- ## Events
492
+ ##### By last conversation
359
493
 
360
- Note: events will work when identified by 'email'. The `event_name` and `created_at` params are both required. Either `user_id` OR `email` is required.
494
+ ###### As user
361
495
 
362
- ```node
363
- // Create a event
364
- client.events.create({
365
- event_name: 'Foo',
366
- created_at: 1439826340,
367
- user_id: 'bar',
368
- metadata: { type: 'baz' }
369
- }, function (d) {
370
- console.log(d);
496
+ ```typescript
497
+ const response = await client.conversations.replyByLastAsUser({
498
+ body: 'blablbalba',
499
+ intercomUserId: '123',
500
+ attachmentUrls: '345',
371
501
  });
372
502
  ```
373
503
 
374
- ```node
375
- // List events by user
376
- client.events.listBy({
377
- type: 'user',
378
- user_id: 'bar'
379
- }, callback);
504
+ ###### As admin
505
+
506
+ ```typescript
507
+ const response = await client.conversations.replyByLastAsAdmin({
508
+ adminId: '458',
509
+ messageType: ReplyToConversationMessageType.NOTE,
510
+ body: '<b>Bee C</b>',
511
+ attachmentUrls: ['https://site.org/bebra.jpg'],
512
+ });
380
513
  ```
381
514
 
382
- ## Counts
515
+ #### [Assign a conversation](https://developers.intercom.com/intercom-api-reference/reference/assign-a-conversation)
383
516
 
384
- ```node
385
- client.counts.appCounts(callback);
517
+ ##### As team without assignment rules
386
518
 
387
- client.counts.conversationCounts(callback);
519
+ ```typescript
520
+ const response = await client.conversations.assign({
521
+ id: '123',
522
+ type: AssignToConversationUserType.TEAM,
523
+ adminId: '456',
524
+ assigneeId: '789',
525
+ body: '<b>blablbalba</b>',
526
+ });
527
+ ```
388
528
 
389
- client.counts.conversationAdminCounts(callback);
529
+ ##### As team with assignment rules
390
530
 
391
- client.counts.userTagCounts(callback);
531
+ ```typescript
532
+ const response = await client.conversations.assign({
533
+ id: '123',
534
+ withRunningAssignmentRules: true,
535
+ });
536
+ ```
392
537
 
393
- client.counts.userSegmentCounts(callback);
538
+ #### [Snooze a conversation](https://developers.intercom.com/intercom-api-reference/reference/snooze-a-conversation)
394
539
 
395
- client.counts.companyTagCounts(callback);
540
+ ```typescript
541
+ const response = await client.conversations.snooze({
542
+ id: '123',
543
+ adminId: '234',
544
+ snoozedUntil: '1501512795',
545
+ });
546
+ ```
396
547
 
397
- client.counts.companySegmentCounts(callback);
548
+ #### [Close a conversation](https://developers.intercom.com/intercom-api-reference/reference/close-a-conversation)
398
549
 
399
- client.counts.companyUserCounts(callback);
550
+ ```typescript
551
+ const response = await client.conversations.close({
552
+ id: '123',
553
+ adminId: '456',
554
+ body: "That's it...",
555
+ });
400
556
  ```
401
557
 
402
- ## Admins
558
+ #### [Open a conversation](https://developers.intercom.com/intercom-api-reference/reference/open-a-conversation)
403
559
 
404
- ```node
405
- // List admins
406
- client.admins.list(callback);
560
+ ```typescript
561
+ const response = await client.conversations.open({
562
+ id: '123',
563
+ adminId: '234',
564
+ });
407
565
  ```
408
566
 
409
- ```node
410
- // Find current admin (only works with OAuth tokens)
411
- client.admins.me(callback);
567
+ #### [Attach a contact to group conversation](https://developers.intercom.com/intercom-api-reference/reference/adding-to-group-conversations-as-admin)
568
+
569
+ ##### As admin, using intercomUserid
570
+
571
+ ```typescript
572
+ const response = await client.conversations.attachContactAsAdmin({
573
+ id: '123',
574
+ adminId: '234',
575
+ customer: {
576
+ intercomUserId: '456',
577
+ },
578
+ });
412
579
  ```
413
580
 
414
- ```node
415
- // Find admin by ID
416
- client.admins.find('123456789', callback);
581
+ ##### As contact, using intercomUserid
582
+
583
+ ```typescript
584
+ const response = await client.conversations.attachContactAsAdmin({
585
+ id: '123',
586
+ userId: '234',
587
+ customer: {
588
+ intercomUserId: '456',
589
+ },
590
+ });
417
591
  ```
418
592
 
419
- ```node
420
- // Update admin away mode and reassign settings
421
- client.admins.away('123456789', {'away_mode_enabled': true, 'away_mode_reassign': false}, callback);
593
+ #### [Delete a contact from group conversation as admin](https://developers.intercom.com/intercom-api-reference/reference/deleting-from-group-conversations)
594
+
595
+ ```typescript
596
+ const response = await client.conversations.detachContactAsAdmin({
597
+ conversationId: '123',
598
+ contactId: '456',
599
+ adminId: '789',
600
+ });
422
601
  ```
423
602
 
424
- ## Tags
603
+ #### [Search for conversations](https://developers.intercom.com/intercom-api-reference/reference/search-for-conversations)
604
+
605
+ ```typescript
606
+ const response = await client.conversations.search({
607
+ data: {
608
+ query: {
609
+ operator: Operators.AND,
610
+ value: [
611
+ {
612
+ operator: Operators.AND,
613
+ value: [
614
+ {
615
+ field: 'updated_at',
616
+ operator: Operators.GREATER_THAN,
617
+ value: 1560436650,
618
+ },
619
+ {
620
+ field: 'conversation_rating.rating',
621
+ operator: Operators.EQUALS,
622
+ value: 1,
623
+ },
624
+ ],
625
+ },
626
+ {
627
+ operator: Operators.OR,
628
+ value: [
629
+ {
630
+ field: 'updated_at',
631
+ operator: Operators.GREATER_THAN,
632
+ value: 1560436650,
633
+ },
634
+ {
635
+ field: 'conversation_rating.rating',
636
+ operator: Operators.EQUALS,
637
+ value: 2,
638
+ },
639
+ ],
640
+ },
641
+ ],
642
+ },
643
+ pagination: {
644
+ per_page: 5,
645
+ starting_after:
646
+ 'WzE2MzU4NjA2NDgwMDAsIjYxODJiNjJlNDM4YjdhM2EwMWE4YWYxNSIsMl0=',
647
+ },
648
+ sort: {
649
+ field: 'name',
650
+ order: SearchConversationOrderBy.DESC,
651
+ },
652
+ },
653
+ });
654
+ ```
425
655
 
426
- ```node
427
- // Create a tag
428
- client.tags.create({ name: 'haven' }, callback);
656
+ #### [List all conversations](https://developers.intercom.com/intercom-api-reference/reference/list-conversations)
657
+
658
+ ```typescript
659
+ const response = await client.conversations.list({
660
+ query: {
661
+ order: Order.DESC,
662
+ sort: SortBy.UpdatedAt,
663
+ page: 1,
664
+ perPage: 10,
665
+ },
666
+ });
429
667
  ```
430
668
 
431
- ```node
432
- // Tag a user by id
433
- client.tags.tag({ name: 'haven', users: [{ id: '54645654' }] }, callback);
669
+ #### [Redact a conversation](https://developers.intercom.com/intercom-api-reference/reference/redact-a-conversation-part)
670
+
671
+ ```typescript
672
+ const response = await client.conversations.redactConversationPart({
673
+ type: RedactConversationPartType.CONVERSATION_PART,
674
+ conversationId: '123',
675
+ conversationPartId: '456',
676
+ });
434
677
  ```
435
678
 
436
- ```node
437
- // Tag a company by id
438
- client.tags.tag({ name: 'haven', companies: [{ id: '54645654' }] }, callback);
679
+ ### Data Attributes
680
+
681
+ #### [Create Data Attribute](https://developers.intercom.com/intercom-api-reference/reference/create-data-attributes)
682
+
683
+ ```typescript
684
+ const response = await client.dataAttributes.create({
685
+ name: 'list_cda',
686
+ model: ModelType.CONTACT,
687
+ dataType: DataType.STRING,
688
+ description: 'You are either alive or dead',
689
+ options: [{ value: 'alive' }, { value: 'dead' }],
690
+ });
439
691
  ```
440
692
 
441
- ```node
442
- // Untag a user by id
443
- client.tags.untag({ name: 'haven', users: [{ id: '5345342' }] }, callback);
693
+ #### [Update Data Attribute](https://developers.intercom.com/intercom-api-reference/reference/update-data-attributes)
694
+
695
+ ```typescript
696
+ const response = await client.dataAttributes.update({
697
+ id: '123',
698
+ description: 'You are either alive or dead',
699
+ options: [{ value: 'alive' }, { value: 'dead' }],
700
+ archived: true,
701
+ });
444
702
  ```
445
703
 
446
- ```node
447
- // List tags
448
- client.tags.list(callback);
704
+ #### [List all Data Attributes](https://developers.intercom.com/intercom-api-reference/reference/list-data-attributes)
705
+
706
+ ```typescript
707
+ const response = await client.dataAttributes.list({
708
+ model: ModelType.CONTACT,
709
+ includeArchived: true,
710
+ });
449
711
  ```
450
712
 
451
- ```node
452
- // Delete a tag by id
453
- client.tags.delete({ id: '130963' }, callback);
713
+ ### Events
714
+
715
+ #### [Submit a data event](https://developers.intercom.com/intercom-api-reference/reference/list-data-attributes)
716
+
717
+ ```typescript
718
+ const response = await client.events.create({
719
+ eventName: 'placed-order',
720
+ createdAt: 1389913941,
721
+ userId: 'f4ca124298',
722
+ metadata: {
723
+ order_date: 1392036272,
724
+ stripe_invoice: 'inv_3434343434',
725
+ order_number: {
726
+ value: '3434-3434',
727
+ url: 'https://example.org/orders/3434-3434',
728
+ },
729
+ price: {
730
+ currency: 'usd',
731
+ amount: 2999,
732
+ },
733
+ },
734
+ });
454
735
  ```
455
736
 
456
- ## Segments
737
+ #### [List all data events](https://developers.intercom.com/intercom-api-reference/reference/list-user-events)
457
738
 
458
- ```node
459
- // List segments
460
- client.segments.list(callback);
739
+ ```typescript
740
+ const response = await client.events.listBy({
741
+ userId: '1234',
742
+ perPage: 2,
743
+ summary: true,
744
+ email: 'i_love_memes@gmail.com',
745
+ });
461
746
  ```
462
747
 
463
- ```node
464
- // Find segment by id
465
- client.segments.find({ id: '55719a4a' }, callback);
748
+ ### Messages
749
+
750
+ #### [Create a message](https://developers.intercom.com/intercom-api-reference/reference/admin-initiated-conversation)
751
+
752
+ ```typescript
753
+ const response = await client.messages.create({
754
+ messageType: 'email',
755
+ subject: 'This is our demand now',
756
+ body: 'Destroy ponies',
757
+ template: 'plain',
758
+ from: {
759
+ type: 'admin',
760
+ id: '394051',
761
+ },
762
+ to: {
763
+ type: 'user',
764
+ id: '536e564f316c83104c000020',
765
+ },
766
+ });
466
767
  ```
467
768
 
468
- ## Messages
769
+ ### Segments
469
770
 
470
- ```node
471
- // Admin initiated messages:
472
- // Sending an email to a User
473
- var message = {
474
- message_type: "email",
475
- subject: "Hey",
476
- body: "Ponies, cute small horses or something more sinister?",
477
- template: "plain",
478
- from: {
479
- type: "admin",
480
- id: "21599"
481
- },
482
- to: {
483
- type: "user",
484
- id: "55c1ce1def857c31f80001af"
485
- }
486
- }
487
-
488
- client.messages.create(message, callback);
771
+ #### [Retrieve a segment](https://developers.intercom.com/intercom-api-reference/reference/view-a-segment)
772
+
773
+ ```typescript
774
+ const response = await client.segments.find({
775
+ id: '123',
776
+ includeCount: true,
777
+ });
489
778
  ```
490
779
 
491
- ```node
492
- // Creating a user-initiated message:
493
- var message = {
494
- from: {
495
- type: "user",
496
- id: "55c1ce1def857c31f80001af"
497
- },
498
- body: "Howdy"
499
- }
780
+ #### [List all segments](https://developers.intercom.com/intercom-api-reference/reference/list-segments)
500
781
 
501
- client.messages.create(message, callback);
782
+ ```typescript
783
+ const response = await client.segments.list({
784
+ includeCount: true,
785
+ });
502
786
  ```
503
787
 
504
- ## Conversations
788
+ ### Tags
505
789
 
506
- Listing conversations ([documentation](https://developers.intercom.com/intercom-api-reference/reference#list-conversations)):
790
+ #### [Create or update a tag](https://developers.intercom.com/intercom-api-reference/reference/create-and-update-tags)
507
791
 
508
- ```node
509
- client.conversations.list({ type: 'admin', admin_id: 21599 }, callback);
792
+ ##### Create
793
+
794
+ ```typescript
795
+ const response = await client.tags.create({ name: 'haven' });
510
796
  ```
511
797
 
512
- ```node
513
- // Fetch a conversation
514
- client.conversations.find({ id: '1062682196' }, callback);
798
+ ##### Update
799
+
800
+ ```typescript
801
+ const response = await client.tags.update({ id: '123', name: 'haven' });
515
802
  ```
516
803
 
517
- ```node
518
- // Reply to a conversation
519
- var reply = {
520
- id: '1039067180',
521
- intercom_user_id: '55b26822ce97179e52001334',
522
- body: 'Some reply :)',
523
- type: 'user',
524
- message_type: 'comment'
525
- };
526
-
527
- client.conversations.reply(reply, callback);
528
-
529
- // Reply to a conversation with attachments
530
- var reply = {
531
- id: '1039067180',
532
- intercom_user_id: '55b26822ce97179e52001334',
533
- body: 'Some reply :)',
534
- type: 'user',
535
- message_type: 'comment',
536
- attachment_urls: ['http://www.example.com/myattachment.jpg']
537
- };
538
-
539
- client.conversations.reply(reply, callback);
804
+ #### [Delete a tag](https://developers.intercom.com/intercom-api-reference/reference/delete-a-tag)
805
+
806
+ ```typescript
807
+ const response = await client.tags.delete({ id: 'baz' });
540
808
  ```
541
809
 
542
- ```node
543
- // Assign a conversation to an admin
544
- var assignment = {
545
- id: '13879167940',
546
- type: 'admin',
547
- admin_id: '1309092',
548
- assignee_id: '1723471',
549
- message_type: 'assignment'
550
- };
810
+ #### [Attach a contact](https://developers.intercom.com/intercom-api-reference/reference/tag-contact)
551
811
 
552
- client.conversations.reply(assignment, callback);
812
+ ```typescript
813
+ const response = await client.tags.tagContact({
814
+ contactId: '123',
815
+ tagId: '234',
816
+ });
817
+ ```
553
818
 
554
- // Assign a conversation to unassigned
555
- var assignment = {
556
- id: '13879167940',
557
- type: 'admin',
558
- admin_id: '1309092',
559
- assignee_id: '0',
560
- message_type: 'assignment'
561
- }
819
+ #### [Attach a conversation](https://developers.intercom.com/intercom-api-reference/reference/attach-a-tag-to-a-conversation)
562
820
 
563
- client.conversations.reply(assignment, callback);
821
+ ```typescript
822
+ const response = await client.tags.tagConversation({
823
+ conversationId: '123',
824
+ tagId: '456',
825
+ adminId: '789',
826
+ });
564
827
  ```
565
828
 
566
- ```node
567
- // Mark a conversation as read
568
- client.conversations.markAsRead({ id: '1039067180' }, callback);
829
+ #### [Tag companies](https://developers.intercom.com/intercom-api-reference/reference/tag-companies)
830
+
831
+ ```typescript
832
+ const response = await client.tags.tagCompanies({
833
+ tagName: 'gutenTag',
834
+ companiesIds: ['123', '234', '456'],
835
+ });
569
836
  ```
570
837
 
571
- ## Notes
838
+ #### [Untag companies](https://developers.intercom.com/intercom-api-reference/reference/untag-companies)
572
839
 
573
- ```node
574
- // Create a note
575
- var note = {
576
- admin_id: 21599,
577
- body: 'Hello notes!',
578
- user: {
579
- id: '55b26822ce97179e52001334'
580
- }
581
- };
840
+ ```typescript
841
+ const response = await client.tags.tagCompanies({
842
+ tagName: 'gutenTag',
843
+ companiesIds: ['123', '234', '456'],
844
+ });
845
+ ```
846
+
847
+ #### [Untag conversation](https://developers.intercom.com/intercom-api-reference/reference/detach-a-tag-from-a-conversation)
582
848
 
583
- client.notes.create(note, callback);
849
+ ```typescript
850
+ const response = await client.tags.untagConversation({
851
+ conversationId: '123',
852
+ tagId: '345',
853
+ adminId: '678',
854
+ });
584
855
  ```
585
856
 
586
- ```node
587
- // List notes by user
588
- client.notes.list({ email: 'bob@intercom.io' }, callback);
857
+ #### [Untag contact](https://developers.intercom.com/intercom-api-reference/reference/untag-contact)
858
+
859
+ ```typescript
860
+ const response = await client.tags.untagContact({
861
+ contactId: '123',
862
+ tagId: '345',
863
+ });
589
864
  ```
590
865
 
591
- ```node
592
- //Fetch a note
593
- client.notes.find({ id: '3342887' }, callback);
866
+ #### [List all tags](https://developers.intercom.com/intercom-api-reference/reference/list-tags-for-an-app)
867
+
868
+ ```typescript
869
+ const response = await client.tags.list();
594
870
  ```
595
871
 
596
- ## Pagination
872
+ ### Teams
597
873
 
598
- When listing, the Intercom API may return a pagination object:
874
+ #### [Retrieve a team](https://developers.intercom.com/intercom-api-reference/reference/view-a-team)
599
875
 
600
- ```json
601
- {
602
- "pages": {
603
- "next": "..."
604
- }
605
- }
876
+ ```typescript
877
+ const response = await client.teams.find({
878
+ id: '123',
879
+ });
606
880
  ```
607
881
 
608
- You can grab the next page of results using the client:
882
+ #### [List all teams](https://developers.intercom.com/intercom-api-reference/reference/list-teams)
609
883
 
610
- ```node
611
- client.nextPage(response.pages, callback);
884
+ ```typescript
885
+ const response = await client.teams.list();
612
886
  ```
613
887
 
614
- ## Identity verification
888
+ ### Identity verification
615
889
 
616
890
  `intercom-node` provides a helper for using [identity verification](https://docs.intercom.com/configure-intercom-for-your-product-or-site/staying-secure/enable-identity-verification-on-your-web-product):
617
891
 
618
- ``` node
892
+ ```node
619
893
  import { IdentityVerification } from 'intercom-client';
620
894
 
621
- IdentityVerification.userHash({secretKey: 's3cre7', identifier: 'jayne@serenity.io'});
895
+ IdentityVerification.userHash({
896
+ secretKey: 's3cre7',
897
+ identifier: 'jayne@serenity.io',
898
+ });
622
899
  ```
623
900
 
624
901
  ## License
@@ -627,16 +904,16 @@ Apache-2.0
627
904
 
628
905
  ## Pull Requests
629
906
 
630
- - **Add tests!** Your patch won't be accepted if it doesn't have tests.
907
+ - **Add tests!** Your patch won't be accepted if it doesn't have tests.
631
908
 
632
- - **Document any change in behaviour**. Make sure the README and any other
633
- relevant documentation are kept up-to-date.
909
+ - **Document any change in behaviour**. Make sure the README and any other
910
+ relevant documentation are kept up-to-date.
634
911
 
635
- - **Create topic branches**. Don't ask us to pull from your master branch.
912
+ - **Create topic branches**. Don't ask us to pull from your master branch.
636
913
 
637
- - **One pull request per feature**. If you want to do more than one thing, send
638
- multiple pull requests.
914
+ - **One pull request per feature**. If you want to do more than one thing, send
915
+ multiple pull requests.
639
916
 
640
- - **Send coherent history**. Make sure each individual commit in your pull
641
- request is meaningful. If you had to make multiple intermediate commits while
642
- developing, please squash them before sending them to us.
917
+ - **Send coherent history**. Make sure each individual commit in your pull
918
+ request is meaningful. If you had to make multiple intermediate commits while
919
+ developing, please squash them before sending them to us.