intercom-client 2.10.5 → 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
@@ -1,19 +1,22 @@
1
1
  # intercom-node
2
- > Official Node bindings to the Intercom API
3
2
 
4
- [![Circle CI](https://circleci.com/gh/intercom/intercom-node.png?style=badge)](https://circleci.com/gh/intercom/intercom-node)
3
+ [![Circle CI](https://circleci.com/gh/intercom/intercom-node.png?style=shield)](https://circleci.com/gh/intercom/intercom-node)
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-2.4-blue)
6
+ ![Typescript Supported](https://img.shields.io/badge/Typescript-Supported-lightgrey)
5
7
 
6
- [![npm version](https://badge.fury.io/js/intercom-client.svg)](http://badge.fury.io/js/intercom-client)
8
+ > Official Node bindings to the [Intercom API](https://api.intercom.io/docs)
7
9
 
8
- ## Installation
10
+ ## Project Updates
11
+
12
+ ### Maintenance
9
13
 
10
- [![docker_image 1](https://cloud.githubusercontent.com/assets/15954251/17524401/5743439e-5e56-11e6-8567-d3d9da1727da.png)](https://hub.docker.com/r/intercom/sdk-images/) <br>
11
- Try out our [Docker Image (Beta)](https://hub.docker.com/r/intercom/sdk-images/) to help you get started more quickly. <br>
12
- It should make it easier to get setup with the SDK and start interacting with the API. <br>
13
- (Note, this is in Beta and is for testing purposes only, it should not be used in production)
14
+ Current repository is a new WIP version of Node SDK, that supports latest API version (v2.4 as of 14/01/2022)
15
+
16
+ ## Installation
14
17
 
15
18
  ```bash
16
- npm install intercom-client
19
+ yarn add intercom-client
17
20
  ```
18
21
 
19
22
  **This client is intended for server side use only. Please use the [Intercom Javascript SDK](https://developers.intercom.com/v2.0/docs/intercom-javascript) for client-side operations.**
@@ -21,7 +24,7 @@ npm install intercom-client
21
24
  ## Testing
22
25
 
23
26
  ```bash
24
- npm test
27
+ yarn test
25
28
  ```
26
29
 
27
30
  ## Running the code locally
@@ -29,585 +32,888 @@ npm test
29
32
  Compile using babel:
30
33
 
31
34
  ```bash
32
- gulp babel
35
+ yarn prepublish
33
36
  ```
34
37
 
35
- Require Intercom:
38
+ ## Usage
36
39
 
37
- ```node
38
- var Intercom = require('./dist/index');
40
+ Import Intercom:
41
+
42
+ ```typescript
43
+ import { Client } from './dist/index';
39
44
  ```
40
45
 
41
- ## Usage
46
+ Create a client using access tokens:
42
47
 
43
- Require Intercom:
48
+ ```typescript
49
+ const client = new Client({ tokenAuth: { token: 'my_token' } });
50
+ ```
44
51
 
45
- ```node
46
- var Intercom = require('intercom-client');
52
+ ## Request Options
53
+
54
+ This client library also supports passing in [`request` options](https://github.com/axios/axios#request-config):
55
+
56
+ ```typescript
57
+ const client = new Client({ tokenAuth: { token: 'my_token' } });
58
+ client.useRequestOpts({
59
+ baseURL: 'http://local.test-server.com',
60
+ });
47
61
  ```
48
62
 
49
- Create a client:
50
- #### Using Access Tokens
63
+ Note that certain request options (such as `json`, and certain `headers` names cannot be overriden).
64
+
65
+ ### Setting the API version
51
66
 
52
- ```node
53
- var client = new Intercom.Client({ token: 'my_token' });
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
+ },
75
+ });
54
76
  ```
55
77
 
56
- ## Callbacks
78
+ ## Examples
57
79
 
58
- This client library supports two kinds of callbacks:
80
+ ### Admins
59
81
 
60
- ```node
61
- client.users.list(function (d) {
62
- // d is the response from the server
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' });
86
+ ```
87
+
88
+ #### [Set Admin away](https://developers.intercom.com/intercom-api-reference/reference/set-admin-away-mode)
89
+
90
+ ```typescript
91
+ await client.admins.away({
92
+ adminId: '123',
93
+ enableAwayMode: true,
94
+ enableReassignMode: false,
63
95
  });
96
+ ```
64
97
 
65
- // Or
98
+ #### [List all activity logs](https://developers.intercom.com/intercom-api-reference/reference/view-admin-activity-logs)
66
99
 
67
- client.users.list(function (err, d) {
68
- // err is an error response object, or null
69
- // d is a successful response object, or null
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');,
70
104
  });
71
105
  ```
72
106
 
73
- ## Promises
107
+ #### [List all admins](https://developers.intercom.com/intercom-api-reference/reference/list-admins)
74
108
 
75
- This client library also supports using Promises instead of callbacks:
109
+ ```typescript
110
+ const admins = await client.admins.list();
111
+ ```
76
112
 
77
- ```node
78
- client.users.create({ email: 'foo@bar.com' }).then(function (r) {
79
- // ...
113
+ ### Companies
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: {},
80
128
  });
81
129
  ```
82
130
 
83
- ## Request Options
131
+ #### [Update a company](https://developers.intercom.com/intercom-api-reference/reference/update-a-company)
84
132
 
85
- This client library also supports passing in [`request` options](https://github.com/request/request#requestoptions-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
+ });
145
+ ```
86
146
 
87
- ```node
88
- var client = new Intercom.Client({ token: 'my_token' });
89
- client.useRequestOpts({
90
- baseUrl: 'http://local.test-server.com',
91
- // Uses the forever-agent / http(s).Agent({keepAlive:true})
92
- forever: true
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,
93
154
  });
94
155
  ```
95
156
 
96
- Note that certain request options (such as `json`, and certain `headers` names cannot be overriden).
157
+ ##### By name
97
158
 
159
+ ```typescript
160
+ const company = await client.companies.find({
161
+ name: 'bruh moment inc.',
162
+ });
163
+ ```
98
164
 
99
- ## Users
165
+ #### [Delete a company](https://developers.intercom.com/intercom-api-reference/reference/delete-a-company)
100
166
 
101
- ```node
102
- // Create a user
103
- client.users.create({
104
- email: 'jayne@serenity.io',
105
- custom_attributes: {
106
- foo: 'bar'
107
- }
108
- }, callback);
109
-
110
- // Update a user
111
- client.users.update({
112
- email: 'jayne@serenity.io',
113
- custom_attributes: {
114
- foo: 'bar'
115
- }
116
- }, callback);
167
+ ```typescript
168
+ const company = await client.companies.delete({
169
+ id: 62049,
170
+ });
117
171
  ```
118
172
 
119
- ```node
120
- // Create/update a user with custom attributes
121
- client.users.create({ email: 'jayne@serenity.io', custom_attributes: { invited_friend: true } }, callback);
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,
182
+ });
122
183
  ```
123
184
 
124
- ```node
125
- // List users
126
- client.users.list(callback);
185
+ ##### With TagId and SegmentId
186
+
187
+ ```typescript
188
+ const companies = await client.companies.list({
189
+ tagId: '1234',
190
+ segmentId: '4567',
191
+ });
127
192
  ```
128
193
 
129
- ```node
130
- // List users by tag or segment
131
- client.users.listBy({ tag_id: 'haven' }, callback);
194
+ #### [Scroll over companies](https://developers.intercom.com/intercom-api-reference/reference/iterating-over-all-companies)
195
+
196
+ ##### Using infinite scroll
197
+
198
+ ```typescript
199
+ const companies = await client.companies.scroll.each({});
132
200
  ```
133
201
 
134
- ```node
135
- // Scroll through users list
136
- client.users.scroll.each({}, function(res) {
137
- // if you return a promise from your callback, the client will only scroll
138
- // after this promise has resolved
139
- new Bluebird((resolve) => {
140
- setTimeout(() => {
141
- console.log(res.body.users.length);
142
- // Your custom logic
143
- resolve();
144
- }, 500)
145
- })
146
- });
202
+ ##### Using manual scroll
147
203
 
204
+ ```typescript
205
+ const companies = await client.companies.scroll.next({
206
+ scrollParam: '123_soleil',
207
+ });
148
208
  ```
149
209
 
150
- ```node
151
- // Find user by id
152
- client.users.find({ id: '55b9eaf' }, callback);
210
+ #### [Attach a contact](https://developers.intercom.com/intercom-api-reference/reference/attach-contact-to-company)
153
211
 
154
- // Find user by user_id
155
- client.users.find({ user_id: 'foobar' }, callback);
212
+ ```typescript
213
+ const response = await client.companies.attachContact({
214
+ contactId: '123',
215
+ companyId: '234',
216
+ });
217
+ ```
218
+
219
+ #### [Detach a contact](https://developers.intercom.com/intercom-api-reference/reference/detach-contact-from-company)
156
220
 
157
- // Find user by email
158
- client.users.find({ email: 'jayne@serenity.io' }, callback);
221
+ ```typescript
222
+ const response = await client.companies.detachContact({
223
+ contactId: '123',
224
+ companyId: '234',
225
+ });
159
226
  ```
160
227
 
161
- ```node
162
- // Archive user by id (https://developers.intercom.com/intercom-api-reference/reference#archive-a-user)
163
- client.users.archive({ id: '1234' }, callback);
228
+ #### [List attached contacts](https://developers.intercom.com/intercom-api-reference/reference/list-company-contacts)
229
+
230
+ ```typescript
231
+ const response = await client.companies.listAttachedContacts({
232
+ companyId: '123',
233
+ page: 1,
234
+ perPage: 15,
235
+ });
164
236
  ```
165
237
 
166
- ```node
167
- // Permanently delete a user by id (https://developers.intercom.com/intercom-api-reference/reference#delete-users)
168
- const intercomUserId = '123'
169
- client.users.requestPermanentDeletion(intercomUserId, callback);
238
+ #### [List attached segments](https://developers.intercom.com/intercom-api-reference/reference/list-attached-segments-1)
239
+
240
+ ```typescript
241
+ const response = await client.companies.listAttachedSegments({
242
+ companyId: '123',
243
+ });
170
244
  ```
171
245
 
172
- ```node
173
- // Permanently delete a user by id in params
174
- client.users.requestPermanentDeletionByParams({ id: '55b9eaf' }, callback);
246
+ ### Contacts
247
+
248
+ #### [Create Contact](https://developers.intercom.com/intercom-api-reference/reference/create-contact)
175
249
 
176
- // Permanently delete a user by user_id
177
- client.users.requestPermanentDeletionByParams({ user_id: 'foobar' }, callback);
250
+ ##### With User Role
178
251
 
179
- // Permanently delete a user by email
180
- client.users.requestPermanentDeletionByParams({ email: 'jayne@serenity.io' }, callback);
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,
262
+ });
181
263
  ```
182
264
 
183
- ## Leads
265
+ ##### With Lead Role
184
266
 
185
- ```node
186
- // Create a contact
187
- client.leads.create(function (r) {
188
- console.log(r);
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,
189
276
  });
277
+ ```
278
+
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' });
283
+ ```
190
284
 
191
- // Create a contact with attributes
192
- client.leads.create({ email: 'jayne@serenity.io' }, function (r) {
193
- console.log(r);
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
+ },
194
295
  });
195
296
  ```
196
297
 
197
- ```node
198
- // Update a contact by id
199
- client.leads.update({ id: '5435345', 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' });
200
302
  ```
201
303
 
202
- ```node
203
- // List contacts
204
- client.leads.list(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' });
205
308
  ```
206
309
 
207
- ```node
208
- // Scroll through contacts list
209
- client.leads.scroll.each({}, function(res) {
210
- // if you return a promise from your callback, the client will only scroll
211
- // after this promise has resolved
212
- new Bluebird((resolve) => {
213
- setTimeout(() => {
214
- console.log(res.body.contacts.length);
215
- // Your custom logic
216
- resolve();
217
- }, 500)
218
- })
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' });
314
+ ```
315
+
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',
219
322
  });
220
323
  ```
221
324
 
222
- ```node
223
- // List contacts by email
224
- client.leads.listBy({ email: 'wash@serenity.io' }, callback);
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
+ });
225
373
  ```
226
374
 
375
+ #### [List all Contacts](https://developers.intercom.com/intercom-api-reference/reference/list-contacts)
227
376
 
228
- ```node
229
- // Find contact by id
230
- client.leads.find({ id: '5342423' }, callback);
231
- ```
377
+ ##### With cursor
232
378
 
233
- ```node
234
- // Delete contact by id
235
- client.leads.delete({ id: '5342423' }, callback);
379
+ ```typescript
380
+ const response = await client.contacts.list({
381
+ perPage: 5,
382
+ startingAfter:
383
+ 'WzE2MzU3NzU4NjkwMDAsIjYxODJiNjJhMDMwZTk4OTBkZWU4NGM5YiIsMl0=',
384
+ });
236
385
  ```
237
386
 
238
- ```node
239
- // Convert Leads into Users
240
- var conversion = {
241
- contact: { user_id: '1234-5678-9876' },
242
- user: { email: 'mal@serenity.io' }
243
- };
244
- client.leads.convert(conversion, callback);
387
+ ##### Without a cursor
388
+
389
+ ```typescript
390
+ const response = await client.contacts.list();
245
391
  ```
246
392
 
247
- ## Visitors
393
+ #### [List attached companies](https://developers.intercom.com/intercom-api-reference/reference/list-companies-of-contact)
248
394
 
249
- ```node
250
- // Update a visitor by id
251
- client.visitors.update({ id: '5435345', email: 'wash@serenity.io' }, callback);
395
+ ```typescript
396
+ const response = await client.contacts.listAttachedCompanies({
397
+ id: '123',
398
+ perPage: 5,
399
+ page: 1,
400
+ });
252
401
  ```
253
402
 
254
- ```node
255
- // Find visitor by id or user_id
256
- client.visitors.find({ id: '5342423' }, callback);
257
- client.visitors.find({ user_id: '5b868511-ca3b-4eac-8d26-cfd82a83ac76' }, 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' });
258
407
  ```
259
408
 
260
- ```node
261
- // Delete visitor by id
262
- client.visitors.delete({ id: '5342423' }, 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' });
263
413
  ```
264
414
 
265
- ```node
266
- // Convert visitors into Users
267
- var conversion = {
268
- visitor: { user_id: '1234-5678-9876' },
269
- user: { email: 'mal@serenity.io' },
270
- type: "user"
271
- };
272
- 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
+ });
273
421
  ```
274
422
 
275
- ```node
276
- // Convert visitors into Lead
277
- var conversion = {
278
- visitor: { user_id: '1234-5678-9876' },
279
- type: "lead"
280
- };
281
- client.visitors.convert(conversion, callback);
423
+ ### Conversations
424
+
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',
431
+ });
282
432
  ```
283
433
 
434
+ #### [Retrieve a conversation](https://developers.intercom.com/intercom-api-reference/reference/retrieve-a-conversation)
284
435
 
285
- ## Companies
436
+ ##### Formatted text
286
437
 
287
- ```node
288
- // Create/update a company
289
- client.companies.create({ company_id: '1234', name: 'serenity' }, function (r) {
290
- console.log(r);
438
+ ```typescript
439
+ const response = await client.conversations.find({
440
+ id: '123',
291
441
  });
292
442
  ```
293
443
 
294
- ```node
295
- // List companies
296
- client.companies.list(callback);
444
+ ##### As plain text
445
+
446
+ ```typescript
447
+ const response = await client.conversations.find({
448
+ id: '123',
449
+ inPlainText: true,
450
+ });
297
451
  ```
298
452
 
299
- ```node
300
- // List companies by tag or segment
301
- client.companies.listBy({ tag_id: 'haven' }, callback);
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
+ },
462
+ });
302
463
  ```
303
464
 
304
- ```node
305
- // Scroll through companies list
306
- client.companies.scroll.each({}, function(res) {
307
- // if you return a promise from your callback, the client will only scroll
308
- // after this promise has resolved
309
- new Bluebird((resolve) => {
310
- setTimeout(() => {
311
- console.log(res.body.companies.length);
312
- // Your custom logic
313
- resolve();
314
- }, 500)
315
- })
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',
316
477
  });
317
478
  ```
318
479
 
480
+ ###### As admin
319
481
 
320
- ```node
321
- // Find company by id
322
- client.companies.find({ id: '1234' }, callback);
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
+ });
323
490
  ```
324
491
 
325
- ```node
326
- // List company users by id or company_id
327
- client.companies.listUsers({ id: '1234' }, callback);
328
- client.companies.listUsers({ company_id: '1234' }, callback);
492
+ ##### By last conversation
493
+
494
+ ###### As user
495
+
496
+ ```typescript
497
+ const response = await client.conversations.replyByLastAsUser({
498
+ body: 'blablbalba',
499
+ intercomUserId: '123',
500
+ attachmentUrls: '345',
501
+ });
329
502
  ```
330
503
 
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
+ });
513
+ ```
331
514
 
332
- ## Events
515
+ #### [Assign a conversation](https://developers.intercom.com/intercom-api-reference/reference/assign-a-conversation)
333
516
 
334
- 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.
517
+ ##### As team without assignment rules
335
518
 
336
- ```node
337
- // Create a event
338
- client.events.create({
339
- event_name: 'Foo',
340
- created_at: 1439826340,
341
- user_id: 'bar',
342
- metadata: { type: 'baz' }
343
- }, function (d) {
344
- console.log(d);
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>',
345
526
  });
346
527
  ```
347
528
 
348
- ```node
349
- // List events by user
350
- client.events.listBy({
351
- type: 'user',
352
- user_id: 'bar'
353
- }, callback);
529
+ ##### As team with assignment rules
530
+
531
+ ```typescript
532
+ const response = await client.conversations.assign({
533
+ id: '123',
534
+ withRunningAssignmentRules: true,
535
+ });
354
536
  ```
355
537
 
356
- ## Counts
538
+ #### [Snooze a conversation](https://developers.intercom.com/intercom-api-reference/reference/snooze-a-conversation)
357
539
 
358
- ```node
359
- client.counts.appCounts(callback);
540
+ ```typescript
541
+ const response = await client.conversations.snooze({
542
+ id: '123',
543
+ adminId: '234',
544
+ snoozedUntil: '1501512795',
545
+ });
546
+ ```
360
547
 
361
- client.counts.conversationCounts(callback);
548
+ #### [Close a conversation](https://developers.intercom.com/intercom-api-reference/reference/close-a-conversation)
362
549
 
363
- client.counts.conversationAdminCounts(callback);
550
+ ```typescript
551
+ const response = await client.conversations.close({
552
+ id: '123',
553
+ adminId: '456',
554
+ body: "That's it...",
555
+ });
556
+ ```
364
557
 
365
- client.counts.userTagCounts(callback);
558
+ #### [Open a conversation](https://developers.intercom.com/intercom-api-reference/reference/open-a-conversation)
366
559
 
367
- client.counts.userSegmentCounts(callback);
560
+ ```typescript
561
+ const response = await client.conversations.open({
562
+ id: '123',
563
+ adminId: '234',
564
+ });
565
+ ```
368
566
 
369
- client.counts.companyTagCounts(callback);
567
+ #### [Attach a contact to group conversation](https://developers.intercom.com/intercom-api-reference/reference/adding-to-group-conversations-as-admin)
370
568
 
371
- client.counts.companySegmentCounts(callback);
569
+ ##### As admin, using intercomUserid
372
570
 
373
- client.counts.companyUserCounts(callback);
571
+ ```typescript
572
+ const response = await client.conversations.attachContactAsAdmin({
573
+ id: '123',
574
+ adminId: '234',
575
+ customer: {
576
+ intercomUserId: '456',
577
+ },
578
+ });
374
579
  ```
375
580
 
376
- ## Admins
581
+ ##### As contact, using intercomUserid
377
582
 
378
- ```node
379
- // List admins
380
- client.admins.list(callback);
583
+ ```typescript
584
+ const response = await client.conversations.attachContactAsAdmin({
585
+ id: '123',
586
+ userId: '234',
587
+ customer: {
588
+ intercomUserId: '456',
589
+ },
590
+ });
381
591
  ```
382
592
 
383
- ```node
384
- // Find current admin (only works with OAuth tokens)
385
- client.admins.me(callback);
386
- ```
593
+ #### [Delete a contact from group conversation as admin](https://developers.intercom.com/intercom-api-reference/reference/deleting-from-group-conversations)
387
594
 
595
+ ```typescript
596
+ const response = await client.conversations.detachContactAsAdmin({
597
+ conversationId: '123',
598
+ contactId: '456',
599
+ adminId: '789',
600
+ });
388
601
  ```
389
- // Find admin by ID
390
- client.admins.find('123456789', callback);
602
+
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
+ });
391
654
  ```
392
655
 
393
- ## Tags
656
+ #### [List all conversations](https://developers.intercom.com/intercom-api-reference/reference/list-conversations)
394
657
 
395
- ```node
396
- // Create a tag
397
- client.tags.create({ name: 'haven' }, callback);
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
+ });
398
667
  ```
399
668
 
400
- ```node
401
- // Tag a user by id
402
- 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
+ });
403
677
  ```
404
678
 
405
- ```node
406
- // Tag a company by id
407
- 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
+ });
408
691
  ```
409
692
 
410
- ```node
411
- // Untag a user by id
412
- 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
+ });
413
702
  ```
414
703
 
415
- ```node
416
- // List tags
417
- 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
+ });
418
711
  ```
419
712
 
420
- ```node
421
- // Delete a tag by id
422
- 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
+ });
423
735
  ```
424
736
 
425
- ## Segments
737
+ #### [List all data events](https://developers.intercom.com/intercom-api-reference/reference/list-user-events)
426
738
 
427
- ```node
428
- // List segments
429
- 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
+ });
430
746
  ```
431
747
 
432
- ```node
433
- // Find segment by id
434
- 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
+ });
435
767
  ```
436
768
 
437
- ## Messages
769
+ ### Segments
438
770
 
439
- ```node
440
- // Admin initiated messages:
441
- // Sending an email to a User
442
- var message = {
443
- message_type: "email",
444
- subject: "Hey",
445
- body: "Ponies, cute small horses or something more sinister?",
446
- template: "plain",
447
- from: {
448
- type: "admin",
449
- id: "21599"
450
- },
451
- to: {
452
- type: "user",
453
- id: "55c1ce1def857c31f80001af"
454
- }
455
- }
456
-
457
- 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
+ });
458
778
  ```
459
779
 
460
- ```node
461
- // Creating a user-initiated message:
462
- var message = {
463
- from: {
464
- type: "user",
465
- id: "55c1ce1def857c31f80001af"
466
- },
467
- body: "Howdy"
468
- }
780
+ #### [List all segments](https://developers.intercom.com/intercom-api-reference/reference/list-segments)
469
781
 
470
- client.messages.create(message, callback);
782
+ ```typescript
783
+ const response = await client.segments.list({
784
+ includeCount: true,
785
+ });
471
786
  ```
472
787
 
473
- ## Conversations
788
+ ### Tags
474
789
 
475
- 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)
476
791
 
477
- ```node
478
- client.conversations.list({ type: 'admin', admin_id: 21599 }, callback);
792
+ ##### Create
793
+
794
+ ```typescript
795
+ const response = await client.tags.create({ name: 'haven' });
479
796
  ```
480
797
 
798
+ ##### Update
481
799
 
482
- ```node
483
- // Fetch a conversation
484
- client.conversations.find({ id: '1062682196' }, callback);
800
+ ```typescript
801
+ const response = await client.tags.update({ id: '123', name: 'haven' });
485
802
  ```
486
803
 
487
- ```node
488
- // Reply to a conversation
489
- var reply = {
490
- id: '1039067180',
491
- intercom_user_id: '55b26822ce97179e52001334',
492
- body: 'Some reply :)',
493
- type: 'user',
494
- message_type: 'comment'
495
- };
496
-
497
- client.conversations.reply(reply, callback);
498
-
499
- // Reply to a conversation with attachments
500
- var reply = {
501
- id: '1039067180',
502
- intercom_user_id: '55b26822ce97179e52001334',
503
- body: 'Some reply :)',
504
- type: 'user',
505
- message_type: 'comment',
506
- attachment_urls: ['http://www.example.com/myattachment.jpg']
507
- };
508
-
509
- 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' });
510
808
  ```
511
809
 
512
- ```node
513
- // Assign a conversation to an admin
514
- var assignment = {
515
- id: '13879167940',
516
- type: 'admin',
517
- admin_id: '1309092',
518
- assignee_id: '1723471',
519
- message_type: 'assignment'
520
- };
810
+ #### [Attach a contact](https://developers.intercom.com/intercom-api-reference/reference/tag-contact)
521
811
 
522
- client.conversations.reply(assignment, callback);
812
+ ```typescript
813
+ const response = await client.tags.tagContact({
814
+ contactId: '123',
815
+ tagId: '234',
816
+ });
817
+ ```
523
818
 
524
- // Assign a conversation to unassigned
525
- var assignment = {
526
- id: '13879167940',
527
- type: 'admin',
528
- admin_id: '1309092',
529
- assignee_id: '0',
530
- message_type: 'assignment'
531
- }
819
+ #### [Attach a conversation](https://developers.intercom.com/intercom-api-reference/reference/attach-a-tag-to-a-conversation)
532
820
 
533
- client.conversations.reply(assignment, callback);
821
+ ```typescript
822
+ const response = await client.tags.tagConversation({
823
+ conversationId: '123',
824
+ tagId: '456',
825
+ adminId: '789',
826
+ });
534
827
  ```
535
828
 
536
- ```node
537
- // Mark a conversation as read
538
- 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
+ });
539
836
  ```
540
837
 
541
- ## Notes
838
+ #### [Untag companies](https://developers.intercom.com/intercom-api-reference/reference/untag-companies)
542
839
 
543
- ```node
544
- // Create a note
545
- var note = {
546
- admin_id: 21599,
547
- body: 'Hello notes!',
548
- user: {
549
- id: '55b26822ce97179e52001334'
550
- }
551
- };
840
+ ```typescript
841
+ const response = await client.tags.tagCompanies({
842
+ tagName: 'gutenTag',
843
+ companiesIds: ['123', '234', '456'],
844
+ });
845
+ ```
552
846
 
553
- client.notes.create(note, callback);
847
+ #### [Untag conversation](https://developers.intercom.com/intercom-api-reference/reference/detach-a-tag-from-a-conversation)
848
+
849
+ ```typescript
850
+ const response = await client.tags.untagConversation({
851
+ conversationId: '123',
852
+ tagId: '345',
853
+ adminId: '678',
854
+ });
554
855
  ```
555
856
 
556
- ```node
557
- // List notes by user
558
- 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
+ });
559
864
  ```
560
865
 
561
- ```node
562
- //Fetch a note
563
- 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();
564
870
  ```
565
871
 
566
- ## Pagination
872
+ ### Teams
567
873
 
568
- 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)
569
875
 
570
- ```json
571
- {
572
- "pages": {
573
- "next": "..."
574
- }
575
- }
876
+ ```typescript
877
+ const response = await client.teams.find({
878
+ id: '123',
879
+ });
576
880
  ```
577
881
 
578
- 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)
579
883
 
580
- ```node
581
- client.nextPage(response.pages, callback);
884
+ ```typescript
885
+ const response = await client.teams.list();
582
886
  ```
583
887
 
584
- ## Identity verification
888
+ ### Identity verification
585
889
 
586
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):
587
891
 
588
- ``` node
892
+ ```node
589
893
  import { IdentityVerification } from 'intercom-client';
590
894
 
591
- IdentityVerification.userHash({secretKey: 's3cre7', identifier: 'jayne@serenity.io'});
895
+ IdentityVerification.userHash({
896
+ secretKey: 's3cre7',
897
+ identifier: 'jayne@serenity.io',
898
+ });
592
899
  ```
593
900
 
594
901
  ## License
595
902
 
596
903
  Apache-2.0
597
904
 
598
-
599
905
  ## Pull Requests
600
906
 
601
- - **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.
602
908
 
603
- - **Document any change in behaviour**. Make sure the README and any other
604
- 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.
605
911
 
606
- - **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.
607
913
 
608
- - **One pull request per feature**. If you want to do more than one thing, send
609
- multiple pull requests.
914
+ - **One pull request per feature**. If you want to do more than one thing, send
915
+ multiple pull requests.
610
916
 
611
- - **Send coherent history**. Make sure each individual commit in your pull
612
- request is meaningful. If you had to make multiple intermediate commits while
613
- 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.