Add attachment types to Signl4 Node (#1388)

* SIGNL4: Attachment Support

Attachment support added to SIGNL4.

* SI'GNL4: Attachment Support

Attachment support added for SIGNL4.

* Update GenericFunctions.ts

* Update GenericFunctions.ts

* Update GenericFunctions.ts

* Update GenericFunctions.ts

*  Improvements to #1356

Co-authored-by: rons4 <ron@signl4.com>
This commit is contained in:
Jan 2021-01-31 20:08:38 +01:00 committed by GitHub
commit 5549550928
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 40 deletions

View file

@ -14,11 +14,20 @@ import {
* Make an API request to SIGNL4
*
* @param {IHookFunctions | IExecuteFunctions} this
* @param {object} message
* @param {string} method
* @param {string} contentType
* @param {string} body
* @param {object} query
* @param {string} teamSecret
* @param {object} options
* @returns {Promise<any>}
*
*/
export async function SIGNL4ApiRequest(this: IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
export async function SIGNL4ApiRequest(this: IExecuteFunctions, method: string, body: string, query: IDataObject = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('signl4Api');
const teamSecret = credentials?.teamSecret as string;
let options: OptionsWithUri = {
headers: {
@ -27,7 +36,7 @@ export async function SIGNL4ApiRequest(this: IExecuteFunctions, method: string,
method,
body,
qs: query,
uri: uri || ``,
uri: `https://connect.signl4.com/webhook/${teamSecret}`,
json: true,
};

View file

@ -1,7 +1,7 @@
{
"node": "n8n-nodes-base.signl4",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"nodeVersion": "1.1",
"codexVersion": "1.1",
"categories": [
"Communication",
"Development"

View file

@ -270,14 +270,12 @@ export class Signl4 implements INodeType {
message,
};
if (additionalFields.alertingScenario) {
data['X-S4-AlertingScenario'] = additionalFields.alertingScenario as string;
if (additionalFields.title) {
data.title = additionalFields.title as string;
}
if (additionalFields.externalId) {
data['X-S4-ExternalID'] = additionalFields.externalId as string;
}
if (additionalFields.filtering) {
data['X-S4-Filtering'] = (additionalFields.filtering as boolean).toString();
if (additionalFields.service) {
data.service = additionalFields.service as string;
}
if (additionalFields.locationFieldsUi) {
const locationUi = (additionalFields.locationFieldsUi as IDataObject).locationFieldsValues as IDataObject;
@ -285,16 +283,25 @@ export class Signl4 implements INodeType {
data['X-S4-Location'] = `${locationUi.latitude},${locationUi.longitude}`;
}
}
if (additionalFields.service) {
data['X-S4-Service'] = additionalFields.service as string;
if (additionalFields.alertingScenario) {
data['X-S4-AlertingScenario'] = additionalFields.alertingScenario as string;
}
if (additionalFields.filtering) {
data['X-S4-Filtering'] = (additionalFields.filtering as boolean).toString();
}
if (additionalFields.externalId) {
data['X-S4-ExternalID'] = additionalFields.externalId as string;
}
data['X-S4-Status'] = 'new';
if (additionalFields.title) {
data['title'] = additionalFields.title as string;
}
data['X-S4-SourceSystem'] = 'n8n';
// Attachments
const attachments = additionalFields.attachmentsUi as IDataObject;
if (attachments) {
if (attachments.attachmentsBinary && items[i].binary) {
@ -304,14 +311,14 @@ export class Signl4 implements INodeType {
if (binaryProperty) {
const supportedFileExtension = ['png', 'jpg', 'txt'];
const supportedFileExtension = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'mp3', 'wav'];
if (!supportedFileExtension.includes(binaryProperty.fileExtension as string)) {
throw new Error(`Invalid extension, just ${supportedFileExtension.join(',')} are supported}`);
}
data['file'] = {
data.attachment = {
value: Buffer.from(binaryProperty.data, BINARY_ENCODING),
options: {
filename: binaryProperty.fileName,
@ -325,18 +332,14 @@ export class Signl4 implements INodeType {
}
}
const credentials = this.getCredentials('signl4Api');
const endpoint = `https://connect.signl4.com/webhook/${credentials?.teamSecret}`;
responseData = await SIGNL4ApiRequest.call(
this,
'POST',
'',
data,
{},
endpoint,
{},
{
formData: data,
},
);
}
// Resolve alert
@ -348,27 +351,25 @@ export class Signl4 implements INodeType {
data['X-S4-Status'] = 'resolved';
const credentials = this.getCredentials('signl4Api');
const endpoint = `https://connect.signl4.com/webhook/${credentials?.teamSecret}`;
data['X-S4-SourceSystem'] = 'n8n';
responseData = await SIGNL4ApiRequest.call(
this,
'POST',
'',
data,
{},
endpoint,
{},
{
formData: data,
},
);
}
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}