Skip to content

Commit

Permalink
Merge pull request #303 from intercom/3.1.0
Browse files Browse the repository at this point in the history
3.1.0 Release
  • Loading branch information
hypeofpipe committed Feb 8, 2022
2 parents c26cbf8 + 3de4949 commit fccdf60
Show file tree
Hide file tree
Showing 17 changed files with 752 additions and 20 deletions.
144 changes: 138 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const article = await client.articles.create({
title: 'Allez les verts',
description: 'French description',
body: '<p>French body in html</p>',
authorId: 1,
author_id: 1,
state: 'published',
},
},
Expand Down Expand Up @@ -158,7 +158,7 @@ const article = await client.articles.update({
title: 'Allez les verts',
description: 'French description',
body: '<p>French body in html</p>',
authorId: 1,
author_id: 1,
state: 'published',
},
},
Expand Down Expand Up @@ -746,6 +746,62 @@ const response = await client.conversations.redactConversationPart({
});
```

### Counts

#### [App Total Count](https://developers.intercom.com/intercom-api-reference/reference/company-user-counts)

```typescript
const response = await client.counts.forApp();
```

#### [Conversation Count Model](https://developers.intercom.com/intercom-api-reference/reference/conversation-counts)

```typescript
const response = await client.counts.countConversation();
```

#### [Admin Conversation Count Model](https://developers.intercom.com/intercom-api-reference/reference/admin-conversations)

```typescript
const response = await client.counts.countAdminConversation();
```

#### [User Segment/Tag Count Model](https://developers.intercom.com/intercom-api-reference/reference/user-tag-counts)

##### Count User Segment

```typescript
const response = await client.counts.countUserSegment();
```

##### Count User Tag

```typescript
const response = await client.counts.countUserTag();
```

#### [Company User/Segment/Tag Count Model](https://developers.intercom.com/intercom-api-reference/reference/company-tag-counts)

##### Count Company Segment

```typescript
const response = await client.counts.countCompanySegment();
const response = await client.counts.countCompanyTag();
const response = await client.counts.countCompanyUser();
```

##### Count Company Tag

```typescript
const response = await client.counts.countCompanyTag();
```

##### Count Company User

```typescript
const response = await client.counts.countCompanyUser();
```

### Data Attributes

#### [Create Data Attribute](https://developers.intercom.com/intercom-api-reference/reference/create-data-attributes)
Expand Down Expand Up @@ -845,7 +901,7 @@ const article = await client.helpCenter.collections.update({
id: '123',
name: 'Thanks for everything',
description: 'English description',
translatedContent: {
translated_content: {
fr: {
name: 'Allez les verts',
description: 'French description',
Expand Down Expand Up @@ -878,7 +934,7 @@ const response = client.helpCenter.collections.list({
```typescript
const collection = await client.helpCenter.sections.create({
name: 'Thanks for everything',
parentId: '1234',
parent_id: '1234',
translatedContent: {
fr: {
name: 'Allez les verts',
Expand All @@ -900,8 +956,8 @@ const response = await client.helpCenter.sections.find({ id: '123' });
const article = await client.helpCenter.sections.update({
id: '123',
name: 'Thanks for everything',
parentId: '456',
translatedContent: {
parent_id: '456',
translated_content: {
fr: {
name: 'Allez les verts',
description: 'French description',
Expand Down Expand Up @@ -948,6 +1004,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 Expand Up @@ -1067,6 +1151,54 @@ const response = await client.teams.find({
const response = await client.teams.list();
```

### Visitors

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

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

OR

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

#### [Update a Visitor](https://developers.intercom.com/intercom-api-reference/reference/update-a-visitor)

```typescript
const response = await client.visitors.update({
userId: '123',
name: 'anonymous bruh',
customAttributes: {
paid_subscriber: true,
},
});
```

#### [Delete a Visitor](https://developers.intercom.com/intercom-api-reference/reference/delete-a-visitor)

```typescript
const response = await client.visitors.delete({
id,
});
```

#### [Convert a Visitor](https://developers.intercom.com/intercom-api-reference/reference/convert-a-visitor-to-a-user)

```typescript
const response = await client.visitors.mergeToContact({
visitor: {
id: '123',
},
user: {
userId: '123',
},
type: Role.USER,
});
```

### Identity verification

`intercom-node` provides a helper for using [identity verification](https://docs.intercom.com/configure-intercom-for-your-product-or-site/staying-secure/enable-identity-verification-on-your-web-product):
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
13 changes: 11 additions & 2 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { merge, omit } from 'lodash';
import Article from './article';
import Admin from './admin';
import Company from './company';
import Conversation from './conversation';
import Contact from './contact';
import Conversation from './conversation';
import Count from './count';
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';
import Visitor from './visitor';

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

Expand Down Expand Up @@ -54,10 +57,12 @@ export default class Client {
companies: Company;
contacts: Contact;
conversations: Conversation;
counts: Count;
dataAttributes: DataAttribute;
events: Event;
helpCenter: HelpCenter;
messages: Message;
notes: Note;
segments: Segment;
passwordPart?: string;
propertiesToOmitInRequestOpts: string[];
Expand All @@ -66,6 +71,7 @@ export default class Client {
teams: Team;
usebaseURL: (baseURL: string) => this;
usernamePart?: string;
visitors: Visitor;

constructor(args: Constructor) {
const [usernamePart, passwordPart] = Client.getAuthDetails(args);
Expand All @@ -84,13 +90,16 @@ export default class Client {
this.companies = new Company(this);
this.contacts = new Contact(this);
this.conversations = new Conversation(this);
this.counts = new Count(this);
this.dataAttributes = new DataAttribute(this);
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);
this.visitors = new Visitor(this);
this.requestOpts = {
baseURL: 'https://api.intercom.io',
};
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;
}
86 changes: 86 additions & 0 deletions lib/count.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
Client,
CompanySegmentCountResponse,
CompanyTagCountResponse,
CompanyUserCountResponse,
UserCountResponse,
UserSegmentCountResponse,
UserTagCountResponse,
} from '.';
import {
AdminConversationCountResponse,
AppTotalCountResponse,
CompanyCountResponse,
ConversationCountResponse,
CountEntity,
CountType,
} from './count/count.types';

export default class Count {
public readonly baseUrl = 'counts';

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

forApp() {
return this.client.get<AppTotalCountResponse>({
url: `/${this.baseUrl}`,
});
}

countCompany() {
return this.client.get<CompanyCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.COMPANY },
});
}
countCompanySegment() {
return this.client.get<CompanySegmentCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.COMPANY, count: CountEntity.SEGMENT },
});
}
countCompanyTag() {
return this.client.get<CompanyTagCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.COMPANY, count: CountEntity.TAG },
});
}
countCompanyUser() {
return this.client.get<CompanyUserCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.COMPANY, count: CountEntity.USER },
});
}
countConversation() {
return this.client.get<ConversationCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.CONVERSATION },
});
}
countAdminConversation() {
return this.client.get<AdminConversationCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.CONVERSATION, count: CountEntity.ADMIN },
});
}
countUser() {
return this.client.get<UserCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.USER },
});
}
countUserSegment() {
return this.client.get<UserSegmentCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.USER, count: CountEntity.SEGMENT },
});
}
countUserTag() {
return this.client.get<UserTagCountResponse>({
url: `/${this.baseUrl}`,
params: { type: CountType.USER, count: CountEntity.TAG },
});
}
}
Loading

0 comments on commit fccdf60

Please sign in to comment.