Skip to content

Commit bb931b8

Browse files
authored
Merge branch 'master' into lu/implement-list-subscription-types
2 parents 0be4cf5 + ad548d9 commit bb931b8

File tree

8 files changed

+163
-0
lines changed

8 files changed

+163
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,29 @@ const response = await client.dataAttributes.list({
845845
});
846846
```
847847

848+
### Data Exports
849+
850+
#### [Create a export job](https://developers.intercom.com/intercom-api-reference/reference/creating-an-export-job)
851+
852+
```typescript
853+
const response = await client.dataExport.create({
854+
createdAtAfter: 1527811200,
855+
createdAtBefore: 1530316800,
856+
});
857+
```
858+
859+
#### [Retrieve a job status](https://developers.intercom.com/intercom-api-reference/reference/retrieve-a-job-status)
860+
861+
```typescript
862+
const response = await client.dataExport.find({id: export.id})
863+
```
864+
865+
#### [Cancel a job](https://developers.intercom.com/intercom-api-reference/reference/the-export-job-model)
866+
867+
```typescript
868+
const response = await client.dataExport.cancel({id: export.id})
869+
```
870+
848871
### Events
849872

850873
#### [Submit a data event](https://developers.intercom.com/intercom-api-reference/reference/list-data-attributes)
@@ -1078,13 +1101,23 @@ const response = await client.segments.list({
10781101
});
10791102
```
10801103

1104+
10811105
### Subscriptions
10821106

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

10851109
```typescript
10861110
const response = await client.subscriptions.listTypes();
10871111
```
1112+
### PhoneCallRedirects
1113+
1114+
#### [Create a phone call redirect](https://developers.intercom.com/intercom-api-reference/reference/create-a-phone-switch)
1115+
1116+
```typescript
1117+
const response = await client.phoneCallRedirect.create({
1118+
phone: '+353871234567',
1119+
});
1120+
```
10881121

10891122
### Tags
10901123

lib/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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';
@@ -17,6 +18,7 @@ import Subscription from './subscription';
1718
import Team from './team';
1819
import Tag from './tag';
1920
import Visitor from './visitor';
21+
import PhoneCallRedirect from './phoneCallRedirect';
2022

2123
import * as packageJson from '../package.json';
2224

@@ -59,6 +61,7 @@ export default class Client {
5961
conversations: Conversation;
6062
counts: Count;
6163
dataAttributes: DataAttribute;
64+
dataExport: DataExport;
6265
events: Event;
6366
helpCenter: HelpCenter;
6467
messages: Message;
@@ -72,6 +75,7 @@ export default class Client {
7275
teams: Team;
7376
usernamePart?: string;
7477
visitors: Visitor;
78+
phoneCallRedirect: PhoneCallRedirect;
7579

7680
constructor(args: Constructor) {
7781
const [usernamePart, passwordPart] = Client.getAuthDetails(args);
@@ -92,6 +96,7 @@ export default class Client {
9296
this.conversations = new Conversation(this);
9397
this.counts = new Count(this);
9498
this.dataAttributes = new DataAttribute(this);
99+
this.dataExport = new DataExport(this);
95100
this.events = new Event(this);
96101
this.helpCenter = new HelpCenter(this);
97102
this.messages = new Message(this);
@@ -101,6 +106,7 @@ export default class Client {
101106
this.tags = new Tag(this);
102107
this.teams = new Team(this);
103108
this.visitors = new Visitor(this);
109+
this.phoneCallRedirect = new PhoneCallRedirect(this);
104110
this.requestOpts = {
105111
baseURL: 'https://api.intercom.io',
106112
};

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: string;
40+
createdAtAfter: string;
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+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
phone: '+353871234567'
12+
});
13+
dataExport = response.id;
14+
15+
assert.notEqual(response, undefined);
16+
});
17+
18+
it('find', async () => {
19+
const response = await client.dataExport.find({ id: dataExport });
20+
21+
assert.notEqual(response, undefined);
22+
});
23+
24+
it('delete', async () => {
25+
const response = await client.dataExport.cancel({ id: dataExport });
26+
27+
assert.notEqual(response, undefined);
28+
});
29+
});
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+
});

0 commit comments

Comments
 (0)