Skip to content

Commit 8763fa7

Browse files
VoloVolo
authored andcommitted
Fix no email in creating contact params
1 parent a3c534b commit 8763fa7

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

lib/contact.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class Contact {
1919
}
2020
createUser({
2121
externalId,
22+
email,
2223
phone,
2324
name,
2425
avatar,
@@ -31,6 +32,7 @@ export default class Contact {
3132
const requestData: CreateContactRequest = {
3233
role: Role.USER,
3334
external_id: externalId,
35+
email,
3436
phone,
3537
name,
3638
avatar,
@@ -55,7 +57,7 @@ export default class Contact {
5557
signed_up_at: data?.signedUpAt,
5658
last_seen_at: data?.lastSeenAt,
5759
owner_id: data?.ownerId,
58-
unsubscribed_from_emails: data?.isUnsubscribedFromMails,
60+
unsubscribed_from_emails: data?.isUnsubscribedFromEmails,
5961
custom_attributes: data?.customAttributes,
6062
};
6163
return this.client.post<ContactObject>({
@@ -185,8 +187,7 @@ type CreateContactRequest = Pick<ContactObject, 'role'> &
185187
>
186188
>;
187189

188-
interface CreateUserData {
189-
externalId?: CreateContactRequest['external_id'];
190+
interface CreateUserDataBase {
190191
phone?: CreateContactRequest['phone'];
191192
name?: CreateContactRequest['name'];
192193
avatar?: CreateContactRequest['avatar'];
@@ -197,16 +198,12 @@ interface CreateUserData {
197198
customAttributes?: CreateContactRequest['custom_attributes'];
198199
}
199200

200-
interface CreateLeadData {
201-
phone?: CreateContactRequest['phone'];
202-
name?: CreateContactRequest['name'];
203-
avatar?: CreateContactRequest['avatar'];
204-
signedUpAt?: CreateContactRequest['signed_up_at'];
205-
lastSeenAt?: CreateContactRequest['last_seen_at'];
206-
ownerId?: CreateContactRequest['owner_id'];
207-
isUnsubscribedFromMails?: CreateContactRequest['unsubscribed_from_emails'];
208-
customAttributes?: CreateContactRequest['custom_attributes'];
201+
interface CreateUserData extends CreateUserDataBase {
202+
email?: string;
203+
externalId?: string;
209204
}
205+
206+
type CreateLeadData = CreateUserDataBase;
210207
//
211208
interface RetrieveContactData {
212209
id: string;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intercom-client",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
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",

test/contact.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Operators, Role } from '../lib/common/common.types';
55
import { SearchContactOrderBy } from '../lib/contact';
66

77
describe('contacts', () => {
8-
it('should create a contact with user role', async () => {
8+
it('should create a contact with user role with external id', async () => {
99
const id = '536e564f316c83104c000020';
1010

1111
const contact = {
@@ -44,6 +44,43 @@ describe('contacts', () => {
4444
assert.deepStrictEqual(expectedReply, response);
4545
});
4646

47+
it('should create a contact with user role with email', async () => {
48+
const contact = {
49+
role: 'user',
50+
51+
phone: '+48370044567',
52+
name: 'Niko Bellic',
53+
avatar: 'https://nico-from-gta-iv.com/lets_go_bowling.jpg',
54+
signed_up_at: 1638203719,
55+
last_seen_at: 1638203719,
56+
owner_id: 1,
57+
unsubscribed_from_emails: true,
58+
};
59+
60+
const expectedReply = {};
61+
62+
nock('https://api.intercom.io')
63+
.post('/contacts', contact)
64+
.reply(200, expectedReply);
65+
66+
const client = new Client({
67+
usernameAuth: { username: 'foo', password: 'bar' },
68+
});
69+
70+
const response = await client.contacts.createUser({
71+
email: contact.email,
72+
phone: contact.phone,
73+
name: contact.name,
74+
avatar: contact.avatar,
75+
signedUpAt: contact.signed_up_at,
76+
lastSeenAt: contact.last_seen_at,
77+
ownerId: contact.owner_id,
78+
isUnsubscribedFromEmails: contact.unsubscribed_from_emails,
79+
});
80+
81+
assert.deepStrictEqual(expectedReply, response);
82+
});
83+
4784
it('should create a contact with lead role', async () => {
4885
const contact = {
4986
role: 'lead',

0 commit comments

Comments
 (0)