Skip to content

Commit 57fca9b

Browse files
authored
Merge branch 'master' into circle-improvements
2 parents 31a4aa5 + ab79e7a commit 57fca9b

File tree

6 files changed

+78
-10
lines changed

6 files changed

+78
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## Breaking changes
1313

14-
The Node SDK has been updated to support latest API version (2.5). The update also contains requested features, such like Typescript support. You can find more information on how-to migrate and what has changed in the [migration guide](https://github.com/intercom/intercom-node/wiki/Migration-guide).
14+
The Node SDK has been updated to support latest API version (2.6). The update also contains requested features, such like Typescript support. You can find more information on how-to migrate and what has changed in the [migration guide](https://github.com/intercom/intercom-node/wiki/Migration-guide).
1515

1616
## Installation
1717

lib/conversation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export default class Conversation {
1717
constructor(private readonly client: Client) {
1818
this.client = client;
1919
}
20-
create({ userId, body }: CreateConversationData) {
20+
create({ userId, type = ContactType.USER, body }: CreateConversationData) {
2121
const requestData: CreateConversationRequest = {
2222
from: {
2323
id: userId,
24-
type: 'user',
24+
type,
2525
},
2626
body,
2727
};
@@ -288,14 +288,15 @@ export default class Conversation {
288288

289289
interface CreateConversationRequest {
290290
from: {
291-
type: 'user' | string;
291+
type: ContactType;
292292
id: string;
293293
};
294294
body: string;
295295
}
296296

297297
interface CreateConversationData {
298298
userId: string;
299+
type?: ContactType;
299300
body: string;
300301
}
301302
//

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intercom-client",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "Official Node bindings to the Intercom API",
55
"homepage": "https://github.com/intercom/intercom-node",
66
"bugs:": "https://github.com/intercom/intercom-node/issues",
@@ -58,4 +58,4 @@
5858
},
5959
"license": "Apache-2.0",
6060
"packageManager": "[email protected]"
61-
}
61+
}

test/integration/conversations.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ContactObject,
88
ConversationObject,
99
MessageObject,
10+
ContactType,
1011
} from '../../lib';
1112
import assert from 'assert';
1213
import { token } from './utils/config';
@@ -15,6 +16,7 @@ import { randomString } from './utils/random';
1516
describe('Conversations', () => {
1617
let user: ContactObject;
1718
let secondUser: ContactObject;
19+
let leadUser: ContactObject;
1820
let createdConversation: MessageObject;
1921
let foundConversation: ConversationObject;
2022

@@ -38,19 +40,45 @@ describe('Conversations', () => {
3840
name: 'Babushka Boy',
3941
4042
});
43+
leadUser = await client.contacts.createLead({
44+
name: 'Babushka Lead',
45+
46+
});
47+
});
48+
49+
it('create conversation with user as default', async () => {
50+
const response = await client.conversations.create({
51+
userId: user.id,
52+
body: 'Raz-dwa-try kalyna, czorniawaja diwczyna',
53+
});
54+
55+
createdConversation = response;
56+
57+
assert.notEqual(response, undefined);
4158
});
4259

43-
it('create', async () => {
60+
it('create conversation with user', async () => {
4461
const response = await client.conversations.create({
4562
userId: user.id,
4663
body: 'Raz-dwa-try kalyna, czorniawaja diwczyna',
64+
type: ContactType.USER,
4765
});
4866

4967
createdConversation = response;
5068

5169
assert.notEqual(response, undefined);
5270
});
5371

72+
it('create conversation with lead', async () => {
73+
const response = await client.conversations.create({
74+
userId: leadUser.id,
75+
body: 'Raz-dwa-try kalyna, czorniawaja diwczyna',
76+
type: ContactType.LEAD,
77+
});
78+
79+
assert.notEqual(response, undefined);
80+
});
81+
5482
it('find - by id', async () => {
5583
const response = await client.conversations.find({
5684
id: createdConversation.conversation_id as string,

test/integration/integration.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, ContactObject, MessageObject } from '../../lib';
1+
import { Client, ContactObject, ContactType, MessageObject } from '../../lib';
22
import assert from 'assert';
33
import { token } from './utils/config';
44
import { randomInt } from 'crypto';
@@ -66,6 +66,7 @@ describe('Integration between Contact, Conversation, Company and Tag APIs', () =
6666
const response = await client.conversations.create({
6767
userId: contact.id,
6868
body: 'Welcome to the club, buddy!',
69+
type: ContactType.USER,
6970
});
7071

7172
conversation = response;

test/unit/conversation.test.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from 'assert';
2-
import { Client } from '../../lib';
2+
import { Client, ContactType } from '../../lib';
33
import nock from 'nock';
44
import {
55
AssignToConversationMessageType,
@@ -16,7 +16,7 @@ import {
1616
import { Operators } from '../../lib/common/common.types';
1717

1818
describe('conversations', () => {
19-
it('should create a conversation', async () => {
19+
it('should create a conversation from a user', async () => {
2020
const id = '536e564f316c83104c000020';
2121

2222
const message = {
@@ -46,6 +46,44 @@ describe('conversations', () => {
4646

4747
const response = await client.conversations.create({
4848
userId: id,
49+
type: ContactType.USER,
50+
body: message.body,
51+
});
52+
53+
assert.deepStrictEqual(expectedReply, response);
54+
});
55+
56+
it('should create a conversation from a lead', async () => {
57+
const id = '536e564f316c83104c000020';
58+
59+
const message = {
60+
from: {
61+
type: 'lead',
62+
id,
63+
},
64+
body: 'Hello darkness my old friend',
65+
};
66+
67+
const expectedReply = {
68+
type: 'user_message',
69+
id: '2001',
70+
created_at: 1401917202,
71+
body: 'Hello darkness my old friend',
72+
message_type: 'inapp',
73+
conversation_id: '36000324324',
74+
};
75+
76+
nock('https://api.intercom.io')
77+
.post('/conversations', message)
78+
.reply(200, expectedReply);
79+
80+
const client = new Client({
81+
usernameAuth: { username: 'foo', password: 'bar' },
82+
});
83+
84+
const response = await client.conversations.create({
85+
userId: id,
86+
type: ContactType.LEAD,
4987
body: message.body,
5088
});
5189

0 commit comments

Comments
 (0)