mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
✨ 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:
commit
5549550928
|
@ -8,17 +8,26 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
OptionsWithUri,
|
OptionsWithUri,
|
||||||
} from 'request';
|
} from 'request';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an API request to SIGNL4
|
* Make an API request to SIGNL4
|
||||||
*
|
*
|
||||||
* @param {IHookFunctions | IExecuteFunctions} this
|
* @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>}
|
* @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 = {
|
let options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -27,7 +36,7 @@ export async function SIGNL4ApiRequest(this: IExecuteFunctions, method: string,
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: uri || ``,
|
uri: `https://connect.signl4.com/webhook/${teamSecret}`,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"node": "n8n-nodes-base.signl4",
|
"node": "n8n-nodes-base.signl4",
|
||||||
"nodeVersion": "1.0",
|
"nodeVersion": "1.1",
|
||||||
"codexVersion": "1.0",
|
"codexVersion": "1.1",
|
||||||
"categories": [
|
"categories": [
|
||||||
"Communication",
|
"Communication",
|
||||||
"Development"
|
"Development"
|
||||||
|
|
|
@ -264,20 +264,18 @@ export class Signl4 implements INodeType {
|
||||||
// Send alert
|
// Send alert
|
||||||
if (operation === 'send') {
|
if (operation === 'send') {
|
||||||
const message = this.getNodeParameter('message', i) as string;
|
const message = this.getNodeParameter('message', i) as string;
|
||||||
const additionalFields = this.getNodeParameter('additionalFields',i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
||||||
const data: IDataObject = {
|
const data: IDataObject = {
|
||||||
message,
|
message,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (additionalFields.alertingScenario) {
|
if (additionalFields.title) {
|
||||||
data['X-S4-AlertingScenario'] = additionalFields.alertingScenario as string;
|
data.title = additionalFields.title as string;
|
||||||
}
|
}
|
||||||
if (additionalFields.externalId) {
|
|
||||||
data['X-S4-ExternalID'] = additionalFields.externalId as string;
|
if (additionalFields.service) {
|
||||||
}
|
data.service = additionalFields.service as string;
|
||||||
if (additionalFields.filtering) {
|
|
||||||
data['X-S4-Filtering'] = (additionalFields.filtering as boolean).toString();
|
|
||||||
}
|
}
|
||||||
if (additionalFields.locationFieldsUi) {
|
if (additionalFields.locationFieldsUi) {
|
||||||
const locationUi = (additionalFields.locationFieldsUi as IDataObject).locationFieldsValues as IDataObject;
|
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}`;
|
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';
|
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;
|
const attachments = additionalFields.attachmentsUi as IDataObject;
|
||||||
|
|
||||||
if (attachments) {
|
if (attachments) {
|
||||||
if (attachments.attachmentsBinary && items[i].binary) {
|
if (attachments.attachmentsBinary && items[i].binary) {
|
||||||
|
|
||||||
|
@ -304,14 +311,14 @@ export class Signl4 implements INodeType {
|
||||||
|
|
||||||
if (binaryProperty) {
|
if (binaryProperty) {
|
||||||
|
|
||||||
const supportedFileExtension = ['png', 'jpg', 'txt'];
|
const supportedFileExtension = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'mp3', 'wav'];
|
||||||
|
|
||||||
if (!supportedFileExtension.includes(binaryProperty.fileExtension as string)) {
|
if (!supportedFileExtension.includes(binaryProperty.fileExtension as string)) {
|
||||||
|
|
||||||
throw new Error(`Invalid extension, just ${supportedFileExtension.join(',')} are supported}`);
|
throw new Error(`Invalid extension, just ${supportedFileExtension.join(',')} are supported}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
data['file'] = {
|
data.attachment = {
|
||||||
value: Buffer.from(binaryProperty.data, BINARY_ENCODING),
|
value: Buffer.from(binaryProperty.data, BINARY_ENCODING),
|
||||||
options: {
|
options: {
|
||||||
filename: binaryProperty.fileName,
|
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(
|
responseData = await SIGNL4ApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'POST',
|
'POST',
|
||||||
'',
|
'',
|
||||||
data,
|
|
||||||
{},
|
|
||||||
endpoint,
|
|
||||||
{},
|
{},
|
||||||
|
{
|
||||||
|
formData: data,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Resolve alert
|
// Resolve alert
|
||||||
|
@ -348,27 +351,25 @@ export class Signl4 implements INodeType {
|
||||||
|
|
||||||
data['X-S4-Status'] = 'resolved';
|
data['X-S4-Status'] = 'resolved';
|
||||||
|
|
||||||
const credentials = this.getCredentials('signl4Api');
|
data['X-S4-SourceSystem'] = 'n8n';
|
||||||
|
|
||||||
const endpoint = `https://connect.signl4.com/webhook/${credentials?.teamSecret}`;
|
|
||||||
|
|
||||||
responseData = await SIGNL4ApiRequest.call(
|
responseData = await SIGNL4ApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'POST',
|
'POST',
|
||||||
'',
|
'',
|
||||||
data,
|
|
||||||
{},
|
|
||||||
endpoint,
|
|
||||||
{},
|
{},
|
||||||
|
{
|
||||||
|
formData: data,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (Array.isArray(responseData)) {
|
if (Array.isArray(responseData)) {
|
||||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
} else if (responseData !== undefined) {
|
} else if (responseData !== undefined) {
|
||||||
returnData.push(responseData as IDataObject);
|
returnData.push(responseData as IDataObject);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return [this.helpers.returnJsonArray(returnData)];
|
return [this.helpers.returnJsonArray(returnData)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue