Skip to content

Commit 154dc19

Browse files
authored
Merge pull request #297 from intercom/endpoints/notes
Endpoints/notes
2 parents c38923c + e3d8ea4 commit 154dc19

File tree

10 files changed

+175
-12
lines changed

10 files changed

+175
-12
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,34 @@ const response = await client.messages.create({
948948
});
949949
```
950950

951+
### Notes
952+
953+
#### [Create a note](https://developers.intercom.com/intercom-api-reference/reference/create-note-for-contact)
954+
955+
```typescript
956+
const response = await client.notes.create({
957+
adminId: '12345',
958+
body: 'Shiny',
959+
contactId: '5678',
960+
});
961+
```
962+
963+
#### [Retrieve a note](https://developers.intercom.com/intercom-api-reference/reference/view-a-note)
964+
965+
```typescript
966+
const response = await client.notes.find({ id: '123' });
967+
```
968+
969+
#### [List all notes](https://developers.intercom.com/intercom-api-reference/reference/list-notes-of-contact)
970+
971+
```typescript
972+
const response = await client.notes.list({
973+
contactId: '123',
974+
page: 2,
975+
perPage: 3,
976+
});
977+
```
978+
951979
### Segments
952980

953981
#### [Retrieve a segment](https://developers.intercom.com/intercom-api-reference/reference/view-a-segment)

lib/admin/admin.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export interface AdminObject {
88
away_mode_reassign: boolean;
99
has_inbox_seat: boolean;
1010
team_ids: Array<number>;
11-
avatar: string;
11+
avatar: string | { image_url: string };
1212
}

lib/article.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import {
33
ArticleObject,
44
TranslatedContentObject,
55
} from './article/article.types';
6-
import { GenericDeletedResponse, Paginated } from './common/common.types';
6+
import {
7+
GenericDeletedResponse,
8+
OperationById,
9+
Paginated,
10+
} from './common/common.types';
711

812
export default class Article {
913
public readonly baseUrl = 'articles';
@@ -99,10 +103,6 @@ interface CreateArticleData {
99103
translatedContent?: Omit<TranslatedContentObject, 'type'>;
100104
}
101105

102-
interface OperationById {
103-
id: string;
104-
}
105-
106106
type ArticleFindByIdData = OperationById;
107107

108108
type UpdateArticleData = Partial<CreateArticleData> & OperationById;

lib/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import Contact from './contact';
1010
import DataAttribute from './dataAttribute';
1111
import Event from './event';
1212
import HelpCenter from './helpCenter';
13-
import Segment from './segment';
1413
import Message from './message';
14+
import Note from './note';
15+
import Segment from './segment';
1516
import Team from './team';
1617
import Tag from './tag';
1718

@@ -58,6 +59,7 @@ export default class Client {
5859
events: Event;
5960
helpCenter: HelpCenter;
6061
messages: Message;
62+
notes: Note;
6163
segments: Segment;
6264
passwordPart?: string;
6365
propertiesToOmitInRequestOpts: string[];
@@ -88,6 +90,7 @@ export default class Client {
8890
this.events = new Event(this);
8991
this.helpCenter = new HelpCenter(this);
9092
this.messages = new Message(this);
93+
this.notes = new Note(this);
9194
this.segments = new Segment(this);
9295
this.tags = new Tag(this);
9396
this.teams = new Team(this);

lib/common/common.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ export interface GenericDeletedResponse<ObjectType extends string> {
6969
object: ObjectType;
7070
deleted: boolean;
7171
}
72+
73+
export interface OperationById {
74+
id: string;
75+
}

lib/helpCenter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Client } from '.';
2-
import { GenericDeletedResponse, Paginated } from './common/common.types';
2+
import {
3+
GenericDeletedResponse,
4+
OperationById,
5+
Paginated,
6+
} from './common/common.types';
37
import {
48
CollectionObject,
59
GroupTranslatedContentObject,
@@ -165,7 +169,3 @@ type SectionListData = {
165169
};
166170

167171
type SectionListResponse = Paginated<SectionObject>;
168-
169-
interface OperationById {
170-
id: string;
171-
}

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export * from './dataAttribute/dataAttribute.types';
3434
export * from './event/event.types';
3535
export * from './helpCenter/helpCenter.types';
3636
export * from './message/message.types';
37+
export * from './note/note.types';
3738
export * from './segment/segment.types';
3839
export * from './subscription/subscription.types';
3940
export * from './tag/tag.types';

lib/note.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Client, NoteObject } from '.';
2+
import { OperationById, Paginated } from './common/common.types';
3+
4+
export default class Note {
5+
public readonly baseUrl = 'notes';
6+
7+
constructor(private readonly client: Client) {
8+
this.client = client;
9+
}
10+
11+
create({ adminId, body, contactId }: CreateNoteData) {
12+
const data = {
13+
admin_id: adminId,
14+
body,
15+
};
16+
17+
return this.client.post<NoteObject>({
18+
url: `/${this.client.contacts.baseUrl}/${contactId}/${this.baseUrl}`,
19+
data,
20+
});
21+
}
22+
find({ id }: FindNoteByIdData) {
23+
return this.client.get<NoteObject>({
24+
url: `/${this.baseUrl}/${id}`,
25+
});
26+
}
27+
list({ contactId, page, perPage: per_page }: ListNotesData) {
28+
const params = {
29+
page,
30+
per_page,
31+
};
32+
33+
return this.client.get<ListNotesResponse>({
34+
url: `/${this.client.contacts.baseUrl}/${contactId}/${this.baseUrl}`,
35+
params,
36+
});
37+
}
38+
}
39+
40+
interface CreateNoteData {
41+
adminId: string;
42+
body: string;
43+
contactId: string;
44+
}
45+
46+
type FindNoteByIdData = OperationById;
47+
48+
type ListNotesData = {
49+
contactId: string;
50+
page?: number;
51+
perPage?: number;
52+
};
53+
54+
type ListNotesResponse = Paginated<NoteObject>;

lib/note/note.types.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { AdminObject, Timestamp } from '..';
2+
3+
export type NoteObject = {
4+
type: 'note';
5+
id: string;
6+
created_at: Timestamp;
7+
contact: {
8+
type: 'contact';
9+
id: string;
10+
};
11+
author?: Pick<
12+
AdminObject,
13+
| 'type'
14+
| 'id'
15+
| 'name'
16+
| 'email'
17+
| 'away_mode_enabled'
18+
| 'away_mode_reassign'
19+
| 'avatar'
20+
>;
21+
body: string;
22+
};

test/notes.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import assert from 'assert';
2+
import { Client } from '../lib';
3+
import nock from 'nock';
4+
5+
describe('notes', () => {
6+
const client = new Client({
7+
usernameAuth: { username: 'foo', password: 'bar' },
8+
});
9+
10+
it('creates new', async () => {
11+
const contactId = 'baz';
12+
const requestBody = {
13+
body: 'Shiny',
14+
admin_id: '12345',
15+
};
16+
17+
nock('https://api.intercom.io')
18+
.post(`/contacts/${contactId}/notes`, requestBody)
19+
.reply(200, {});
20+
const response = await client.notes.create({
21+
adminId: requestBody.admin_id,
22+
body: requestBody.body,
23+
contactId,
24+
});
25+
26+
assert.deepStrictEqual({}, response);
27+
});
28+
it('finds by id', async () => {
29+
const id = 'beb';
30+
31+
nock('https://api.intercom.io').get(`/notes/${id}`).reply(200, {});
32+
const response = await client.notes.find({ id });
33+
34+
assert.deepStrictEqual({}, response);
35+
});
36+
it('lists all for specific contact by id', async () => {
37+
const contactId = 'yoopi';
38+
39+
nock('https://api.intercom.io')
40+
.get(`/contacts/${contactId}/notes`)
41+
.query({ page: 2, per_page: 3 })
42+
.reply(200, {});
43+
const response = await client.notes.list({
44+
contactId,
45+
page: 2,
46+
perPage: 3,
47+
});
48+
49+
assert.deepStrictEqual({}, response);
50+
});
51+
});

0 commit comments

Comments
 (0)