Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,34 @@ const response = await client.messages.create({
});
```

### Notes

#### [Create a note](https://developers.intercom.com/intercom-api-reference/reference/create-note-for-contact)

```typescript
const response = await client.notes.create({
adminId: '12345',
body: 'Shiny',
contactId: '5678',
});
```

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

```typescript
const response = await client.notes.find({ id: '123' });
```

#### [List all notes](https://developers.intercom.com/intercom-api-reference/reference/list-notes-of-contact)

```typescript
const response = await client.notes.list({
contactId: '123',
page: 2,
perPage: 3,
});
```

### Segments

#### [Retrieve a segment](https://developers.intercom.com/intercom-api-reference/reference/view-a-segment)
Expand Down
2 changes: 1 addition & 1 deletion lib/admin/admin.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface AdminObject {
away_mode_reassign: boolean;
has_inbox_seat: boolean;
team_ids: Array<number>;
avatar: string;
avatar: string | { image_url: string };
}
10 changes: 5 additions & 5 deletions lib/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
ArticleObject,
TranslatedContentObject,
} from './article/article.types';
import { GenericDeletedResponse, Paginated } from './common/common.types';
import {
GenericDeletedResponse,
OperationById,
Paginated,
} from './common/common.types';

export default class Article {
public readonly baseUrl = 'articles';
Expand Down Expand Up @@ -99,10 +103,6 @@ interface CreateArticleData {
translatedContent?: Omit<TranslatedContentObject, 'type'>;
}

interface OperationById {
id: string;
}

type ArticleFindByIdData = OperationById;

type UpdateArticleData = Partial<CreateArticleData> & OperationById;
Expand Down
5 changes: 4 additions & 1 deletion lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import Contact from './contact';
import DataAttribute from './dataAttribute';
import Event from './event';
import HelpCenter from './helpCenter';
import Segment from './segment';
import Message from './message';
import Note from './note';
import Segment from './segment';
import Team from './team';
import Tag from './tag';

Expand Down Expand Up @@ -58,6 +59,7 @@ export default class Client {
events: Event;
helpCenter: HelpCenter;
messages: Message;
notes: Note;
segments: Segment;
passwordPart?: string;
propertiesToOmitInRequestOpts: string[];
Expand Down Expand Up @@ -88,6 +90,7 @@ export default class Client {
this.events = new Event(this);
this.helpCenter = new HelpCenter(this);
this.messages = new Message(this);
this.notes = new Note(this);
this.segments = new Segment(this);
this.tags = new Tag(this);
this.teams = new Team(this);
Expand Down
4 changes: 4 additions & 0 deletions lib/common/common.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ export interface GenericDeletedResponse<ObjectType extends string> {
object: ObjectType;
deleted: boolean;
}

export interface OperationById {
id: string;
}
10 changes: 5 additions & 5 deletions lib/helpCenter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Client } from '.';
import { GenericDeletedResponse, Paginated } from './common/common.types';
import {
GenericDeletedResponse,
OperationById,
Paginated,
} from './common/common.types';
import {
CollectionObject,
GroupTranslatedContentObject,
Expand Down Expand Up @@ -165,7 +169,3 @@ type SectionListData = {
};

type SectionListResponse = Paginated<SectionObject>;

interface OperationById {
id: string;
}
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export * from './dataAttribute/dataAttribute.types';
export * from './event/event.types';
export * from './helpCenter/helpCenter.types';
export * from './message/message.types';
export * from './note/note.types';
export * from './segment/segment.types';
export * from './subscription/subscription.types';
export * from './tag/tag.types';
Expand Down
54 changes: 54 additions & 0 deletions lib/note.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Client, NoteObject } from '.';
import { OperationById, Paginated } from './common/common.types';

export default class Note {
public readonly baseUrl = 'notes';

constructor(private readonly client: Client) {
this.client = client;
}

create({ adminId, body, contactId }: CreateNoteData) {
const data = {
admin_id: adminId,
body,
};

return this.client.post<NoteObject>({
url: `/${this.client.contacts.baseUrl}/${contactId}/${this.baseUrl}`,
data,
});
}
find({ id }: FindNoteByIdData) {
return this.client.get<NoteObject>({
url: `/${this.baseUrl}/${id}`,
});
}
list({ contactId, page, perPage: per_page }: ListNotesData) {
const params = {
page,
per_page,
};

return this.client.get<ListNotesResponse>({
url: `/${this.client.contacts.baseUrl}/${contactId}/${this.baseUrl}`,
params,
});
}
}

interface CreateNoteData {
adminId: string;
body: string;
contactId: string;
}

type FindNoteByIdData = OperationById;

type ListNotesData = {
contactId: string;
page?: number;
perPage?: number;
};

type ListNotesResponse = Paginated<NoteObject>;
22 changes: 22 additions & 0 deletions lib/note/note.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AdminObject, Timestamp } from '..';

export type NoteObject = {
type: 'note';
id: string;
created_at: Timestamp;
contact: {
type: 'contact';
id: string;
};
author?: Pick<
AdminObject,
| 'type'
| 'id'
| 'name'
| 'email'
| 'away_mode_enabled'
| 'away_mode_reassign'
| 'avatar'
>;
body: string;
};
51 changes: 51 additions & 0 deletions test/notes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import assert from 'assert';
import { Client } from '../lib';
import nock from 'nock';

describe('notes', () => {
const client = new Client({
usernameAuth: { username: 'foo', password: 'bar' },
});

it('creates new', async () => {
const contactId = 'baz';
const requestBody = {
body: 'Shiny',
admin_id: '12345',
};

nock('https://api.intercom.io')
.post(`/contacts/${contactId}/notes`, requestBody)
.reply(200, {});
const response = await client.notes.create({
adminId: requestBody.admin_id,
body: requestBody.body,
contactId,
});

assert.deepStrictEqual({}, response);
});
it('finds by id', async () => {
const id = 'beb';

nock('https://api.intercom.io').get(`/notes/${id}`).reply(200, {});
const response = await client.notes.find({ id });

assert.deepStrictEqual({}, response);
});
it('lists all for specific contact by id', async () => {
const contactId = 'yoopi';

nock('https://api.intercom.io')
.get(`/contacts/${contactId}/notes`)
.query({ page: 2, per_page: 3 })
.reply(200, {});
const response = await client.notes.list({
contactId,
page: 2,
perPage: 3,
});

assert.deepStrictEqual({}, response);
});
});