🔀 Merge branch 'feature/intercom-node' of https://github.com/RicardoE105/n8n into RicardoE105-feature/intercom-node

This commit is contained in:
Jan Oberhauser 2019-11-22 07:13:11 +01:00
commit efb0ce88f1
11 changed files with 2084 additions and 2 deletions

View file

@ -0,0 +1,18 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
export class IntercomApi implements ICredentialType {
name = 'intercomApi';
displayName = 'Intercom API';
properties = [
{
displayName: 'API Key',
name: 'apiKey',
type: 'string' as NodePropertyTypes,
default: '',
},
];
}

View file

@ -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: 'Users',
value: 'users',
description: `List company's users`,
},
],
default: '',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const companyFields = [
/* -------------------------------------------------------------------------- */
/* company:users */
/* -------------------------------------------------------------------------- */
{
displayName: 'List By',
name: 'listBy',
type: 'options',
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'users',
],
},
},
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: [
'users',
],
},
},
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[];

View file

@ -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;
}

View file

@ -0,0 +1,51 @@
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
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
const credentials = this.getCredentials('intercomApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const headerWithAuthentication = Object.assign({}, headers,
{ Authorization: `Bearer ${credentials.apiKey}`, Accept: 'application/json' });
const endpoint = 'api.intercom.io';
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method,
uri: `https://${endpoint}${resource}`,
body,
json: true
};
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) {
throw errorMessage;
}
throw error.response.body;
}
}
export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any
let result;
try {
result = JSON.parse(json!);
} catch (exception) {
result = '';
}
return result;
}

View file

@ -0,0 +1,507 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeTypeDescription,
INodeExecutionData,
INodeType,
ILoadOptionsFunctions,
INodePropertyOptions,
} from 'n8n-workflow';
import {
leadOpeations,
leadFields,
} from './LeadDescription';
import {
intercomApiRequest,
validateJSON,
} from './GenericFunctions';
import {
ILead,
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',
icon: 'file:intercom.png',
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume intercom API',
defaults: {
name: 'Intercom',
color: '#c02428',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'intercomApi',
required: true,
}
],
properties: [
{
displayName: 'Resource',
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: '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,
],
};
methods = {
loadOptions: {
// Get all the available companies to display them to user so that he can
// select them easily
async getCompanies(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
let companies, response;
try {
response = await intercomApiRequest.call(this, '/companies', 'GET');
} catch (err) {
throw new Error(`Intercom Error: ${err}`);
}
companies = response.companies;
for (const company of companies) {
const companyName = company.name;
const companyId = company.company_id;
returnData.push({
name: companyName,
value: companyId,
});
}
return returnData;
},
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let responseData;
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 = {};
if (email) {
body.email = this.getNodeParameter('email', 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.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
options.companies.forEach( o => {
const company: ILeadCompany = {};
company.company_id = o;
companies.push(company);
});
body.companies = companies;
}
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 updateBy = this.getNodeParameter('updateBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (updateBy === 'userId') {
body.user_id = value;
}
if (updateBy === 'id') {
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;
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 === 'users') {
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[]);
} else {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}

View file

@ -0,0 +1,514 @@
import { INodeProperties } from "n8n-workflow";
export const leadOpeations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'lead',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a new lead',
},
{
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: '',
description: 'The operation to perform.',
},
] 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',
type: 'options',
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'update',
],
},
},
options: [
{
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',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'update',
],
},
},
description: 'Update by value',
},
/* -------------------------------------------------------------------------- */
/* lead:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'lead',
],
operation: [
'create',
],
},
},
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',
type: 'boolean',
default: false,
description: '',
displayOptions: {
show: {
operation: [
'create',
'update',
],
resource: [
'lead'
],
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'create',
'update',
],
resource: [
'lead'
],
},
},
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 Lead 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: '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: [
'lead',
],
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: [
'lead',
],
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[];

View file

@ -0,0 +1,29 @@
import { IDataObject } from "n8n-workflow";
export interface ILeadCompany {
company_id?: string;
}
export interface IAvatar {
type?: string;
image_url?: string;
}
export interface ILead {
user_id?: string;
id?: string;
email?: string;
phone?: string;
name?: string;
custom_attributes?: IDataObject;
companies?: ILeadCompany[];
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;
}

View file

@ -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[];

View file

@ -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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

@ -41,6 +41,7 @@
"dist/credentials/HttpBasicAuth.credentials.js",
"dist/credentials/HttpDigestAuth.credentials.js",
"dist/credentials/HttpHeaderAuth.credentials.js",
"dist/credentials/IntercomApi.credentials.js",
"dist/credentials/Imap.credentials.js",
"dist/credentials/LinkFishApi.credentials.js",
"dist/credentials/MailchimpApi.credentials.js",
@ -99,6 +100,7 @@
"dist/nodes/HttpRequest.node.js",
"dist/nodes/If.node.js",
"dist/nodes/Interval.node.js",
"dist/nodes/Intercom/Intercom.node.js",
"dist/nodes/LinkFish/LinkFish.node.js",
"dist/nodes/Mailchimp/Mailchimp.node.js",
"dist/nodes/Mailgun/Mailgun.node.js",