Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(INT-177): intercom refactor #2612

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const DestCanonicalNames = {
'TWITTER_ADS',
],
BRAZE: ['BRAZE', 'Braze', 'braze'],
INTERCOM: ['INTERCOM', 'intercom','Intercom'],
};

module.exports = { DestHandlerMap, DestCanonicalNames };
63 changes: 43 additions & 20 deletions src/v0/destinations/intercom/config.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,76 @@
const { getMappingConfig } = require('../../util');

const BASE_ENDPOINT = 'https://api.intercom.io';
const BASE_EU_ENDPOINT = 'https://api.eu.intercom.io';
const BASE_AU_ENDPOINT = 'https://api.au.intercom.io';

// track events | Track
const TRACK_ENDPOINT = `${BASE_ENDPOINT}/events`;
// Create, Update a user with a company | Identify
const IDENTIFY_ENDPOINT = `${BASE_ENDPOINT}/users`;
// create, update, delete a company | Group
const GROUP_ENDPOINT = `${BASE_ENDPOINT}/companies`;
const SEARCH_CONTACT_ENDPOINT = 'contacts/search';
const CREATE_OR_UPDATE_COMPANY_ENDPOINT = 'companies';

const ConfigCategory = {
TRACK: {
endpoint: TRACK_ENDPOINT,
endpoint: 'events',
name: 'INTERCOMTrackConfig',
},
IDENTIFY: {
endpoint: IDENTIFY_ENDPOINT,
endpoint: 'contacts',
name: 'INTERCOMIdentifyConfig',
},
GROUP: {
endpoint: GROUP_ENDPOINT,
endpoint: 'contacts/{id}/companies',
name: 'INTERCOMGroupConfig',
},
};

const MappingConfig = getMappingConfig(ConfigCategory, __dirname);

const ReservedTraitsProperties = [
const ReservedUserAttributes = [
'userId',
'role',
'email',
'phone',
'name',
'createdAt',
'firstName',
'avatar',
'company',
'ownerId',
'lastName',
'firstname',
'lastname',
'company',
'firstName',
'firstname',
'createdAt',
'timestamp',
'originalTimestamp',
'unsubscribedFromEmails',
];

const ReservedCompanyProperties = ['id', 'name', 'industry'];
const ReservedCompanyAttributes = [
'tags',
'size',
'plan',
'name',
'email',
'userId',
'website',
'industry',
'segments',
'userCount',
'createdAt',
'sessionCount',
'monthlySpend',
'remoteCreatedAt',
];

// ref:- https://developers.intercom.com/intercom-api-reference/v1.4/reference/event-metadata-types
const MetadataTypes = { richLink: ['url', 'value'], monetaryAmount: ['amount', 'currency'] };

module.exports = {
ConfigCategory,
MappingConfig,
ReservedCompanyProperties,
ReservedTraitsProperties,
BASE_ENDPOINT,
MetadataTypes,
MappingConfig,
ConfigCategory,
BASE_EU_ENDPOINT,
BASE_AU_ENDPOINT,
ReservedUserAttributes,
SEARCH_CONTACT_ENDPOINT,
ReservedCompanyAttributes,
CREATE_OR_UPDATE_COMPANY_ENDPOINT,
};
8 changes: 8 additions & 0 deletions src/v0/destinations/intercom/data/INTERCOMGroupConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,13 @@
"type": "toNumber"
},
"required": false
},
{
"destKey": "custom_attributes",
"sourceKeys": [
"traits",
"context.traits"
],
"required": false
}
]
53 changes: 44 additions & 9 deletions src/v0/destinations/intercom/data/INTERCOMIdentifyConfig.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
[
{
"destKey": "user_id",
"destKey": "role",
"sourceKeys": [
"traits.role",
"context.traits.role"
],
"required": false
},
{
"destKey": "external_id",
"sourceKeys": [
"userId",
"traits.userId",
"traits.id",
"context.traits.userId",
"context.traits.id"
"context.traits.userId"
],
"required": false
},
{
"destKey": "email",
"sourceKeys": ["traits.email", "context.traits.email"],
"sourceKeys": "email",
"sourceFromGenericMap": true,
"required": false
},
{
"destKey": "phone",
"sourceKeys": ["traits.phone", "context.traits.phone"],
"sourceKeys": "phone",
"sourceFromGenericMap": true,
"required": false
},
{
"destKey": "name",
"sourceKeys": ["traits.name", "context.traits.name"],
"sourceKeys": "name",
"sourceFromGenericMap": true,
"required": false
},
{
"destKey": "avatar",
"sourceKeys": "avatar",
"sourceFromGenericMap": true,
"required": false
},
{
Expand All @@ -34,8 +49,28 @@
}
},
{
"destKey": "last_seen_user_agent",
"sourceKeys": "context.userAgent",
"destKey": "last_seen_at",
"sourceKeys": "timestamp",
"sourceFromGenericMap": true,
"required": false,
"metadata": {
"type": "secondTimestamp"
}
},
{
"destKey": "owner_id",
"sourceKeys": ["traits.ownerId", "context.traits.ownerId"],
"required": false,
"metadata": {
"type": "toNumber"
}
},
{
"destKey": "unsubscribed_from_emails",
"sourceKeys": [
"traits.unsubscribedFromEmails",
"context.traits.unsubscribedFromEmails"
],
"required": false
},
{
Expand Down
45 changes: 27 additions & 18 deletions src/v0/destinations/intercom/data/INTERCOMTrackConfig.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
[
{
"destKey": "event_name",
"sourceKeys": "event",
"required": true
},
{
"destKey": "created_at",
"sourceKeys": "timestamp",
"sourceFromGenericMap": true,
"required": true,
"metadata": {
"type": "secondTimestamp"
}
},
{
"destKey": "user_id",
"sourceKeys": [
"userId",
"traits.userId",
"traits.id",
"context.traits.userId",
"context.traits.id"
"context.traits.userId"
],
"required": false
},
{
"destKey": "email",
"sourceKeys": ["traits.email", "context.traits.email"],
"destKey": "id",
"sourceKeys": [
"traits.id",
"properties.id",
"context.traits.id"
],
"required": false
},
{
"destKey": "event_name",
"sourceKeys": "event",
"required": true
},
{
"destKey": "created",
"sourceKeys": "timestamp",
"destKey": "email",
"sourceKeys": "email",
"sourceFromGenericMap": true,
"required": true,
"metadata": {
"type": "secondTimestamp"
}
"required": false
},
{
"destKey": "metadata",
"sourceKeys": "properties"
"sourceKeys": "properties",
"required": false
}
]
]
Loading