Skip to content

Commit ad548d9

Browse files
authored
Merge pull request #331 from intercom/seanhealy/addSwitch
Add switch api + data export api
2 parents 9ef9ff3 + 0457377 commit ad548d9

File tree

8 files changed

+165
-2
lines changed

8 files changed

+165
-2
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ If you are using the european instance of intercom and would like to call it dir
8282
```typescript
8383
const client = new Client({ tokenAuth: { token: 'my_token' } });
8484
client.useRequestOpts({
85-
baseUrl: 'https://api.eu.intercom.io'
86-
})
85+
baseUrl: 'https://api.eu.intercom.io',
86+
});
8787
```
8888

8989
## Examples
@@ -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,6 +1101,16 @@ const response = await client.segments.list({
10781101
});
10791102
```
10801103

1104+
### PhoneCallRedirects
1105+
1106+
#### [Create a phone call redirect](https://developers.intercom.com/intercom-api-reference/reference/create-a-phone-switch)
1107+
1108+
```typescript
1109+
const response = await client.phoneCallRedirect.create({
1110+
phone: '+353871234567',
1111+
});
1112+
```
1113+
10811114
### Tags
10821115

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

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';
@@ -16,6 +17,7 @@ import Segment from './segment';
1617
import Team from './team';
1718
import Tag from './tag';
1819
import Visitor from './visitor';
20+
import PhoneCallRedirect from './phoneCallRedirect';
1921

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

@@ -58,6 +60,7 @@ export default class Client {
5860
conversations: Conversation;
5961
counts: Count;
6062
dataAttributes: DataAttribute;
63+
dataExport: DataExport;
6164
events: Event;
6265
helpCenter: HelpCenter;
6366
messages: Message;
@@ -70,6 +73,7 @@ export default class Client {
7073
teams: Team;
7174
usernamePart?: string;
7275
visitors: Visitor;
76+
phoneCallRedirect: PhoneCallRedirect;
7377

7478
constructor(args: Constructor) {
7579
const [usernamePart, passwordPart] = Client.getAuthDetails(args);
@@ -90,6 +94,7 @@ export default class Client {
9094
this.conversations = new Conversation(this);
9195
this.counts = new Count(this);
9296
this.dataAttributes = new DataAttribute(this);
97+
this.dataExport = new DataExport(this);
9398
this.events = new Event(this);
9499
this.helpCenter = new HelpCenter(this);
95100
this.messages = new Message(this);
@@ -98,6 +103,7 @@ export default class Client {
98103
this.tags = new Tag(this);
99104
this.teams = new Team(this);
100105
this.visitors = new Visitor(this);
106+
this.phoneCallRedirect = new PhoneCallRedirect(this);
101107
this.requestOpts = {
102108
baseURL: 'https://api.intercom.io',
103109
};

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)