🐛 Fix issue sending tags when creating a conversation (HelpScout) (#1501)

This commit is contained in:
Ricardo Espinoza 2021-03-01 17:38:22 -05:00 committed by GitHub
parent 3ff7d3af39
commit f13a2781a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 19 deletions

View file

@ -1,10 +1,14 @@
import { OptionsWithUri } from 'request'; import {
OptionsWithUri,
} from 'request';
import { import {
IExecuteFunctions, IExecuteFunctions,
IExecuteSingleFunctions, IExecuteSingleFunctions,
IHookFunctions, IHookFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
} from 'n8n-core'; } from 'n8n-core';
import { import {
IDataObject, IDataObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -35,8 +39,8 @@ export async function helpscoutApiRequest(this: IExecuteFunctions | IExecuteSing
return await this.helpers.requestOAuth2.call(this, 'helpScoutOAuth2Api', options); return await this.helpers.requestOAuth2.call(this, 'helpScoutOAuth2Api', options);
} catch (error) { } catch (error) {
if (error.response && error.response.body if (error.response && error.response.body
&& error.response.body._embedded && error.response.body._embedded
&& error.response.body._embedded.errors) { && error.response.body._embedded.errors) {
// Try to return the error prettier // Try to return the error prettier
//@ts-ignore //@ts-ignore
throw new Error(`HelpScout error response [${error.statusCode}]: ${error.response.body.message} - ${error.response.body._embedded.errors.map(error => { throw new Error(`HelpScout error response [${error.statusCode}]: ${error.response.body.message} - ${error.response.body._embedded.errors.map(error => {
@ -48,7 +52,7 @@ export async function helpscoutApiRequest(this: IExecuteFunctions | IExecuteSing
} }
} }
export async function helpscoutApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, propertyName: string ,method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function helpscoutApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];

View file

@ -59,7 +59,7 @@ export class HelpScout implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'HelpScout', displayName: 'HelpScout',
name: 'helpScout', name: 'helpScout',
icon: 'file:helpScout.png', icon: 'file:helpScout.svg',
group: ['input'], group: ['input'],
version: 1, version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
@ -139,7 +139,7 @@ export class HelpScout implements INodeType {
const tagId = tag.id; const tagId = tag.id;
returnData.push({ returnData.push({
name: tagName, name: tagName,
value: tagId, value: tagName,
}); });
} }
return returnData; return returnData;
@ -391,23 +391,23 @@ export class HelpScout implements INodeType {
} }
if (attachments) { if (attachments) {
if (attachments.attachmentsValues if (attachments.attachmentsValues
&& (attachments.attachmentsValues as IDataObject[]).length !== 0) { && (attachments.attachmentsValues as IDataObject[]).length !== 0) {
body.attachments?.push.apply(body.attachments, attachments.attachmentsValues as IAttachment[]); body.attachments?.push.apply(body.attachments, attachments.attachmentsValues as IAttachment[]);
} }
if (attachments.attachmentsBinary if (attachments.attachmentsBinary
&& (attachments.attachmentsBinary as IDataObject[]).length !== 0 && (attachments.attachmentsBinary as IDataObject[]).length !== 0
&& items[i].binary) { && items[i].binary) {
const mapFunction = (value: IDataObject): IAttachment => { const mapFunction = (value: IDataObject): IAttachment => {
const binaryProperty = (items[i].binary as IBinaryKeyData)[value.property as string]; const binaryProperty = (items[i].binary as IBinaryKeyData)[value.property as string];
if (binaryProperty) { if (binaryProperty) {
return { return {
fileName: binaryProperty.fileName || 'unknown', fileName: binaryProperty.fileName || 'unknown',
data: binaryProperty.data, data: binaryProperty.data,
mimeType: binaryProperty.mimeType, mimeType: binaryProperty.mimeType,
}; };
} else { } else {
throw new Error(`Binary property ${value.property} does not exist on input`); throw new Error(`Binary property ${value.property} does not exist on input`);
} }
}; };
body.attachments?.push.apply(body.attachments, (attachments.attachmentsBinary as IDataObject[]).map(mapFunction) as IAttachment[]); body.attachments?.push.apply(body.attachments, (attachments.attachmentsBinary as IDataObject[]).map(mapFunction) as IAttachment[]);
} }

View file

@ -15,13 +15,15 @@ import {
helpscoutApiRequestAllItems, helpscoutApiRequestAllItems,
} from './GenericFunctions'; } from './GenericFunctions';
import { createHmac } from 'crypto'; import {
createHmac,
} from 'crypto';
export class HelpScoutTrigger implements INodeType { export class HelpScoutTrigger implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
displayName: 'HelpScout Trigger', displayName: 'HelpScout Trigger',
name: 'helpScoutTrigger', name: 'helpScoutTrigger',
icon: 'file:helpScout.png', icon: 'file:helpScout.svg',
group: ['trigger'], group: ['trigger'],
version: 1, version: 1,
description: 'Starts the workflow when HelpScout events occure.', description: 'Starts the workflow when HelpScout events occure.',
@ -125,7 +127,7 @@ export class HelpScoutTrigger implements INodeType {
if (webhook.url === webhookUrl) { if (webhook.url === webhookUrl) {
for (const event of events) { for (const event of events) {
if (!webhook.events.includes(event) if (!webhook.events.includes(event)
&& webhook.state === 'enabled') { && webhook.state === 'enabled') {
return false; return false;
} }
} }
@ -186,7 +188,7 @@ export class HelpScoutTrigger implements INodeType {
const bodyData = this.getBodyData(); const bodyData = this.getBodyData();
const headerData = this.getHeaderData() as IDataObject; const headerData = this.getHeaderData() as IDataObject;
const webhookData = this.getWorkflowStaticData('node'); const webhookData = this.getWorkflowStaticData('node');
if (headerData['x-helpscout-signature'] === undefined) { if (headerData['x-helpscout-signature'] === undefined) {
return {}; return {};
} }
//@ts-ignore //@ts-ignore

Binary file not shown.

Before

Width:  |  Height:  |  Size: 870 B

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="256px" height="310px" viewBox="0 0 256 310" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
<g>
<path d="M18.432,180.968727 L108.916364,90.4843636 C120.645818,78.9410909 127.906909,62.7432727 127.906909,45.056 C127.906909,27.5549091 120.832,11.5432727 109.474909,0 L18.9905455,90.4843636 C7.26109091,102.027636 0,118.225455 0,135.912727 C0,153.6 7.07490909,169.425455 18.432,180.968727 Z M237.568,128.093091 L147.083636,218.577455 C135.354182,230.120727 128.093091,246.318545 128.093091,264.005818 C128.093091,281.506909 135.168,297.518545 146.525091,309.061818 L237.009455,218.577455 C248.738909,207.034182 256,190.836364 256,173.149091 C256,155.461818 248.925091,139.636364 237.568,128.093091 Z M237.009455,90.6705455 C248.738909,79.1272727 256,62.9294545 256,45.2421818 C256,27.7410909 248.925091,11.7294545 237.568,0.186181818 L18.9905455,218.577455 C7.26109091,230.306909 0,246.318545 0,264.192 C0,281.693091 7.07490909,297.704727 18.432,309.248 L237.009455,90.6705455 Z" fill="#1292EE"></path>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB