1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-20 09:27:44 +03:00

Some changes and fixes on Intercom-Node

This commit is contained in:
Jan Oberhauser 2019-11-22 23:04:06 +01:00
parent efb0ce88f1
commit 9897a156ca
5 changed files with 624 additions and 495 deletions

View File

@ -1,6 +1,6 @@
import { INodeProperties } from "n8n-workflow";
export const companyOpeations = [
export const companyOperations = [
{
displayName: 'Operation',
name: 'operation',
@ -18,28 +18,28 @@ export const companyOpeations = [
value: 'create',
description: 'Create a new company',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a company',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get data of all companies',
},
{
name: 'Update',
value: 'update',
description: 'Update a company',
},
{
name: 'View',
value: 'view',
description: 'View a company',
},
{
name: 'List',
value: 'list',
description: 'List companies',
},
{
name: 'Users',
value: 'users',
description: `List company's users`,
},
],
default: '',
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
@ -68,18 +68,16 @@ export const companyFields = [
{
name: 'ID',
value: 'id',
default: '',
description: 'The Intercom defined id representing the company',
},
{
name: 'Company ID',
value: 'companyId',
default: '',
description: 'The company_id you have given to the company',
},
],
default: '',
description: 'List by'
description: 'List by',
},
{
displayName: 'Value',
@ -100,77 +98,91 @@ export const companyFields = [
description: 'View by value',
},
/* -------------------------------------------------------------------------- */
/* company:list */
/* company:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'List by',
name: 'listBy',
type: 'options',
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'list',
'getAll',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 60,
},
default: 50,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'getAll',
],
},
},
options: [
{
name: 'Segment ID',
value: 'segmentId',
displayName: 'Segment ID',
name: 'segment_id',
type: 'string',
default: '',
description: 'Segment representing the Lead',
},
{
name: 'Tag ID',
value: 'tagId',
displayName: 'Tag ID',
name: 'tag_id',
type: 'string',
default: '',
description: 'Tag representing the Lead',
},
{
name: 'All',
value: 'all',
default: '',
description: 'List all users',
},
],
default: '',
description: 'List by'
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'list',
],
},
hide: {
listBy: [
'all'
]
}
},
description: 'list by value',
]
},
/* -------------------------------------------------------------------------- */
/* company:view */
/* company:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'View By',
name: 'viewBy',
displayName: 'Select By',
name: 'selectBy',
type: 'options',
displayOptions: {
show: {
@ -178,32 +190,29 @@ export const companyFields = [
'company',
],
operation: [
'view',
'get',
],
},
},
options: [
{
name: 'ID',
value: 'id',
default: '',
description: 'The Intercom defined id representing the company',
},
{
name: 'Company ID',
value: 'companyId',
default: '',
description: 'The company_id you have given to the company',
},
{
name: 'ID',
value: 'id',
description: 'The Intercom defined id representing the company',
},
{
name: 'Name',
value: 'name',
default: '',
description: 'The name of the company',
},
],
default: '',
description: 'View by'
description: 'What property to use to query the company.',
},
{
displayName: 'Value',
@ -217,7 +226,7 @@ export const companyFields = [
'company',
],
operation: [
'view',
'get',
],
},
},
@ -240,7 +249,7 @@ export const companyFields = [
],
operation: [
'create',
'update'
'update',
],
},
},
@ -259,16 +268,16 @@ export const companyFields = [
'update',
],
resource: [
'company'
'company',
],
},
},
},
{
displayName: 'Options',
name: 'options',
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Option',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
@ -277,11 +286,18 @@ export const companyFields = [
'update',
],
resource: [
'company'
'company',
],
},
},
options: [
{
displayName: 'Industry',
name: 'industry',
type: 'string',
default: '',
description: 'The industry that this company operates in',
},
{
displayName: 'Monthly Spend',
name: 'monthlySpend',
@ -317,13 +333,7 @@ export const companyFields = [
name: 'website',
type: 'string',
default: '',
description: `The URL for this company's website. Please note that the value specified here is not validated. Accepts any string.`,
},
{
displayName: 'Industry',
name: 'industry',
type: 'string',
description: 'The industry that this company operates in',
description: `The URL for this company's website. Please note that the value<br />specified here is not validated. Accepts any string.`,
},
]
},
@ -399,4 +409,3 @@ export const companyFields = [
description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.',
},
] as INodeProperties[];

View File

@ -7,21 +7,24 @@ import {
IExecuteSingleFunctions
} from 'n8n-core';
export async function intercomApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
import {
IDataObject,
} from 'n8n-workflow';
export async function intercomApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('intercomApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const headerWithAuthentication = Object.assign({}, headers,
const headerWithAuthentication = Object.assign({},
{ Authorization: `Bearer ${credentials.apiKey}`, Accept: 'application/json' });
const endpoint = 'api.intercom.io';
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method,
uri: `https://${endpoint}${resource}`,
qs: query,
uri: uri || `https://api.intercom.io${endpoint}`,
body,
json: true
};
@ -29,8 +32,6 @@ export async function intercomApiRequest(this: IHookFunctions | IExecuteFunction
try {
return await this.helpers.request!(options);
} catch (error) {
console.error(error);
const errorMessage = error.response.body.message || error.response.body.Message;
if (errorMessage !== undefined) {
@ -40,6 +41,36 @@ export async function intercomApiRequest(this: IHookFunctions | IExecuteFunction
}
}
/**
* Make an API request to paginated intercom endpoint
* and return all results
*/
export async function intercomApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = [];
let responseData;
query.per_page = 60;
let uri: string | undefined;
do {
responseData = await intercomApiRequest.call(this, endpoint, method, body, query, uri);
uri = responseData.pages.next;
returnData.push.apply(returnData, responseData[propertyName]);
} while (
responseData.pages !== undefined &&
responseData.pages.next !== undefined &&
responseData.pages.next !== null
);
return returnData;
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
let result;
try {

View File

@ -15,6 +15,7 @@ import {
} from './LeadDescription';
import {
intercomApiRequest,
intercomApiRequestAllItems,
validateJSON,
} from './GenericFunctions';
import {
@ -24,7 +25,7 @@ import {
} from './LeadInterface';
import { userOpeations, userFields } from './UserDescription';
import { IUser, IUserCompany } from './UserInterface';
import { companyOpeations, companyFields } from './CompanyDescription';
import { companyOperations, companyFields } from './CompanyDescription';
import { ICompany } from './CompanyInteface';
export class Intercom implements INodeType {
@ -55,9 +56,9 @@ export class Intercom implements INodeType {
type: 'options',
options: [
{
name: 'User',
value: 'user',
description: 'The Users resource is the primary way of interacting with Intercom',
name: 'Company',
value: 'company',
description: 'Companies allow you to represent commercial organizations using your product.',
},
{
name: 'Lead',
@ -65,17 +66,17 @@ export class Intercom implements INodeType {
description: 'Leads are useful for representing logged-out users of your application.',
},
{
name: 'Company',
value: 'company',
description: 'Companies allow you to represent commercial organizations using your product.',
name: 'User',
value: 'user',
description: 'The Users resource is the primary way of interacting with Intercom',
},
],
default: '',
default: 'user',
description: 'Resource to consume.',
},
...leadOpeations,
...userOpeations,
...companyOpeations,
...companyOperations,
...userFields,
...leadFields,
...companyFields,
@ -112,58 +113,62 @@ export class Intercom implements INodeType {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let qs: IDataObject;
let responseData;
for (let i = 0; i < length; i++) {
qs = {};
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
//https://developers.intercom.com/intercom-api-reference/reference#leads
if (resource === 'lead') {
if (operation === 'create' || operation === 'update') {
const email = this.getNodeParameter('email', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
const body: ILead = {};
if (email) {
if (operation === 'create') {
body.email = this.getNodeParameter('email', i) as string;
}
if (options.phone) {
body.phone = options.phone as string;
if (additionalFields.email) {
body.email = additionalFields.email as string;
}
if (options.name) {
body.name = options.name as string;
if (additionalFields.phone) {
body.phone = additionalFields.phone as string;
}
if (options.unsubscribedFromEmails) {
body.unsubscribed_from_emails = options.unsubscribedFromEmails as boolean;
if (additionalFields.name) {
body.name = additionalFields.name as string;
}
if (options.updateLastRequestAt) {
body.update_last_request_at = options.updateLastRequestAt as boolean;
if (additionalFields.unsubscribedFromEmails) {
body.unsubscribed_from_emails = additionalFields.unsubscribedFromEmails as boolean;
}
if (options.utmSource) {
body.utm_source = options.utmSource as string;
if (additionalFields.updateLastRequestAt) {
body.update_last_request_at = additionalFields.updateLastRequestAt as boolean;
}
if (options.utmMedium) {
body.utm_medium = options.utmMedium as string;
if (additionalFields.utmSource) {
body.utm_source = additionalFields.utmSource as string;
}
if (options.utmCampaign) {
body.utm_campaign = options.utmCampaign as string;
if (additionalFields.utmMedium) {
body.utm_medium = additionalFields.utmMedium as string;
}
if (options.utmTerm) {
body.utm_term = options.utmTerm as string;
if (additionalFields.utmCampaign) {
body.utm_campaign = additionalFields.utmCampaign as string;
}
if (options.utmContent) {
body.utm_content = options.utmContent as string;
if (additionalFields.utmTerm) {
body.utm_term = additionalFields.utmTerm as string;
}
if(options.avatar) {
if (additionalFields.utmContent) {
body.utm_content = additionalFields.utmContent as string;
}
if (additionalFields.avatar) {
const avatar: IAvatar = {
type: 'avatar',
image_url: options.avatar as string,
image_url: additionalFields.avatar as string,
};
body.avatar = avatar;
}
if (options.companies) {
if (additionalFields.companies) {
const companies: ILeadCompany[] = [];
// @ts-ignore
options.companies.forEach( o => {
additionalFields.companies.forEach( o => {
const company: ILeadCompany = {};
company.company_id = o;
companies.push(company);
@ -186,6 +191,7 @@ export class Intercom implements INodeType {
body.custom_attributes = customAttributesJson;
}
}
if (operation === 'update') {
const updateBy = this.getNodeParameter('updateBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
@ -196,43 +202,49 @@ export class Intercom implements INodeType {
body.id = value;
}
}
try {
responseData = await intercomApiRequest.call(this, '/contacts', 'POST', body);
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'view') {
let query = '';
const viewBy = this.getNodeParameter('viewBy', 0) as string;
if (operation === 'get') {
const selectBy = this.getNodeParameter('selectBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (viewBy === 'userId') {
query = `user_id=${value}`;
if (selectBy === 'email') {
qs.email = value;
}
if (viewBy === 'phone') {
query = `phone=${value}`;
if (selectBy === 'userId') {
qs.user_id = value;
}
if (selectBy === 'phone') {
qs.phone = value;
}
try {
if (viewBy === 'id') {
responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'GET');
} else {
responseData = await intercomApiRequest.call(this, `/contacts?${query}`, 'GET');
}
if (selectBy === 'id') {
responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'GET');
} else {
responseData = await intercomApiRequest.call(this, '/contacts', 'GET', {}, qs);
responseData = responseData.contacts;
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'list') {
let query = '';
const listBy = this.getNodeParameter('listBy', 0) as string;
if (listBy === 'email') {
query = `email=${this.getNodeParameter('value', i) as string}`;
}
if (listBy === 'phone') {
query = `phone=${this.getNodeParameter('value', i) as string}`;
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
Object.assign(qs, filters);
try {
responseData = await intercomApiRequest.call(this, `/contacts?${query}`, 'GET');
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'contacts', '/contacts', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/contacts', 'GET', {}, qs);
responseData = responseData.contacts;
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
@ -244,7 +256,8 @@ export class Intercom implements INodeType {
if (deleteBy === 'id') {
responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'DELETE');
} else {
responseData = await intercomApiRequest.call(this, `/contacts?user_id=${value}`, 'DELETE');
qs.user_id = value;
responseData = await intercomApiRequest.call(this, '/contacts', 'DELETE', {}, qs);
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
@ -254,65 +267,74 @@ export class Intercom implements INodeType {
//https://developers.intercom.com/intercom-api-reference/reference#users
if (resource === 'user') {
if (operation === 'create' || operation === 'update') {
const id = this.getNodeParameter('id', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
const body: IUser = {};
if (id === 'email') {
body.email = this.getNodeParameter('idValue', i) as string;
if (operation === 'create') {
const identifierType = this.getNodeParameter('identifierType', i) as string;
if (identifierType === 'email') {
body.email = this.getNodeParameter('idValue', i) as string;
} else if (identifierType === 'userId') {
body.user_id = this.getNodeParameter('idValue', i) as string;
}
}
if (id === 'userId') {
body.user_id = this.getNodeParameter('idValue', i) as string;
if (additionalFields.email) {
body.email = additionalFields.email as string;
}
if (options.phone) {
body.phone = options.phone as string;
if (additionalFields.userId) {
body.user_id = additionalFields.userId as string;
}
if (options.name) {
body.name = options.name as string;
if (additionalFields.phone) {
body.phone = additionalFields.phone as string;
}
if (options.unsubscribedFromEmails) {
body.unsubscribed_from_emails = options.unsubscribedFromEmails as boolean;
if (additionalFields.name) {
body.name = additionalFields.name as string;
}
if (options.updateLastRequestAt) {
body.update_last_request_at = options.updateLastRequestAt as boolean;
if (additionalFields.unsubscribedFromEmails) {
body.unsubscribed_from_emails = additionalFields.unsubscribedFromEmails as boolean;
}
if (options.sessionCount) {
body.session_count = options.sessionCount as number;
if (additionalFields.updateLastRequestAt) {
body.update_last_request_at = additionalFields.updateLastRequestAt as boolean;
}
if(options.avatar) {
if (additionalFields.sessionCount) {
body.session_count = additionalFields.sessionCount as number;
}
if (additionalFields.avatar) {
const avatar: IAvatar = {
type: 'avatar',
image_url: options.avatar as string,
image_url: additionalFields.avatar as string,
};
body.avatar = avatar;
}
if (options.utmSource) {
body.utm_source = options.utmSource as string;
if (additionalFields.utmSource) {
body.utm_source = additionalFields.utmSource as string;
}
if (options.utmMedium) {
body.utm_medium = options.utmMedium as string;
if (additionalFields.utmMedium) {
body.utm_medium = additionalFields.utmMedium as string;
}
if (options.utmCampaign) {
body.utm_campaign = options.utmCampaign as string;
if (additionalFields.utmCampaign) {
body.utm_campaign = additionalFields.utmCampaign as string;
}
if (options.utmTerm) {
body.utm_term = options.utmTerm as string;
if (additionalFields.utmTerm) {
body.utm_term = additionalFields.utmTerm as string;
}
if (options.utmContent) {
body.utm_content = options.utmContent as string;
if (additionalFields.utmContent) {
body.utm_content = additionalFields.utmContent as string;
}
if (options.companies) {
if (additionalFields.companies) {
const companies: IUserCompany[] = [];
// @ts-ignore
options.companies.forEach( o => {
additionalFields.companies.forEach( o => {
const company: IUserCompany = {};
company.company_id = o;
companies.push(company);
});
body.companies = companies;
}
if (options.sessionCount) {
body.session_count = options.sessionCount as number;
if (additionalFields.sessionCount) {
body.session_count = additionalFields.sessionCount as number;
}
if (!jsonActive) {
const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[];
@ -330,57 +352,56 @@ export class Intercom implements INodeType {
body.custom_attributes = customAttributesJson;
}
}
if (operation === 'update') {
const id = this.getNodeParameter('id', i) as string;
const email = this.getNodeParameter('email', i) as string;
const userId = this.getNodeParameter('userId', i) as string;
if (id) {
body.id = id;
const updateBy = this.getNodeParameter('updateBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (updateBy === 'userId') {
body.user_id = value;
}
if (email) {
body.email = email;
if (updateBy === 'id') {
body.id = value;
}
if (userId) {
body.user_id = userId;
if (updateBy === 'email') {
body.email = value;
}
}
try {
responseData = await intercomApiRequest.call(this, '/users', 'POST', body);
responseData = await intercomApiRequest.call(this, '/users', 'POST', body, qs);
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'view') {
let query = '';
const viewBy = this.getNodeParameter('viewBy', 0) as string;
if (operation === 'get') {
const selectBy = this.getNodeParameter('selectBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (viewBy === 'userId') {
query = `user_id=${value}`;
if (selectBy === 'userId') {
qs.user_id = value;
}
try {
if (viewBy === 'id') {
responseData = await intercomApiRequest.call(this, `/users/${value}`, 'GET');
} else {
responseData = await intercomApiRequest.call(this, `/users?${query}`, 'GET');
}
if (selectBy === 'id') {
responseData = await intercomApiRequest.call(this, `/users/${value}`, 'GET', {}, qs);
} else {
responseData = await intercomApiRequest.call(this, '/users', 'GET', {}, qs);
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'list') {
let query = '';
const listBy = this.getNodeParameter('listBy', 0) as string;
if (listBy === 'email') {
query = `email=${this.getNodeParameter('value', i) as string}`;
}
if (listBy === 'segmentId') {
query = `segment_id=${this.getNodeParameter('value', i) as string}`;
}
if (listBy === 'tagId') {
query = `tag_id=${this.getNodeParameter('value', i) as string}`;
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
Object.assign(qs, filters);
try {
responseData = await intercomApiRequest.call(this, `/users?${query}`, 'GET');
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'users', '/users', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/users', 'GET', {}, qs);
responseData = responseData.users;
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
@ -398,28 +419,28 @@ export class Intercom implements INodeType {
if (resource === 'company') {
if (operation === 'create' || operation === 'update') {
const id = this.getNodeParameter('companyId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
const body: ICompany = {
company_id: id,
};
if (options.monthlySpend) {
body.monthly_spend = options.monthlySpend as number;
if (additionalFields.monthlySpend) {
body.monthly_spend = additionalFields.monthlySpend as number;
}
if (options.name) {
body.name = options.name as string;
if (additionalFields.name) {
body.name = additionalFields.name as string;
}
if (options.plan) {
body.plan = options.plan as string;
if (additionalFields.plan) {
body.plan = additionalFields.plan as string;
}
if (options.size) {
body.size = options.size as number;
if (additionalFields.size) {
body.size = additionalFields.size as number;
}
if (options.website) {
body.website = options.website as string;
if (additionalFields.website) {
body.website = additionalFields.website as string;
}
if (options.industry) {
body.industry = options.industry as string;
if (additionalFields.industry) {
body.industry = additionalFields.industry as string;
}
if (!jsonActive) {
const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[];
@ -438,58 +459,59 @@ export class Intercom implements INodeType {
}
}
try {
responseData = await intercomApiRequest.call(this, '/companies', 'POST', body);
responseData = await intercomApiRequest.call(this, '/companies', 'POST', body, qs);
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'view') {
let query = '';
const viewBy = this.getNodeParameter('viewBy', 0) as string;
if (operation === 'get') {
const selectBy = this.getNodeParameter('selectBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (viewBy === 'companyId') {
query = `company_id=${value}`;
if (selectBy === 'companyId') {
qs.company_id = value;
}
if (viewBy === 'name') {
query = `name=${value}`;
if (selectBy === 'name') {
qs.name = value;
}
try {
if (viewBy === 'id') {
responseData = await intercomApiRequest.call(this, `/companies/${value}`, 'GET');
} else {
responseData = await intercomApiRequest.call(this, `/companies?${query}`, 'GET');
}
if (selectBy === 'id') {
responseData = await intercomApiRequest.call(this, `/companies/${value}`, 'GET', {}, qs);
} else {
responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs);
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'list') {
let query = '';
const listBy = this.getNodeParameter('listBy', 0) as string;
if (listBy === 'segmentId') {
query = `segment_id=${this.getNodeParameter('value', i) as string}`;
}
if (listBy === 'tagId') {
query = `tag_id=${this.getNodeParameter('value', i) as string}`;
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
Object.assign(qs, filters);
try {
responseData = await intercomApiRequest.call(this, `/companies?${query}`, 'GET');
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'companies', '/companies', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs);
responseData = responseData.companies;
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);
}
}
if (operation === 'users') {
let query = '';
const listBy = this.getNodeParameter('listBy', 0) as string;
const filterBy = this.getNodeParameter('filterBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (listBy === 'companyId') {
query = `company_id=${value}`;
if (filterBy === 'companyId') {
qs.company_id = value;
}
try {
if (listBy === 'id') {
responseData = await intercomApiRequest.call(this, `/companies/${value}/users`, 'GET');
if (filterBy === 'id') {
responseData = await intercomApiRequest.call(this, `/companies/${value}/users`, 'GET', {}, qs);
} else {
responseData = await intercomApiRequest.call(this, `/companies?${query}&type=users`, 'GET');
qs.type = 'users';
responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs);
}
} catch (err) {
throw new Error(`Intercom Error: ${JSON.stringify(err)}`);

View File

@ -18,28 +18,28 @@ export const leadOpeations = [
value: 'create',
description: 'Create a new lead',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a lead',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get data of all leads',
},
{
name: 'Update',
value: 'update',
description: 'Update new lead',
},
{
name: 'View',
value: 'view',
description: 'View a lead',
},
{
name: 'List',
value: 'list',
description: 'List leads',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a lead',
}
],
default: '',
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
@ -68,18 +68,16 @@ export const leadFields = [
{
name: 'ID',
value: 'id',
default: '',
description: 'The Intercom defined id representing the Lead',
},
{
name: 'User ID',
value: 'userId',
default: '',
description: 'Automatically generated identifier for the Lead',
},
],
default: '',
description: 'Delete by'
description: 'Delete by',
},
{
displayName: 'Value',
@ -100,12 +98,12 @@ export const leadFields = [
},
/* -------------------------------------------------------------------------- */
/* lead:view */
/* lead:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'View By',
name: 'viewBy',
displayName: 'Select By',
name: 'selectBy',
type: 'options',
displayOptions: {
show: {
@ -113,67 +111,7 @@ export const leadFields = [
'lead',
],
operation: [
'view',
],
},
},
options: [
{
name: 'ID',
value: 'id',
default: '',
description: 'The Intercom defined id representing the Lead',
},
{
name: 'User ID',
value: 'userId',
default: '',
description: 'Automatically generated identifier for the Lead',
},
{
name: 'Phone',
value: 'phone',
default: '',
description: 'Phone representing the Lead',
},
],
default: '',
description: 'View by'
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'view',
],
},
},
description: 'View by value',
},
/* -------------------------------------------------------------------------- */
/* lead:list */
/* -------------------------------------------------------------------------- */
{
displayName: 'List by',
name: 'listBy',
type: 'options',
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'list',
'get',
],
},
},
@ -181,24 +119,26 @@ export const leadFields = [
{
name: 'Email',
value: 'email',
default: '',
description: 'Email representing the Lead',
},
{
name: 'ID',
value: 'id',
description: 'The Intercom defined id representing the Lead',
},
{
name: 'User ID',
value: 'userId',
description: 'Automatically generated identifier for the Lead',
},
{
name: 'Phone',
value: 'phone',
default: '',
description: 'Phone representing the Lead',
},
{
name: 'All',
value: 'all',
default: '',
description: 'List all leads',
},
],
default: '',
description: 'List by'
description: 'The property to select the lead by.',
},
{
displayName: 'Value',
@ -212,16 +152,90 @@ export const leadFields = [
'lead',
],
operation: [
'list',
'get',
],
},
hide: {
listBy: [
'all'
]
}
},
description: 'list by value',
description: 'View by value',
},
/* -------------------------------------------------------------------------- */
/* lead:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'getAll',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 60,
},
default: 50,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'getAll',
],
},
},
options: [
{
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
description: 'The email address of the lead',
},
{
displayName: 'Phone',
name: 'phone',
type: 'string',
default: '',
description: 'The phone number of the lead',
},
]
},
/* -------------------------------------------------------------------------- */
@ -246,18 +260,16 @@ export const leadFields = [
{
name: 'User ID',
value: 'userId',
default: '',
description: 'Automatically generated identifier for the Lead',
},
{
name: 'ID',
value: 'id',
default: '',
description: 'The Intercom defined id representing the Lead',
},
],
default: '',
description: 'Update by',
default: 'id',
description: 'The property via which to query the lead.',
},
{
displayName: 'Value',
@ -275,7 +287,7 @@ export const leadFields = [
],
},
},
description: 'Update by value',
description: 'Value of the property to identify the lead to update',
},
/* -------------------------------------------------------------------------- */
@ -300,24 +312,6 @@ export const leadFields = [
},
description: 'The email of the user.',
},
{
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
required: false,
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'update',
],
},
},
description: 'The email of the user.',
},
{
displayName: 'JSON Parameters',
name: 'jsonParameters',
@ -331,16 +325,16 @@ export const leadFields = [
'update',
],
resource: [
'lead'
'lead',
],
},
},
},
{
displayName: 'Options',
name: 'options',
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Option',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
@ -349,11 +343,25 @@ export const leadFields = [
'update',
],
resource: [
'lead'
'lead',
],
},
},
options: [
{
displayName: 'Avatar',
name: 'avatar',
type: 'string',
default: '',
description: 'An avatar image URL. note: the image url needs to be https.',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Name of the user',
},
{
displayName: 'Phone',
name: 'phone',
@ -361,20 +369,11 @@ export const leadFields = [
default: '',
description: 'The phone number of the user',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
placeholder: '',
description: 'Name of the user',
},
{
displayName: 'Unsubscribed From Emails',
name: 'unsubscribedFromEmails',
type: 'boolean',
default: '',
placeholder: '',
default: false,
description: 'Whether the Lead is unsubscribed from emails',
},
{
@ -382,8 +381,7 @@ export const leadFields = [
name: 'updateLastRequestAt',
type: 'boolean',
default: false,
options: [],
description: `A boolean value, which if true, instructs Intercom to update the users' last_request_at value to the current API service time in UTC. default value if not sent is false.`,
description: 'A boolean value, which if true, instructs Intercom to update the<br />users last_request_at value to the current API service time in<br />UTC. default value if not sent is false.',
},
{
displayName: 'Companies',
@ -396,11 +394,21 @@ export const leadFields = [
description: 'Identifies the companies this user belongs to.',
},
{
displayName: 'Avatar',
name: 'avatar',
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
description: 'An avatar image URL. note: the image url needs to be https.',
displayOptions: {
show: {
'/resource': [
'lead',
],
'/operation': [
'update',
],
},
},
description: 'The email of the user.',
},
{
displayName: 'UTM Source',
@ -511,4 +519,3 @@ export const leadFields = [
description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.',
},
] as INodeProperties[];

View File

@ -18,28 +18,28 @@ export const userOpeations = [
value: 'create',
description: 'Create a new user',
},
{
name: 'Get',
value: 'get',
description: 'Get data of a user',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get data of all users',
},
{
name: 'Update',
value: 'update',
description: 'Update a user',
},
{
name: 'View',
value: 'view',
description: 'View a user',
},
{
name: 'List',
value: 'list',
description: 'List users',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a user',
}
],
default: '',
default: 'create',
description: 'The operation to perform.',
},
] as INodeProperties[];
@ -70,89 +70,106 @@ export const userFields = [
},
/* -------------------------------------------------------------------------- */
/* user:list */
/* user:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'List by',
name: 'listBy',
type: 'options',
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'list',
'getAll',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 60,
},
default: 50,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getAll',
],
},
},
options: [
{
name: 'Email',
value: 'email',
displayName: 'Company ID',
name: 'company_id',
type: 'string',
default: '',
description: 'Email representing the Lead',
description: 'Company ID representing the user',
},
{
name: 'Segment ID',
value: 'segmentId',
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
description: 'Segment representing the Lead',
description: 'The email address of the user',
},
{
name: 'Tag ID',
value: 'tagId',
displayName: 'Tag ID',
name: 'tag_id',
type: 'string',
default: '',
description: 'Tag representing the Lead',
description: 'Tag representing the user',
},
{
name: 'Company ID',
value: 'companyId',
displayName: 'Segment ID',
name: 'segment_id',
type: 'string',
default: '',
description: 'Company representing the Lead',
},
{
name: 'All',
value: 'all',
default: '',
description: 'List all users',
description: 'Segment representing the user',
},
],
default: '',
description: 'List by'
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'list',
],
},
hide: {
listBy: [
'all'
]
}
},
description: 'list by value',
},
/* -------------------------------------------------------------------------- */
/* view:user */
/* user:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'View By',
name: 'viewBy',
displayName: 'Select By',
name: 'selectBy',
type: 'options',
displayOptions: {
show: {
@ -160,7 +177,7 @@ export const userFields = [
'user',
],
operation: [
'view',
'get',
],
},
},
@ -179,7 +196,7 @@ export const userFields = [
},
],
default: '',
description: 'View by'
description: 'The property to select the user by.',
},
{
displayName: 'Value',
@ -193,7 +210,7 @@ export const userFields = [
'user',
],
operation: [
'view',
'get',
],
},
},
@ -205,10 +222,9 @@ export const userFields = [
/* -------------------------------------------------------------------------- */
{
displayName: 'Id',
name: 'id',
type: 'string',
default: '',
displayName: 'Update By',
name: 'updateBy',
type: 'options',
displayOptions: {
show: {
resource: [
@ -219,13 +235,33 @@ export const userFields = [
],
},
},
description: 'id is matched - the user_id and email will be updated if they are sent.',
options: [
{
name: 'ID',
value: 'id',
description: 'The Intercom defined id representing the user',
},
{
name: 'Email',
value: 'email',
description: 'The email address of user',
},
{
name: 'User ID',
value: 'userId',
description: 'Automatically generated identifier for the user',
},
],
default: 'id',
description: 'The property via which to query the user.',
},
{
displayName: 'User Id',
name: 'userId',
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
@ -236,25 +272,7 @@ export const userFields = [
],
},
},
description: 'user_id match - the email will be updated, the id is not updated.',
},
{
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'update',
],
},
},
description: `email match where no user_id set on the matching user - the user_id will be set to the value sent in the request, the id is not updated.
email match where there is a user_id set on the matching user - a new unique record with new id will be created if a new value for user_id is sent in the request.`,
description: 'Value of the property to identify the user to update',
},
/* -------------------------------------------------------------------------- */
@ -262,8 +280,8 @@ export const userFields = [
/* -------------------------------------------------------------------------- */
{
displayName: 'Id',
name: 'id',
displayName: 'Identifier Type',
name: 'identifierType',
type: 'options',
displayOptions: {
show: {
@ -277,15 +295,13 @@ export const userFields = [
},
options: [
{
name: 'User Id',
name: 'User ID',
value: 'userId',
default: '',
description: 'A unique string identifier for the user. It is required on creation if an email is not supplied.',
},
{
name: 'Email',
value: 'email',
default: '',
description: `The user's email address. It is required on creation if a user_id is not supplied.`,
},
],
@ -329,10 +345,10 @@ export const userFields = [
},
},
{
displayName: 'Options',
name: 'options',
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Option',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
@ -346,6 +362,51 @@ export const userFields = [
},
},
options: [
{
displayName: 'Email',
name: 'email',
displayOptions: {
show: {
'/operation': [
'update',
],
'/resource': [
'user'
],
},
hide: {
'/updateBy': [
'email',
]
},
},
type: 'string',
default: '',
description: 'Email of the user',
},
{
displayName: 'User ID',
name: 'userId',
displayOptions: {
show: {
'/operation': [
'update',
],
'/resource': [
'user'
],
},
hide: {
'/updateBy': [
'email',
'userId',
]
},
},
type: 'string',
default: '',
description: 'Email of the user',
},
{
displayName: 'Phone',
name: 'phone',
@ -375,7 +436,7 @@ export const userFields = [
type: 'boolean',
default: false,
options: [],
description: `A boolean value, which if true, instructs Intercom to update the users' last_request_at value to the current API service time in UTC. default value if not sent is false.`,
description: 'A boolean value, which if true, instructs Intercom to update the users<br />last_request_at value to the current API service time in UTC.',
},
{
displayName: 'Session Count',
@ -511,4 +572,3 @@ export const userFields = [
description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.',
},
] as INodeProperties[];