update lead done

This commit is contained in:
Ricardo Espinoza 2019-11-20 09:45:58 -05:00
parent b281eb511a
commit 503baf82f7
3 changed files with 90 additions and 5 deletions

View file

@ -97,9 +97,9 @@ export class Intercom implements INodeType {
let responseData;
for (let i = 0; i < length; i++) {
const resource = this.getNodeParameter('resource', 0) as string;
const opeation = this.getNodeParameter('operation', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
if (resource === 'lead') {
if (opeation === 'create') {
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;
@ -144,6 +144,16 @@ 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;
if (updateBy === 'userId') {
body.user_id = value;
}
if (updateBy === 'id') {
body.id = value;
}
}
try {
responseData = await intercomApiRequest.call(this, '/contacts', 'POST', body);
} catch (err) {

View file

@ -18,6 +18,11 @@ export const leadOpeations = [
value: 'create',
description: 'Create a new lead',
},
{
name: 'Update',
value: 'update',
description: 'Update a new lead',
},
],
default: '',
description: 'The operation to perform.',
@ -25,6 +30,55 @@ export const leadOpeations = [
] as INodeProperties[];
export const leadFields = [
{
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',
},
{
displayName: 'Email',
name: 'email',
@ -43,6 +97,24 @@ 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',
@ -53,6 +125,7 @@ export const leadFields = [
show: {
operation: [
'create',
'update',
],
resource: [
'lead'
@ -70,6 +143,7 @@ export const leadFields = [
show: {
operation: [
'create',
'update',
],
resource: [
'lead'
@ -82,7 +156,6 @@ export const leadFields = [
name: 'phone',
type: 'string',
default: '',
required: false,
description: 'The phone number of the user',
},
{
@ -107,7 +180,6 @@ export const leadFields = [
type: 'boolean',
default: false,
options: [],
required: false,
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.`,
},
{
@ -118,7 +190,6 @@ export const leadFields = [
loadOptionsMethod: 'getCompanies',
},
default: [],
required: false,
description: 'Identifies the companies this user belongs to.',
},
]
@ -138,6 +209,7 @@ export const leadFields = [
],
operation: [
'create',
'update',
],
jsonParameters: [
true,
@ -164,6 +236,7 @@ export const leadFields = [
],
operation: [
'create',
'update',
],
jsonParameters: [
false,

View file

@ -5,6 +5,8 @@ export interface ILeadCompany {
}
export interface ILead {
user_id?: string;
id?: string;
email: string;
phone?: string;
name?: string;