Skip to content

Commit 23f2713

Browse files
authored
Merge branch 'master' into patch-1
2 parents e1d2b13 + e02b122 commit 23f2713

File tree

11 files changed

+228
-2
lines changed

11 files changed

+228
-2
lines changed

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ If you are using the european instance of intercom and would like to call it dir
6969
```typescript
7070
const client = new Client({ tokenAuth: { token: 'my_token' } });
7171
client.useRequestOpts({
72-
baseUrl: 'https://api.eu.intercom.io'
73-
})
72+
baseUrl: 'https://api.eu.intercom.io',
73+
});
7474
```
7575

7676
## Examples
@@ -832,6 +832,29 @@ const response = await client.dataAttributes.list({
832832
});
833833
```
834834

835+
### Data Exports
836+
837+
#### [Create a export job](https://developers.intercom.com/intercom-api-reference/reference/creating-an-export-job)
838+
839+
```typescript
840+
const response = await client.dataExport.create({
841+
createdAtAfter: 1527811200,
842+
createdAtBefore: 1530316800,
843+
});
844+
```
845+
846+
#### [Retrieve a job status](https://developers.intercom.com/intercom-api-reference/reference/retrieve-a-job-status)
847+
848+
```typescript
849+
const response = await client.dataExport.find({id: export.id})
850+
```
851+
852+
#### [Cancel a job](https://developers.intercom.com/intercom-api-reference/reference/the-export-job-model)
853+
854+
```typescript
855+
const response = await client.dataExport.cancel({id: export.id})
856+
```
857+
835858
### Events
836859

837860
#### [Submit a data event](https://developers.intercom.com/intercom-api-reference/reference/list-data-attributes)
@@ -1065,6 +1088,24 @@ const response = await client.segments.list({
10651088
});
10661089
```
10671090

1091+
1092+
### Subscriptions
1093+
1094+
#### [List all subscription types](https://developers.intercom.com/intercom-api-reference/reference/list-all-subscription-types)
1095+
1096+
```typescript
1097+
const response = await client.subscriptions.listTypes();
1098+
```
1099+
### PhoneCallRedirects
1100+
1101+
#### [Create a phone call redirect](https://developers.intercom.com/intercom-api-reference/reference/create-a-phone-switch)
1102+
1103+
```typescript
1104+
const response = await client.phoneCallRedirect.create({
1105+
phone: '+353871234567',
1106+
});
1107+
```
1108+
10681109
### Tags
10691110

10701111
#### [Create or update a tag](https://developers.intercom.com/intercom-api-reference/reference/create-and-update-tags)

lib/client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import Contact from './contact';
88
import Conversation from './conversation';
99
import Count from './count';
1010
import DataAttribute from './dataAttribute';
11+
import DataExport from './dataExport';
1112
import Event from './event';
1213
import HelpCenter from './helpCenter';
1314
import Message from './message';
1415
import Note from './note';
1516
import Segment from './segment';
17+
import Subscription from './subscription';
1618
import Team from './team';
1719
import Tag from './tag';
1820
import Visitor from './visitor';
21+
import PhoneCallRedirect from './phoneCallRedirect';
1922

2023
import * as packageJson from '../package.json';
2124

@@ -58,18 +61,21 @@ export default class Client {
5861
conversations: Conversation;
5962
counts: Count;
6063
dataAttributes: DataAttribute;
64+
dataExport: DataExport;
6165
events: Event;
6266
helpCenter: HelpCenter;
6367
messages: Message;
6468
notes: Note;
6569
segments: Segment;
70+
subscriptions: Subscription;
6671
passwordPart?: string;
6772
propertiesToOmitInRequestOpts: string[];
6873
requestOpts: Partial<AxiosDefaults>;
6974
tags: Tag;
7075
teams: Team;
7176
usernamePart?: string;
7277
visitors: Visitor;
78+
phoneCallRedirect: PhoneCallRedirect;
7379

7480
constructor(args: Constructor) {
7581
const [usernamePart, passwordPart] = Client.getAuthDetails(args);
@@ -90,14 +96,17 @@ export default class Client {
9096
this.conversations = new Conversation(this);
9197
this.counts = new Count(this);
9298
this.dataAttributes = new DataAttribute(this);
99+
this.dataExport = new DataExport(this);
93100
this.events = new Event(this);
94101
this.helpCenter = new HelpCenter(this);
95102
this.messages = new Message(this);
96103
this.notes = new Note(this);
97104
this.segments = new Segment(this);
105+
this.subscriptions = new Subscription(this);
98106
this.tags = new Tag(this);
99107
this.teams = new Team(this);
100108
this.visitors = new Visitor(this);
109+
this.phoneCallRedirect = new PhoneCallRedirect(this);
101110
this.requestOpts = {
102111
baseURL: 'https://api.intercom.io',
103112
};

lib/dataExport.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Client } from '.';
2+
import { DataExportObject } from './dataExport/dataExport.types';
3+
import { OperationById } from './common/common.types';
4+
5+
export default class DataExport {
6+
public readonly baseUrl = 'export';
7+
8+
constructor(private readonly client: Client) {
9+
this.client = client;
10+
}
11+
12+
find({ id }: DataExportByIdData) {
13+
return this.client.get<DataExportObject>({
14+
url: `/${this.baseUrl}/content/data/${id}`,
15+
});
16+
}
17+
18+
create({ createdAtBefore, createdAtAfter }: CreateDataExportData) {
19+
const data = {
20+
created_at_before: createdAtBefore,
21+
created_at_after: createdAtAfter,
22+
};
23+
24+
return this.client.post<DataExportObject>({
25+
url: `/${this.client.dataExport.baseUrl}/content/data/`,
26+
data,
27+
});
28+
}
29+
30+
cancel({ id }: DataExportByIdData) {
31+
return this.client.post<DataExportObject>({
32+
url: `/${this.baseUrl}/cancel/${id}`,
33+
data: {},
34+
});
35+
}
36+
}
37+
38+
interface CreateDataExportData {
39+
createdAtBefore: number;
40+
createdAtAfter: number;
41+
}
42+
43+
type DataExportByIdData = OperationById;

lib/dataExport/dataExport.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type DataExportObject = {
2+
job_identifier: string;
3+
status: string;
4+
download_url: string;
5+
download_expires_at: string;
6+
};

lib/phoneCallRedirect.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Client } from '.';
2+
import { PhoneCallRedirectObject } from './phoneCallRedirect/phoneCallRedirect.types';
3+
import { JavascriptObject } from './common/common.types';
4+
5+
export default class PhoneCallRedirect {
6+
public readonly baseUrl = 'phone_call_redirects';
7+
8+
constructor(private readonly client: Client) {
9+
this.client = client;
10+
}
11+
12+
create({ phone, customAttributes }: CreatePhoneRedirectData) {
13+
const data = {
14+
phone,
15+
customAttributes,
16+
};
17+
return this.client.post<PhoneCallRedirectObject>({
18+
url: `/${this.client.phoneCallRedirect.baseUrl}/`,
19+
data,
20+
});
21+
}
22+
}
23+
24+
interface CreatePhoneRedirectData {
25+
phone: string;
26+
customAttributes?: JavascriptObject;
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type PhoneCallRedirectObject = {
2+
type: 'phone_call_redirect';
3+
url: string;
4+
};

lib/subscription.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Client } from '.';
2+
import { SubscriptionObject } from './subscription/subscription.types';
3+
4+
export default class Subscription {
5+
public readonly baseUrl = 'subscription_types';
6+
7+
constructor(private readonly client: Client) {
8+
this.client = client;
9+
}
10+
listTypes() {
11+
return this.client.get<ListResponse>({
12+
url: `/${this.baseUrl}`,
13+
});
14+
}
15+
}
16+
17+
interface ListResponse {
18+
type: 'list';
19+
data: SubscriptionObject[];
20+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Client } from '../../dist';
2+
import assert from 'assert';
3+
import { token } from './utils/config';
4+
5+
describe('dataExport', () => {
6+
const client = new Client({ tokenAuth: { token } });
7+
let dataExport: string;
8+
9+
it('create', async () => {
10+
const response = await client.dataExport.create({
11+
createdAtAfter: 1670000000,
12+
createdAtBefore: 1670940528,
13+
});
14+
dataExport = response.job_identifier;
15+
16+
assert.notEqual(response, undefined);
17+
});
18+
19+
it('find', async () => {
20+
const response = await client.dataExport.find({ id: dataExport });
21+
22+
assert.notEqual(response, undefined);
23+
});
24+
25+
it('delete', async () => {
26+
const response = await client.dataExport.cancel({ id: dataExport });
27+
28+
assert.notEqual(response, undefined);
29+
});
30+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Client} from '../../dist';
2+
import assert from 'assert';
3+
import { token } from './utils/config';
4+
5+
describe('phoneCallRedirect', () => {
6+
const client = new Client({ tokenAuth: { token } });
7+
8+
it('create', async () => {
9+
const response = await client.phoneCallRedirect.create({
10+
phone: '+353871234567'
11+
});
12+
13+
assert.notEqual(response, undefined);
14+
});
15+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Client } from '../../dist';
2+
import assert from 'assert';
3+
import { token } from './utils/config';
4+
5+
describe('Subscriptions', () => {
6+
const client = new Client({ tokenAuth: { token } });
7+
8+
it('listTypes', async () => {
9+
const response = await client.subscriptions.listTypes();
10+
11+
assert.notEqual(response, undefined);
12+
});
13+
});

0 commit comments

Comments
 (0)