Skip to content

Commit ddd62de

Browse files
authored
Merge pull request #340 from intercom/seanhealy/updateConversationListEndpoint
Update conversation list to use 2.6 cursor pagination
2 parents 961d76b + a3f4fa5 commit ddd62de

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Circle CI](https://circleci.com/gh/intercom/intercom-node.png?style=shield)](https://circleci.com/gh/intercom/intercom-node)
44
[![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.5-blue)
5+
![Intercom API Version](https://img.shields.io/badge/Intercom%20API%20Version-2.6-blue)
66
![Typescript Supported](https://img.shields.io/badge/Typescript-Supported-lightgrey)
77

88
> Official Node bindings to the [Intercom API](https://api.intercom.io/docs)
@@ -21,7 +21,6 @@ yarn add intercom-client
2121

2222
**This client is intended for server side use only. Please use the [Intercom Javascript SDK](https://developers.intercom.com/installing-intercom/docs/intercom-for-web) for client-side operations.**
2323

24-
2524
## Usage
2625

2726
Import Intercom:
@@ -57,7 +56,7 @@ We version our API (see the "Choose Version" section of the [API & Webhooks Refe
5756
const client = new Client({ tokenAuth: { token: 'my_token' } });
5857
client.useRequestOpts({
5958
headers: {
60-
'Intercom-Version': 2.4,
59+
'Intercom-Version': 2.6,
6160
},
6261
});
6362
```
@@ -725,9 +724,7 @@ const response = await client.conversations.search({
725724

726725
```typescript
727726
const response = await client.conversations.list({
728-
order: Order.DESC,
729-
sort: SortBy.UpdatedAt,
730-
page: 1,
727+
startingAfter: 'WzE2NzA0MjI1MjkwMDAsMjQzMTY3NzA2ODcsMl0=',
731728
perPage: 10,
732729
});
733730
```
@@ -1088,14 +1085,14 @@ const response = await client.segments.list({
10881085
});
10891086
```
10901087

1091-
10921088
### Subscriptions
10931089

10941090
#### [List all subscription types](https://developers.intercom.com/intercom-api-reference/reference/list-all-subscription-types)
10951091

10961092
```typescript
10971093
const response = await client.subscriptions.listTypes();
10981094
```
1095+
10991096
### PhoneCallRedirects
11001097

11011098
#### [Create a phone call redirect](https://developers.intercom.com/intercom-api-reference/reference/create-a-phone-switch)

lib/contact/contact.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface ContactObject {
4545
tags: AddressableList;
4646
notes: AddressableList;
4747
companies: AddressableList;
48+
opted_in_subscription_types: AddressableList;
49+
opted_out_subscription_tyes: AddressableList;
4850
referrer: string;
4951
utm_campaign: string | null;
5052
utm_content: string | null;

lib/conversation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Client from './client';
22
import {
33
StringifiedTimestamp,
44
GenericSearchFilters,
5-
Order,
65
PaginatedBase,
76
} from './common/common.types';
87
import {
@@ -256,8 +255,11 @@ export default class Conversation {
256255
data,
257256
});
258257
}
259-
list({ order, sort, page, perPage: per_page }: ListConversationData) {
260-
const params = { order, sort, page, per_page };
258+
list({
259+
startingAfter: starting_after,
260+
perPage: per_page,
261+
}: ListConversationData) {
262+
const params = { starting_after, per_page };
261263

262264
return this.client.get<ListConversationResponse>({
263265
url: `/${this.baseUrl}`,
@@ -518,9 +520,7 @@ export enum SortBy {
518520
}
519521

520522
interface ListConversationData {
521-
order?: Order;
522-
sort?: SortBy;
523-
page?: number;
523+
startingAfter?: string;
524524
perPage?: number;
525525
}
526526

test/unit/conversation.test.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import {
1212
ReplyToConversationUserType,
1313
SearchConversationOrderBy,
1414
SnoozeConversationMessageType,
15-
SortBy,
1615
} from '../../lib/conversation';
17-
import { Operators, Order } from '../../lib/common/common.types';
16+
import { Operators } from '../../lib/common/common.types';
1817

1918
describe('conversations', () => {
2019
it('should create a conversation', async () => {
@@ -545,21 +544,53 @@ describe('conversations', () => {
545544
assert.deepStrictEqual(expectedReply, response);
546545
});
547546

548-
it('should list all conversations', async () => {
547+
it('should list all conversations with', async () => {
549548
const expectedReply = {};
550549

551550
nock('https://api.intercom.io')
552-
.get(`/conversations?order=desc&sort=updated_at&page=1&per_page=10`)
551+
.get(`/conversations`)
552+
.reply(200, expectedReply);
553+
554+
const client = new Client({
555+
usernameAuth: { username: 'foo', password: 'bar' },
556+
});
557+
558+
const response = await client.conversations.list({});
559+
560+
assert.deepStrictEqual(expectedReply, response);
561+
});
562+
563+
it('should list all conversations with per_page param', async () => {
564+
const expectedReply = {};
565+
566+
nock('https://api.intercom.io')
567+
.get(`/conversations?per_page=10`)
568+
.reply(200, expectedReply);
569+
570+
const client = new Client({
571+
usernameAuth: { username: 'foo', password: 'bar' },
572+
});
573+
574+
const response = await client.conversations.list({
575+
perPage: 10,
576+
});
577+
578+
assert.deepStrictEqual(expectedReply, response);
579+
});
580+
581+
it('should list all conversations with starting_after', async () => {
582+
const expectedReply = {};
583+
584+
nock('https://api.intercom.io')
585+
.get(`/conversations?starting_after=asdf123&per_page=10`)
553586
.reply(200, expectedReply);
554587

555588
const client = new Client({
556589
usernameAuth: { username: 'foo', password: 'bar' },
557590
});
558591

559592
const response = await client.conversations.list({
560-
order: Order.DESC,
561-
sort: SortBy.UpdatedAt,
562-
page: 1,
593+
startingAfter: 'asdf123',
563594
perPage: 10,
564595
});
565596

0 commit comments

Comments
 (0)