Skip to content

Commit 74bd5f3

Browse files
Permit creating leads with email (#316)
* Allow adding leads with email - Create interface CreateLeadData * Add test for creating lead with email address * rm email from CreateUserData & CreateLeadData Co-authored-by: Johnny Nader <[email protected]> Co-authored-by: Johnny Nader <[email protected]>
1 parent 2e3fa9b commit 74bd5f3

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/contact.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default class Contact {
5252
const requestData: CreateContactRequest = {
5353
role: Role.LEAD,
5454
phone: data?.phone,
55+
email: data?.email,
5556
name: data?.name,
5657
avatar: data?.avatar,
5758
signed_up_at: data?.signedUpAt,
@@ -190,6 +191,7 @@ type CreateContactRequest = Pick<ContactObject, 'role'> &
190191
interface CreateUserDataBase {
191192
phone?: CreateContactRequest['phone'];
192193
name?: CreateContactRequest['name'];
194+
email?: CreateContactRequest['email'];
193195
avatar?: CreateContactRequest['avatar'];
194196
signedUpAt?: CreateContactRequest['signed_up_at'];
195197
lastSeenAt?: CreateContactRequest['last_seen_at'];
@@ -199,11 +201,11 @@ interface CreateUserDataBase {
199201
}
200202

201203
interface CreateUserData extends CreateUserDataBase {
202-
email?: string;
203204
externalId?: string;
204205
}
205206

206207
type CreateLeadData = CreateUserDataBase;
208+
207209
//
208210
interface RetrieveContactData {
209211
id: string;
@@ -290,8 +292,8 @@ interface SearchContactOrder {
290292

291293
interface SearchContactRequest {
292294
data: GenericSearchFilters &
293-
Partial<SearchContactPagination> &
294-
Partial<SearchContactOrder>;
295+
Partial<SearchContactPagination> &
296+
Partial<SearchContactOrder>;
295297
}
296298

297299
type SearchContactResponse = Paginated<ContactObject>;

test/unit/contact.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ describe('contacts', () => {
101101
assert.deepStrictEqual(expectedReply, response);
102102
});
103103

104+
it('should create a contact with lead role with email', async () => {
105+
const contact = {
106+
role: 'lead',
107+
108+
};
109+
110+
const expectedReply = {};
111+
112+
nock('https://api.intercom.io')
113+
.post('/contacts', contact)
114+
.reply(200, expectedReply);
115+
116+
const client = new Client({
117+
usernameAuth: { username: 'foo', password: 'bar' },
118+
});
119+
120+
const response = await client.contacts.createLead({
121+
email: contact.email,
122+
});
123+
124+
assert.deepStrictEqual(expectedReply, response);
125+
});
126+
104127
it('should retrieve a contact by id', async () => {
105128
const id = '536e564f316c83104c000020';
106129

0 commit comments

Comments
 (0)