From 8763fa70022698e76e3c0c9799b40dedfa0a9dd7 Mon Sep 17 00:00:00 2001 From: Volo Date: Thu, 10 Feb 2022 11:52:03 +0200 Subject: [PATCH 1/3] Fix no email in creating contact params --- lib/contact.ts | 21 +++++++++------------ package.json | 2 +- test/contact.ts | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/lib/contact.ts b/lib/contact.ts index 830275cb..00480a2e 100644 --- a/lib/contact.ts +++ b/lib/contact.ts @@ -19,6 +19,7 @@ export default class Contact { } createUser({ externalId, + email, phone, name, avatar, @@ -31,6 +32,7 @@ export default class Contact { const requestData: CreateContactRequest = { role: Role.USER, external_id: externalId, + email, phone, name, avatar, @@ -55,7 +57,7 @@ export default class Contact { signed_up_at: data?.signedUpAt, last_seen_at: data?.lastSeenAt, owner_id: data?.ownerId, - unsubscribed_from_emails: data?.isUnsubscribedFromMails, + unsubscribed_from_emails: data?.isUnsubscribedFromEmails, custom_attributes: data?.customAttributes, }; return this.client.post({ @@ -185,8 +187,7 @@ type CreateContactRequest = Pick & > >; -interface CreateUserData { - externalId?: CreateContactRequest['external_id']; +interface CreateUserDataBase { phone?: CreateContactRequest['phone']; name?: CreateContactRequest['name']; avatar?: CreateContactRequest['avatar']; @@ -197,16 +198,12 @@ interface CreateUserData { customAttributes?: CreateContactRequest['custom_attributes']; } -interface CreateLeadData { - phone?: CreateContactRequest['phone']; - name?: CreateContactRequest['name']; - avatar?: CreateContactRequest['avatar']; - signedUpAt?: CreateContactRequest['signed_up_at']; - lastSeenAt?: CreateContactRequest['last_seen_at']; - ownerId?: CreateContactRequest['owner_id']; - isUnsubscribedFromMails?: CreateContactRequest['unsubscribed_from_emails']; - customAttributes?: CreateContactRequest['custom_attributes']; +interface CreateUserData extends CreateUserDataBase { + email?: string; + externalId?: string; } + +type CreateLeadData = CreateUserDataBase; // interface RetrieveContactData { id: string; diff --git a/package.json b/package.json index 30096afd..65fe08e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "intercom-client", - "version": "3.1.1", + "version": "3.1.2", "description": "Official Node bindings to the Intercom API", "homepage": "https://github.com/intercom/intercom-node", "bugs:": "https://github.com/intercom/intercom-node/issues", diff --git a/test/contact.ts b/test/contact.ts index d23e0ecc..1d666781 100644 --- a/test/contact.ts +++ b/test/contact.ts @@ -5,7 +5,7 @@ import { Operators, Role } from '../lib/common/common.types'; import { SearchContactOrderBy } from '../lib/contact'; describe('contacts', () => { - it('should create a contact with user role', async () => { + it('should create a contact with user role with external id', async () => { const id = '536e564f316c83104c000020'; const contact = { @@ -44,6 +44,43 @@ describe('contacts', () => { assert.deepStrictEqual(expectedReply, response); }); + it('should create a contact with user role with email', async () => { + const contact = { + role: 'user', + email: 'niko_bellic@mail.com', + phone: '+48370044567', + name: 'Niko Bellic', + avatar: 'https://nico-from-gta-iv.com/lets_go_bowling.jpg', + signed_up_at: 1638203719, + last_seen_at: 1638203719, + owner_id: 1, + unsubscribed_from_emails: true, + }; + + const expectedReply = {}; + + nock('https://api.intercom.io') + .post('/contacts', contact) + .reply(200, expectedReply); + + const client = new Client({ + usernameAuth: { username: 'foo', password: 'bar' }, + }); + + const response = await client.contacts.createUser({ + email: contact.email, + phone: contact.phone, + name: contact.name, + avatar: contact.avatar, + signedUpAt: contact.signed_up_at, + lastSeenAt: contact.last_seen_at, + ownerId: contact.owner_id, + isUnsubscribedFromEmails: contact.unsubscribed_from_emails, + }); + + assert.deepStrictEqual(expectedReply, response); + }); + it('should create a contact with lead role', async () => { const contact = { role: 'lead', From c3bbe4797b910d1722456faa89da67b90f7e0461 Mon Sep 17 00:00:00 2001 From: Volo Date: Thu, 10 Feb 2022 12:21:49 +0200 Subject: [PATCH 2/3] Fix issue #308 --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 94d0069f..aa3a2e02 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,6 @@ "target": "es5", "module": "commonjs", "moduleResolution": "node", - "importHelpers": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": true, From 757c38ec341cf9dcce5bb855901774f857dd04a0 Mon Sep 17 00:00:00 2001 From: Volo Date: Thu, 10 Feb 2022 12:26:57 +0200 Subject: [PATCH 3/3] Fix issue #309 --- lib/conversation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/conversation.ts b/lib/conversation.ts index c800db2c..1364a969 100644 --- a/lib/conversation.ts +++ b/lib/conversation.ts @@ -406,7 +406,7 @@ interface SnoozeConversationData { } // export enum CloseConversationMessageType { - CLOSED = 'closed', + CLOSED = 'close', } export enum CloseConversationType { ADMIN = 'admin',