@musicplayce/intercom-ts v0.0.12
This SDK is intended for server-side use only. *Intercom* offers their official Javascript SDK for client-side operations.
Table of Contents
Getting Started
Currently the SDK only supports Intercom API Version 2.0
Installing
Using npm:
npm install @musicplayce/intercom-ts
Using yarn:
yarn add @musicplayce/intercom-ts
Usage
Import the SDK into your project:
import IntercomClient from '@musicplayce/intercom-ts';
// or use require
const IntercomClient = require('@musicplayce/intercom-ts');
Initialize a new client:
const client = new IntercomClient({ token: 'YOUR_API_TOKEN_HERE' });
console.log(client.intercomVersion); // '2.0'
Contacts
Create:
const create = await client.contacts.create({
role: 'user',
external_id: 'ID IDENTIFIER IN YOUR SYSTEM',
email: 'node_user@test.com',
phone: '+5562999999999',
name: 'Node Test User',
avatar: 'URL TO AVATAR',
signed_up_at: 1213313,
last_seen_at: 123123,
custom_attributes: {
custom_attr1: 'custom_attribute_1',
custom_attr2: 'custom_attribute_2'
}
});
Update:
const update = await client.contacts.update('', {
role: 'user',
external_id: '',
email: 'lucas.mota@musicplayce.com',
custom_attributes: {
plan: 'free'
}
});
Delete:
const deleted = await client.contacts.delete('5ea1c76499abcb4afe7fb83f');
Find By Id:
const findById = await client.contacts.find({
id: '5ea1c76499abcb4afe7fb83f' // Intercom Id
});
Find By Email:
const findByEmail = await client.contacts.find({
email: 'node_user@test.com'
});
Find By External Id:
const findByExternalId = await client.contacts.find({
external_id: '5ea1c76499abcb4afe7fb83f'
});
Search Single Filter:
const searchSingleFilter = await client.contacts.search({
field: 'custom_attributes.salesforce_status',
operator: '~',
value: 'open'
});
Search Multiple Filter:
const searchMultipleFilters = await client.contacts.search({
operator: 'AND',
value: [
{
field: 'custom_attributes.social_network',
operator: '=',
value: 'facebook'
},
{
field: 'custom_attributes.social_network',
operator: '=',
value: 'twitter'
},
{
field: 'custom_attributes.social_network',
operator: '=',
value: 'instagram'
}
]
});
Search Nested Filter:
const searchNestedFilters = await client.contacts.search({
operator: 'AND',
value: [
{
operator: 'OR',
value: [
{
field: 'created_at',
operator: '>',
value: 1560436650
},
{
field: 'signed_up_at',
operator: '>',
value: 1560436784
}
]
},
{
operator: 'OR',
value: [
{
field: 'custom_attributes.salseforce_status',
operator: '~',
value: 'Open'
},
{
field: 'custom_attributes.salesforce_object_type',
operator: '=',
value: 'Lead'
}
]
}
]
});
Events
Create:
const event = await client.events.create({
event_name: 'click',
created_at: 1571069751,
email: 'node_user@test.com',
metadata: {
clicked: true
}
});
List customer events:
const eventList = await client.events.list({ email: '5ea1c76499abcb4afe7fb83f' })
const eventList = await client.events.list({ intercom_user_id: '5ea1c76499abcb4afe7fb83f' })
According to the Intercom API you can only 'list' events that are less than 90 days old. Event counts and summaries will still include your events older than 90 days but you cannot 'list' these events individually if they are older than 90 days
Built With
- Typescript - Typescript enables JavaScript developers to use highly-productive development tools and practices like static checking and code refactoring when developing JavaScript applications.
- Axios - Promise based HTTP client for the browser and node.js.
- lodash - A modern JavaScript utility library delivering modularity, performance, & extras.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Author(s)
- Gustavo Quinta - Initial work - MoonTory
License
This project is licensed under the MIT License - see the LICENSE.md file for details