diff --git a/packages/nodes-base/nodes/Intercom/CompanyDescription.ts b/packages/nodes-base/nodes/Intercom/CompanyDescription.ts new file mode 100644 index 000000000..fd95ce07d --- /dev/null +++ b/packages/nodes-base/nodes/Intercom/CompanyDescription.ts @@ -0,0 +1,402 @@ +import { INodeProperties } from "n8n-workflow"; + +export const companyOpeations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'company', + ], + }, + }, + options: [ + { + name: 'Create', + value: 'create', + description: 'Create a new company', + }, + { + name: 'Update', + value: 'update', + description: 'Update a company', + }, + { + name: 'View', + value: 'view', + description: 'View a company', + }, + { + name: 'List', + value: 'list', + description: 'List companies', + }, + { + name: 'Company Users', + value: 'companyUsers', + description: `List company's users`, + }, + ], + default: '', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const companyFields = [ + +/* -------------------------------------------------------------------------- */ +/* company:companyUsers */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'List By', + name: 'listBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'companyUsers', + ], + }, + }, + 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', + }, + ], + default: '', + description: 'List by' + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'companyUsers', + ], + }, + }, + description: 'View by value', + }, +/* -------------------------------------------------------------------------- */ +/* company:list */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'List by', + name: 'listBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'list', + ], + }, + }, + options: [ + { + name: 'Segment ID', + value: 'segmentId', + default: '', + description: 'Segment representing the Lead', + }, + { + name: 'Tag ID', + value: 'tagId', + 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 */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'View By', + name: 'viewBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'view', + ], + }, + }, + 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: 'Name', + value: 'name', + default: '', + description: 'The name of the company', + }, + ], + default: '', + description: 'View by' + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'view', + ], + }, + }, + description: 'View by value', + }, + +/* -------------------------------------------------------------------------- */ +/* company:create/update */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'Company Id', + name: 'companyId', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'create', + 'update' + ], + }, + }, + description: 'The company id you have defined for the company', + }, + { + displayName: 'JSON Parameters', + name: 'jsonParameters', + type: 'boolean', + default: false, + description: '', + displayOptions: { + show: { + operation: [ + 'create', + 'update', + ], + resource: [ + 'company' + ], + }, + }, + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + displayOptions: { + show: { + operation: [ + 'create', + 'update', + ], + resource: [ + 'company' + ], + }, + }, + options: [ + { + displayName: 'Monthly Spend', + name: 'monthlySpend', + type: 'string', + default: '', + description: 'The phone number of the user', + }, + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + placeholder: '', + description: 'Name of the user', + }, + { + displayName: 'Plan', + name: 'plan', + type: 'string', + default: '', + placeholder: '', + description: 'The name of the plan you have associated with the company', + }, + { + displayName: 'Size', + name: 'size', + type: 'number', + default: '', + description: 'The number of employees in this company', + }, + { + displayName: 'Website', + 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', + }, + ] + }, + { + displayName: 'Custom Attributes', + name: 'customAttributesJson', + type: 'json', + required: false, + typeOptions: { + alwaysOpenEditWindow: true, + }, + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'create', + 'update', + ], + jsonParameters: [ + true, + ], + }, + }, + default: '', + description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.', + }, + { + displayName: 'Custom Attributes', + name: 'customAttributesUi', + type: 'fixedCollection', + default: '', + placeholder: 'Add Attribute', + typeOptions: { + multipleValues: true, + }, + required: false, + displayOptions: { + show: { + resource: [ + 'company', + ], + operation: [ + 'create', + 'update', + ], + jsonParameters: [ + false, + ], + }, + }, + options: [ + { + name: 'customAttributesValues', + displayName: 'Attributes', + values: [ + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + }, + ], + } + ], + description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.', + }, +] as INodeProperties[]; + diff --git a/packages/nodes-base/nodes/Intercom/CompanyInteface.ts b/packages/nodes-base/nodes/Intercom/CompanyInteface.ts new file mode 100644 index 000000000..bffa55334 --- /dev/null +++ b/packages/nodes-base/nodes/Intercom/CompanyInteface.ts @@ -0,0 +1,13 @@ +import { IDataObject } from "n8n-workflow"; + +export interface ICompany { + remote_created_at?: string; + company_id?: string; + name?: string; + monthly_spend?: number; + plan?: string; + size?: number; + website?: string; + industry?: string; + custom_attributes?: IDataObject; +} diff --git a/packages/nodes-base/nodes/Intercom/GenericFunctions.ts b/packages/nodes-base/nodes/Intercom/GenericFunctions.ts index 8b32b726b..2c8df9962 100644 --- a/packages/nodes-base/nodes/Intercom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Intercom/GenericFunctions.ts @@ -9,7 +9,6 @@ import { export async function intercomApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise { // tslint:disable-line:no-any const credentials = this.getCredentials('intercomApi'); - if (credentials === undefined) { throw new Error('No credentials got returned!'); } diff --git a/packages/nodes-base/nodes/Intercom/Intercom.node.ts b/packages/nodes-base/nodes/Intercom/Intercom.node.ts index 58fe5ebe9..d5bc587ff 100644 --- a/packages/nodes-base/nodes/Intercom/Intercom.node.ts +++ b/packages/nodes-base/nodes/Intercom/Intercom.node.ts @@ -19,11 +19,15 @@ import { } from './GenericFunctions'; import { ILead, - ILeadCompany + ILeadCompany, + IAvatar, } from './LeadInterface'; +import { userOpeations, userFields } from './UserDescription'; +import { IUser, IUserCompany } from './UserInterface'; +import { companyOpeations, companyFields } from './CompanyDescription'; +import { ICompany } from './CompanyInteface'; export class Intercom implements INodeType { - description: INodeTypeDescription = { displayName: 'Intercom', name: 'intercom', @@ -50,17 +54,31 @@ export class Intercom implements INodeType { name: 'resource', type: 'options', options: [ + { + name: 'User', + value: 'user', + description: 'The Users resource is the primary way of interacting with Intercom', + }, { name: 'Lead', value: 'lead', - description: '', + 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.', }, ], default: '', description: 'Resource to consume.', }, ...leadOpeations, + ...userOpeations, + ...companyOpeations, + ...userFields, ...leadFields, + ...companyFields, ], }; @@ -86,7 +104,7 @@ export class Intercom implements INodeType { }); } return returnData; - } + }, }, }; @@ -98,14 +116,16 @@ export class Intercom implements INodeType { for (let i = 0; i < length; i++) { 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 jsonActive = this.getNodeParameter('jsonParameters', i) as boolean; - const body: ILead = { - email, - }; + const body: ILead = {}; + if (email) { + body.email = this.getNodeParameter('email', i) as string; + } if (options.phone) { body.phone = options.phone as string; } @@ -118,6 +138,28 @@ export class Intercom implements INodeType { if (options.updateLastRequestAt) { body.update_last_request_at = options.updateLastRequestAt as boolean; } + if (options.utmSource) { + body.utm_source = options.utmSource as string; + } + if (options.utmMedium) { + body.utm_medium = options.utmMedium as string; + } + if (options.utmCampaign) { + body.utm_campaign = options.utmCampaign as string; + } + if (options.utmTerm) { + body.utm_term = options.utmTerm as string; + } + if (options.utmContent) { + body.utm_content = options.utmContent as string; + } + if(options.avatar) { + const avatar: IAvatar = { + type: 'avatar', + image_url: options.avatar as string, + }; + body.avatar = avatar; + } if (options.companies) { const companies: ILeadCompany[] = []; // @ts-ignore @@ -128,6 +170,18 @@ export class Intercom implements INodeType { }); body.companies = companies; } + // console.log(options.segments) + // if (options.segments) { + // const segments: ISegment[] = []; + // // @ts-ignore + // options.segments.forEach( o => { + // const segment: ISegment = {}; + // segment.id = o; + // segment.type = 'segment'; + // segments.push(segment); + // }); + // body.segments = { segments }; + // } if (!jsonActive) { const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[]; if (customAttributesValues) { @@ -138,7 +192,25 @@ export class Intercom implements INodeType { } body.custom_attributes = customAttributes; } + // const socialProfilesValues = (this.getNodeParameter('socialProfilesUi', i) as IDataObject).socialProfilesValues as IDataObject[]; + // if (socialProfilesValues && socialProfilesValues.length > 0) { + // const socialProfiles: ISocialProfile[] = []; + // socialProfilesValues.forEach( o => { + // const socialProfile: ISocialProfile = {}; + // socialProfile.name = o.name as string; + // socialProfile.type = 'social_profile'; + // socialProfile.username = o.username as string; + // socialProfile.url = o.url as string; + // socialProfile.id = o.id as string; + // socialProfiles.push(socialProfile); + // }); + // body.social_profiles = socialProfiles; + // } } else { + // const socialProfilesJson = validateJSON(this.getNodeParameter('socialProfilesJson', i) as string); + // if (socialProfilesJson) { + // body.social_profiles = socialProfilesJson; + // } const customAttributesJson = validateJSON(this.getNodeParameter('customAttributesJson', i) as string); if (customAttributesJson) { body.custom_attributes = customAttributesJson; @@ -160,6 +232,299 @@ export class Intercom implements INodeType { throw new Error(`Intercom Error: ${JSON.stringify(err)}`); } } + if (operation === 'view') { + let query = ''; + const viewBy = this.getNodeParameter('viewBy', 0) as string; + const value = this.getNodeParameter('value', i) as string; + if (viewBy === 'userId') { + query = `user_id=${value}`; + } + if (viewBy === 'phone') { + query = `phone=${value}`; + } + try { + if (viewBy === 'id') { + responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'GET'); + } else { + responseData = await intercomApiRequest.call(this, `/contacts?${query}`, 'GET'); + } + } 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}`; + } + try { + responseData = await intercomApiRequest.call(this, `/contacts?${query}`, 'GET'); + } catch (err) { + throw new Error(`Intercom Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'delete') { + const deleteBy = this.getNodeParameter('deleteBy', 0) as string; + const value = this.getNodeParameter('value', i) as string; + try { + if (deleteBy === 'id') { + responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'DELETE'); + } else { + responseData = await intercomApiRequest.call(this, `/contacts?user_id=${value}`, 'DELETE'); + } + } catch (err) { + throw new Error(`Intercom Error: ${JSON.stringify(err)}`); + } + } + } + //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 jsonActive = this.getNodeParameter('jsonParameters', i) as boolean; + const body: IUser = {}; + if (id === 'email') { + body.email = this.getNodeParameter('idValue', i) as string; + } + if (id === 'userId') { + body.user_id = this.getNodeParameter('idValue', i) as string; + } + if (options.phone) { + body.phone = options.phone as string; + } + if (options.name) { + body.name = options.name as string; + } + if (options.unsubscribedFromEmails) { + body.unsubscribed_from_emails = options.unsubscribedFromEmails as boolean; + } + if (options.updateLastRequestAt) { + body.update_last_request_at = options.updateLastRequestAt as boolean; + } + if (options.sessionCount) { + body.session_count = options.sessionCount as number; + } + if(options.avatar) { + const avatar: IAvatar = { + type: 'avatar', + image_url: options.avatar as string, + }; + body.avatar = avatar; + } + if (options.utmSource) { + body.utm_source = options.utmSource as string; + } + if (options.utmMedium) { + body.utm_medium = options.utmMedium as string; + } + if (options.utmCampaign) { + body.utm_campaign = options.utmCampaign as string; + } + if (options.utmTerm) { + body.utm_term = options.utmTerm as string; + } + if (options.utmContent) { + body.utm_content = options.utmContent as string; + } + if (options.companies) { + const companies: IUserCompany[] = []; + // @ts-ignore + options.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 (!jsonActive) { + const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[]; + if (customAttributesValues) { + const customAttributes = {}; + for (let i = 0; i < customAttributesValues.length; i++) { + // @ts-ignore + customAttributes[customAttributesValues[i].name] = customAttributesValues[i].value; + } + body.custom_attributes = customAttributes; + } + } else { + const customAttributesJson = validateJSON(this.getNodeParameter('customAttributesJson', i) as string); + if (customAttributesJson) { + 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; + } + if (email) { + body.email = email; + } + if (userId) { + body.user_id = userId; + } + } + try { + responseData = await intercomApiRequest.call(this, '/users', '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; + const value = this.getNodeParameter('value', i) as string; + if (viewBy === 'userId') { + query = `user_id=${value}`; + } + try { + if (viewBy === 'id') { + responseData = await intercomApiRequest.call(this, `/users/${value}`, 'GET'); + } else { + responseData = await intercomApiRequest.call(this, `/users?${query}`, 'GET'); + } + } 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}`; + } + try { + responseData = await intercomApiRequest.call(this, `/users?${query}`, 'GET'); + } catch (err) { + throw new Error(`Intercom Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'delete') { + const id = this.getNodeParameter('id', i) as string; + try { + responseData = await intercomApiRequest.call(this, `/users/${id}`, 'DELETE'); + } catch (err) { + throw new Error(`Intercom Error: ${JSON.stringify(err)}`); + } + } + } + //https://developers.intercom.com/intercom-api-reference/reference#companies + 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 jsonActive = this.getNodeParameter('jsonParameters', i) as boolean; + const body: ICompany = { + company_id: id, + }; + if (options.monthlySpend) { + body.monthly_spend = options.monthlySpend as number; + } + if (options.name) { + body.name = options.name as string; + } + if (options.plan) { + body.plan = options.plan as string; + } + if (options.size) { + body.size = options.size as number; + } + if (options.website) { + body.website = options.website as string; + } + if (options.industry) { + body.industry = options.industry as string; + } + if (!jsonActive) { + const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[]; + if (customAttributesValues) { + const customAttributes = {}; + for (let i = 0; i < customAttributesValues.length; i++) { + // @ts-ignore + customAttributes[customAttributesValues[i].name] = customAttributesValues[i].value; + } + body.custom_attributes = customAttributes; + } + } else { + const customAttributesJson = validateJSON(this.getNodeParameter('customAttributesJson', i) as string); + if (customAttributesJson) { + body.custom_attributes = customAttributesJson; + } + } + try { + responseData = await intercomApiRequest.call(this, '/companies', '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; + const value = this.getNodeParameter('value', i) as string; + if (viewBy === 'companyId') { + query = `company_id=${value}`; + } + if (viewBy === 'name') { + query = `name=${value}`; + } + try { + if (viewBy === 'id') { + responseData = await intercomApiRequest.call(this, `/companies/${value}`, 'GET'); + } else { + responseData = await intercomApiRequest.call(this, `/companies?${query}`, 'GET'); + } + } 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}`; + } + try { + responseData = await intercomApiRequest.call(this, `/companies?${query}`, 'GET'); + } catch (err) { + throw new Error(`Intercom Error: ${JSON.stringify(err)}`); + } + } + if (operation === 'companyUsers') { + let query = ''; + const listBy = this.getNodeParameter('listBy', 0) as string; + const value = this.getNodeParameter('value', i) as string; + if (listBy === 'companyId') { + query = `company_id=${value}`; + } + try { + if (listBy === 'id') { + responseData = await intercomApiRequest.call(this, `/companies/${value}/users`, 'GET'); + } else { + responseData = await intercomApiRequest.call(this, `/companies?${query}&type=users`, 'GET'); + } + } catch (err) { + throw new Error(`Intercom Error: ${JSON.stringify(err)}`); + } + } } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); diff --git a/packages/nodes-base/nodes/Intercom/LeadDescription.ts b/packages/nodes-base/nodes/Intercom/LeadDescription.ts index 5e5f53bd0..03bfd1f29 100644 --- a/packages/nodes-base/nodes/Intercom/LeadDescription.ts +++ b/packages/nodes-base/nodes/Intercom/LeadDescription.ts @@ -21,8 +21,23 @@ export const leadOpeations = [ { name: 'Update', value: 'update', - description: 'Update a new lead', + 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: '', description: 'The operation to perform.', @@ -30,6 +45,189 @@ export const leadOpeations = [ ] as INodeProperties[]; export const leadFields = [ + +/* -------------------------------------------------------------------------- */ +/* lead:delete */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'Delete By', + name: 'deleteBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'lead', + ], + operation: [ + 'delete', + ], + }, + }, + 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', + }, + ], + default: '', + description: 'Delete by' + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'lead', + ], + operation: [ + 'delete', + ], + }, + }, + description: 'Delete by value', + }, + +/* -------------------------------------------------------------------------- */ +/* lead:view */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'View By', + name: 'viewBy', + type: 'options', + displayOptions: { + show: { + resource: [ + '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', + ], + }, + }, + options: [ + { + name: 'Email', + value: 'email', + default: '', + description: 'Email representing 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' + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'lead', + ], + operation: [ + 'list', + ], + }, + hide: { + listBy: [ + 'all' + ] + } + }, + description: 'list by value', + }, + +/* -------------------------------------------------------------------------- */ +/* lead:update */ +/* -------------------------------------------------------------------------- */ + { displayName: 'Update By', name: 'updateBy', @@ -46,13 +244,13 @@ export const leadFields = [ }, options: [ { - name: 'User Id', + name: 'User ID', value: 'userId', default: '', description: 'Automatically generated identifier for the Lead', }, { - name: 'Id', + name: 'ID', value: 'id', default: '', description: 'The Intercom defined id representing the Lead', @@ -79,6 +277,11 @@ export const leadFields = [ }, description: 'Update by value', }, + +/* -------------------------------------------------------------------------- */ +/* lead:create */ +/* -------------------------------------------------------------------------- */ + { displayName: 'Email', name: 'email', @@ -192,6 +395,48 @@ export const leadFields = [ default: [], description: 'Identifies the companies this user belongs to.', }, + { + displayName: 'Avatar', + name: 'avatar', + type: 'string', + default: '', + description: 'An avatar image URL. note: the image url needs to be https.', + }, + { + displayName: 'UTM Source', + name: 'utmSource', + type: 'string', + default: '', + description: 'An avatar image URL. note: the image url needs to be https.', + }, + { + displayName: 'UTM Medium', + name: 'utmMedium', + type: 'string', + default: '', + description: 'Identifies what type of link was used', + }, + { + displayName: 'UTM Campaign', + name: 'utmCampaign', + type: 'string', + default: '', + description: 'Identifies a specific product promotion or strategic campaign', + }, + { + displayName: 'UTM Term', + name: 'utmTerm', + type: 'string', + default: '', + description: 'Identifies search terms', + }, + { + displayName: 'UTM Content', + name: 'utmContent', + type: 'string', + default: '', + description: 'Identifies what specifically was clicked to bring the user to the site', + }, ] }, { diff --git a/packages/nodes-base/nodes/Intercom/LeadInterface.ts b/packages/nodes-base/nodes/Intercom/LeadInterface.ts index b7e4f9a00..6a716577f 100644 --- a/packages/nodes-base/nodes/Intercom/LeadInterface.ts +++ b/packages/nodes-base/nodes/Intercom/LeadInterface.ts @@ -4,10 +4,15 @@ export interface ILeadCompany { company_id?: string; } +export interface IAvatar { + type?: string; + image_url?: string; +} + export interface ILead { user_id?: string; id?: string; - email: string; + email?: string; phone?: string; name?: string; custom_attributes?: IDataObject; @@ -15,4 +20,10 @@ export interface ILead { last_request_at?: number; unsubscribed_from_emails?: boolean; update_last_request_at?: boolean; + avatar?: IAvatar; + utm_source?: string; + utm_medium?: string; + utm_campaign?: string; + utm_term?: string; + utm_content?: string; } diff --git a/packages/nodes-base/nodes/Intercom/UserDescription.ts b/packages/nodes-base/nodes/Intercom/UserDescription.ts new file mode 100644 index 000000000..2f89ae368 --- /dev/null +++ b/packages/nodes-base/nodes/Intercom/UserDescription.ts @@ -0,0 +1,514 @@ +import { INodeProperties } from "n8n-workflow"; + +export const userOpeations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + }, + }, + options: [ + { + name: 'Create', + value: 'create', + description: 'Create a new user', + }, + { + 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: '', + description: 'The operation to perform.', + }, +] as INodeProperties[]; + +export const userFields = [ + +/* -------------------------------------------------------------------------- */ +/* user:delete */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'ID', + name: 'id', + type: 'string', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'delete', + ], + }, + }, + default: '', + description: 'The Intercom defined id representing the Lead', + }, + +/* -------------------------------------------------------------------------- */ +/* user:list */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'List by', + name: 'listBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'list', + ], + }, + }, + options: [ + { + name: 'Email', + value: 'email', + default: '', + description: 'Email representing the Lead', + }, + { + name: 'Segment ID', + value: 'segmentId', + default: '', + description: 'Segment representing the Lead', + }, + { + name: 'Tag ID', + value: 'tagId', + default: '', + description: 'Tag representing the Lead', + }, + { + name: 'Company ID', + value: 'companyId', + default: '', + description: 'Company 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: [ + 'user', + ], + operation: [ + 'list', + ], + }, + hide: { + listBy: [ + 'all' + ] + } + }, + description: 'list by value', + }, + +/* -------------------------------------------------------------------------- */ +/* view:user */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'View By', + name: 'viewBy', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + 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', + }, + ], + default: '', + description: 'View by' + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'view', + ], + }, + }, + description: 'View by value', + }, + +/* -------------------------------------------------------------------------- */ +/* user:update */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'Id', + name: 'id', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'update', + ], + }, + }, + description: 'id is matched - the user_id and email will be updated if they are sent.', + }, + { + displayName: 'User Id', + name: 'userId', + type: 'string', + default: '', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'update', + ], + }, + }, + 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.`, + }, + +/* -------------------------------------------------------------------------- */ +/* user:create */ +/* -------------------------------------------------------------------------- */ + + { + displayName: 'Id', + name: 'id', + type: 'options', + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'create', + ], + }, + }, + options: [ + { + 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.`, + }, + ], + default: '', + description: 'Unique string identifier', + }, + { + displayName: 'Value', + name: 'idValue', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'create', + ], + }, + }, + description: 'Unique string identifier value', + }, + { + displayName: 'JSON Parameters', + name: 'jsonParameters', + type: 'boolean', + default: false, + description: '', + displayOptions: { + show: { + operation: [ + 'create', + 'update', + ], + resource: [ + 'user' + ], + }, + }, + }, + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + displayOptions: { + show: { + operation: [ + 'create', + 'update', + ], + resource: [ + 'user' + ], + }, + }, + options: [ + { + displayName: 'Phone', + name: 'phone', + type: 'string', + 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: '', + description: 'Whether the user is unsubscribed from emails', + }, + { + displayName: 'Update Last Request At', + 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.`, + }, + { + displayName: 'Session Count', + name: 'sessionCount', + type: 'number', + default: false, + options: [], + description: `How many sessions the user has recorded`, + }, + { + displayName: 'Companies', + name: 'companies', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getCompanies', + }, + default: [], + description: 'Identifies the companies this user belongs to.', + }, + { + displayName: 'Avatar', + name: 'avatar', + type: 'string', + default: '', + description: 'An avatar image URL. note: the image url needs to be https.', + }, + { + displayName: 'UTM Source', + name: 'utmSource', + type: 'string', + default: '', + description: 'An avatar image URL. note: the image url needs to be https.', + }, + { + displayName: 'UTM Medium', + name: 'utmMedium', + type: 'string', + default: '', + description: 'Identifies what type of link was used', + }, + { + displayName: 'UTM Campaign', + name: 'utmCampaign', + type: 'string', + default: '', + description: 'Identifies a specific product promotion or strategic campaign', + }, + { + displayName: 'UTM Term', + name: 'utmTerm', + type: 'string', + default: '', + description: 'Identifies search terms', + }, + { + displayName: 'UTM Content', + name: 'utmContent', + type: 'string', + default: '', + description: 'Identifies what specifically was clicked to bring the user to the site', + }, + ] + }, + { + displayName: 'Custom Attributes', + name: 'customAttributesJson', + type: 'json', + required: false, + typeOptions: { + alwaysOpenEditWindow: true, + }, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'create', + 'update', + ], + jsonParameters: [ + true, + ], + }, + }, + default: '', + description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.', + }, + { + displayName: 'Custom Attributes', + name: 'customAttributesUi', + type: 'fixedCollection', + default: '', + placeholder: 'Add Attribute', + typeOptions: { + multipleValues: true, + }, + required: false, + displayOptions: { + show: { + resource: [ + 'user', + ], + operation: [ + 'create', + 'update', + ], + jsonParameters: [ + false, + ], + }, + }, + options: [ + { + name: 'customAttributesValues', + displayName: 'Attributes', + values: [ + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + }, + ], + } + ], + description: 'A hash of key/value pairs to represent custom data you want to attribute to a user.', + }, +] as INodeProperties[]; + diff --git a/packages/nodes-base/nodes/Intercom/UserInterface.ts b/packages/nodes-base/nodes/Intercom/UserInterface.ts new file mode 100644 index 000000000..802941af9 --- /dev/null +++ b/packages/nodes-base/nodes/Intercom/UserInterface.ts @@ -0,0 +1,32 @@ +import { IDataObject } from "n8n-workflow"; + +export interface IUserCompany { + company_id?: string; +} + +export interface IAvatar { + type?: string; + image_url?: string; +} + +export interface IUser { + user_id?: string; + id?: string; + email?: string; + phone?: string; + name?: string; + custom_attributes?: IDataObject; + companies?: IUserCompany[]; + last_request_at?: number; + signed_up_at?: string; + unsubscribed_from_emails?: boolean; + update_last_request_at?: boolean; + last_seen_user_agent?: boolean; + session_count?: number; + avatar?: IAvatar; + utm_source?: string; + utm_medium?: string; + utm_campaign?: string; + utm_term?: string; + utm_content?: string; +}