Skip to content

Commit d4c8a47

Browse files
VoloVolo
authored andcommitted
Add Count
1 parent f5bf5dd commit d4c8a47

File tree

6 files changed

+322
-1
lines changed

6 files changed

+322
-1
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,62 @@ const response = await client.conversations.redactConversationPart({
746746
});
747747
```
748748

749+
### Counts
750+
751+
#### [App Total Count](https://developers.intercom.com/intercom-api-reference/reference/company-user-counts)
752+
753+
```typescript
754+
const response = await client.counts.forApp();
755+
```
756+
757+
#### [Conversation Count Model](https://developers.intercom.com/intercom-api-reference/reference/conversation-counts)
758+
759+
```typescript
760+
const response = await client.counts.countConversation();
761+
```
762+
763+
#### [Admin Conversation Count Model](https://developers.intercom.com/intercom-api-reference/reference/admin-conversations)
764+
765+
```typescript
766+
const response = await client.counts.countAdminConversation();
767+
```
768+
769+
#### [User Segment/Tag Count Model](https://developers.intercom.com/intercom-api-reference/reference/user-tag-counts)
770+
771+
##### Count User Segment
772+
773+
```typescript
774+
const response = await client.counts.countUserSegment();
775+
```
776+
777+
##### Count User Tag
778+
779+
```typescript
780+
const response = await client.counts.countUserTag();
781+
```
782+
783+
#### [Company User/Segment/Tag Count Model](https://developers.intercom.com/intercom-api-reference/reference/company-tag-counts)
784+
785+
##### Count Company Segment
786+
787+
```typescript
788+
const response = await client.counts.countCompanySegment();
789+
const response = await client.counts.countCompanyTag();
790+
const response = await client.counts.countCompanyUser();
791+
```
792+
793+
##### Count Company Tag
794+
795+
```typescript
796+
const response = await client.counts.countCompanyTag();
797+
```
798+
799+
##### Count Company User
800+
801+
```typescript
802+
const response = await client.counts.countCompanyUser();
803+
```
804+
749805
### Data Attributes
750806

751807
#### [Create Data Attribute](https://developers.intercom.com/intercom-api-reference/reference/create-data-attributes)

lib/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { merge, omit } from 'lodash';
55
import Article from './article';
66
import Admin from './admin';
77
import Company from './company';
8-
import Conversation from './conversation';
98
import Contact from './contact';
9+
import Conversation from './conversation';
10+
import Count from './count';
1011
import DataAttribute from './dataAttribute';
1112
import Event from './event';
1213
import HelpCenter from './helpCenter';
@@ -56,6 +57,7 @@ export default class Client {
5657
companies: Company;
5758
contacts: Contact;
5859
conversations: Conversation;
60+
counts: Count;
5961
dataAttributes: DataAttribute;
6062
events: Event;
6163
helpCenter: HelpCenter;
@@ -88,6 +90,7 @@ export default class Client {
8890
this.companies = new Company(this);
8991
this.contacts = new Contact(this);
9092
this.conversations = new Conversation(this);
93+
this.counts = new Count(this);
9194
this.dataAttributes = new DataAttribute(this);
9295
this.events = new Event(this);
9396
this.helpCenter = new HelpCenter(this);

lib/count.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
Client,
3+
CompanySegmentCountResponse,
4+
CompanyTagCountResponse,
5+
CompanyUserCountResponse,
6+
UserCountResponse,
7+
UserSegmentCountResponse,
8+
UserTagCountResponse,
9+
} from '.';
10+
import {
11+
AdminConversationCountResponse,
12+
AppTotalCountResponse,
13+
CompanyCountResponse,
14+
ConversationCountResponse,
15+
CountEntity,
16+
CountType,
17+
} from './count/count.types';
18+
19+
export default class Count {
20+
public readonly baseUrl = 'counts';
21+
22+
constructor(private readonly client: Client) {
23+
this.client = client;
24+
}
25+
26+
forApp() {
27+
return this.client.get<AppTotalCountResponse>({
28+
url: `/${this.baseUrl}`,
29+
});
30+
}
31+
32+
countCompany() {
33+
return this.client.get<CompanyCountResponse>({
34+
url: `/${this.baseUrl}`,
35+
params: { type: CountType.COMPANY },
36+
});
37+
}
38+
countCompanySegment() {
39+
return this.client.get<CompanySegmentCountResponse>({
40+
url: `/${this.baseUrl}`,
41+
params: { type: CountType.COMPANY, count: CountEntity.SEGMENT },
42+
});
43+
}
44+
countCompanyTag() {
45+
return this.client.get<CompanyTagCountResponse>({
46+
url: `/${this.baseUrl}`,
47+
params: { type: CountType.COMPANY, count: CountEntity.TAG },
48+
});
49+
}
50+
countCompanyUser() {
51+
return this.client.get<CompanyUserCountResponse>({
52+
url: `/${this.baseUrl}`,
53+
params: { type: CountType.COMPANY, count: CountEntity.USER },
54+
});
55+
}
56+
countConversation() {
57+
return this.client.get<ConversationCountResponse>({
58+
url: `/${this.baseUrl}`,
59+
params: { type: CountType.CONVERSATION },
60+
});
61+
}
62+
countAdminConversation() {
63+
return this.client.get<AdminConversationCountResponse>({
64+
url: `/${this.baseUrl}`,
65+
params: { type: CountType.CONVERSATION, count: CountEntity.ADMIN },
66+
});
67+
}
68+
countUser() {
69+
return this.client.get<UserCountResponse>({
70+
url: `/${this.baseUrl}`,
71+
params: { type: CountType.USER },
72+
});
73+
}
74+
countUserSegment() {
75+
return this.client.get<UserSegmentCountResponse>({
76+
url: `/${this.baseUrl}`,
77+
params: { type: CountType.USER, count: CountEntity.SEGMENT },
78+
});
79+
}
80+
countUserTag() {
81+
return this.client.get<UserTagCountResponse>({
82+
url: `/${this.baseUrl}`,
83+
params: { type: CountType.USER, count: CountEntity.TAG },
84+
});
85+
}
86+
}

lib/count/count.types.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
export type AppTotalCountResponse = {
2+
type: 'count.hash';
3+
company: CountObject;
4+
user: CountObject;
5+
lead: CountObject;
6+
tag: CountObject;
7+
segment: CountObject;
8+
};
9+
10+
export type ConversationCountResponse = {
11+
type: 'count';
12+
conversation: {
13+
assigned: number;
14+
closed: number;
15+
open: number;
16+
unassigned: number;
17+
};
18+
};
19+
20+
export type AdminConversationCountResponse = {
21+
type: 'count';
22+
conversation: {
23+
admin: {
24+
id: string;
25+
name: string;
26+
open: number;
27+
closed: number;
28+
}[];
29+
};
30+
};
31+
32+
export type CompanyCountResponse = {
33+
type: 'count';
34+
company: CountObject;
35+
};
36+
37+
export type CompanySegmentCountResponse = {
38+
type: 'count';
39+
company: { segment: GenericCountObject[] };
40+
};
41+
42+
export type CompanyTagCountResponse = {
43+
type: 'count';
44+
company: { tag: GenericCountObject[] };
45+
};
46+
47+
export type CompanyUserCountResponse = {
48+
type: 'count';
49+
company: {
50+
user: GenericCountObject & { remote_company_id: string }[];
51+
};
52+
};
53+
54+
export type UserCountResponse = {
55+
type: 'count';
56+
user: {
57+
user: CountObject;
58+
};
59+
};
60+
61+
export type UserSegmentCountResponse = {
62+
type: 'count';
63+
company: { segment: GenericCountObject[] };
64+
};
65+
66+
export type UserTagCountResponse = {
67+
type: 'count';
68+
company: { tag: GenericCountObject[] };
69+
};
70+
71+
export type CountObject = {
72+
count: number;
73+
};
74+
75+
export enum CountType {
76+
CONVERSATION = 'conversation',
77+
USER = 'user',
78+
COMPANY = 'company',
79+
}
80+
81+
export enum CountEntity {
82+
ADMIN = 'admin',
83+
SEGMENT = 'segment',
84+
TAG = 'tag',
85+
USER = 'user',
86+
}
87+
88+
type GenericCountObject = {
89+
[title: string]: number;
90+
};

lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from './common/common.types';
3030
export * from './company/company.types';
3131
export * from './contact/contact.types';
3232
export * from './conversation/conversation.types';
33+
export * from './count/count.types';
3334
export * from './dataAttribute/dataAttribute.types';
3435
export * from './event/event.types';
3536
export * from './helpCenter/helpCenter.types';

test/counts.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import assert from 'assert';
2+
import { Client, CountEntity, CountType } from '../lib';
3+
import nock from 'nock';
4+
5+
describe.only('counts', () => {
6+
const client = new Client({
7+
usernameAuth: { username: 'foo', password: 'bar' },
8+
});
9+
it('gets total app count', async () => {
10+
nock('https://api.intercom.io').get('/counts').reply(200, {});
11+
const response = await client.counts.forApp();
12+
13+
assert.deepStrictEqual({}, response);
14+
});
15+
it('gets conversations count', async () => {
16+
nock('https://api.intercom.io')
17+
.get('/counts')
18+
.query({ type: CountType.CONVERSATION })
19+
.reply(200, {});
20+
const response = await client.counts.countConversation();
21+
22+
assert.deepStrictEqual({}, response);
23+
});
24+
it('gets admin conversations count', async () => {
25+
nock('https://api.intercom.io')
26+
.get('/counts')
27+
.query({ type: CountType.CONVERSATION, count: CountEntity.ADMIN })
28+
.reply(200, {});
29+
const response = await client.counts.countAdminConversation();
30+
31+
assert.deepStrictEqual({}, response);
32+
});
33+
describe('for user', () => {
34+
it('gets segment count', async () => {
35+
nock('https://api.intercom.io')
36+
.get('/counts')
37+
.query({ type: CountType.USER, count: CountEntity.SEGMENT })
38+
.reply(200, {});
39+
const response = await client.counts.countUserSegment();
40+
41+
assert.deepStrictEqual({}, response);
42+
});
43+
44+
it('gets tags count', async () => {
45+
nock('https://api.intercom.io')
46+
.get('/counts')
47+
.query({ type: CountType.USER, count: CountEntity.TAG })
48+
.reply(200, {});
49+
const response = await client.counts.countUserTag();
50+
51+
assert.deepStrictEqual({}, response);
52+
});
53+
});
54+
describe('for company', () => {
55+
it('gets segment count', async () => {
56+
nock('https://api.intercom.io')
57+
.get('/counts')
58+
.query({ type: CountType.COMPANY, count: CountEntity.SEGMENT })
59+
.reply(200, {});
60+
const response = await client.counts.countCompanySegment();
61+
62+
assert.deepStrictEqual({}, response);
63+
});
64+
65+
it('gets tags count', async () => {
66+
nock('https://api.intercom.io')
67+
.get('/counts')
68+
.query({ type: CountType.COMPANY, count: CountEntity.TAG })
69+
.reply(200, {});
70+
const response = await client.counts.countCompanyTag();
71+
72+
assert.deepStrictEqual({}, response);
73+
});
74+
75+
it('gets users count', async () => {
76+
nock('https://api.intercom.io')
77+
.get('/counts')
78+
.query({ type: CountType.COMPANY, count: CountEntity.USER })
79+
.reply(200, {});
80+
const response = await client.counts.countCompanyUser();
81+
82+
assert.deepStrictEqual({}, response);
83+
});
84+
});
85+
});

0 commit comments

Comments
 (0)