mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
⚡ Small improvements to MessageBird node
This commit is contained in:
parent
95fe980163
commit
edd4c7a82f
|
@ -1,7 +1,15 @@
|
|||
import { IExecuteFunctions, IHookFunctions } from 'n8n-core';
|
||||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
* Make an API request to Message Bird
|
||||
|
@ -17,23 +25,17 @@ export async function messageBirdApiRequest(
|
|||
method: string,
|
||||
resource: string,
|
||||
body: IDataObject,
|
||||
query?: IDataObject
|
||||
query: IDataObject = {},
|
||||
): Promise<any> {
|
||||
const credentials = this.getCredentials('messageBirdApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials returned!');
|
||||
}
|
||||
|
||||
if (query === undefined) {
|
||||
query = {};
|
||||
}
|
||||
let token;
|
||||
token = token = `AccessKey ${credentials.accessKey}`;
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: token
|
||||
Authorization: `AccessKey ${credentials.accessKey}`,
|
||||
},
|
||||
method,
|
||||
qs: query,
|
||||
|
@ -51,18 +53,12 @@ export async function messageBirdApiRequest(
|
|||
|
||||
if (error.response && error.response.body && error.response.body.errors) {
|
||||
// Try to return the error prettier
|
||||
let errorMessage;
|
||||
for (let i = 0; i < error.response.body.errors.length; i++) {
|
||||
errorMessage =
|
||||
errorMessage +
|
||||
`Message Bird Error response [${error.statusCode}]: ${error.response.body.errors[i].description}`;
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
const errorMessage = error.response.body.errors.map((e: IDataObject) => e.description);
|
||||
|
||||
throw new Error(`MessageBird Error response [${error.statusCode}]: ${errorMessage.join('|')}`);
|
||||
}
|
||||
|
||||
// If that data does not exist for some reason return the actual error
|
||||
throw new Error(
|
||||
`Message Bird error ${error.response.body.errors[0].description}`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
INodeTypeDescription,
|
||||
INodeExecutionData,
|
||||
INodeType
|
||||
INodeType,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { messageBirdApiRequest } from './GenericFunctions';
|
||||
import {
|
||||
messageBirdApiRequest,
|
||||
} from './GenericFunctions';
|
||||
|
||||
export class MessageBird implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'MessageBird',
|
||||
name: 'messageBird',
|
||||
icon: 'file:messagebird.png',
|
||||
group: ['transform'],
|
||||
group: ['output'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Sending SMS',
|
||||
|
@ -50,15 +55,17 @@ export class MessageBird implements INodeType {
|
|||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['sms']
|
||||
}
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Send',
|
||||
value: 'send',
|
||||
description: 'Send text messages (SMS)'
|
||||
}
|
||||
},
|
||||
],
|
||||
default: 'send',
|
||||
description: 'The operation to perform.'
|
||||
|
@ -76,9 +83,13 @@ export class MessageBird implements INodeType {
|
|||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['send'],
|
||||
resource: ['sms']
|
||||
}
|
||||
operation: [
|
||||
'send',
|
||||
],
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The number from which to send the message'
|
||||
},
|
||||
|
@ -106,9 +117,13 @@ export class MessageBird implements INodeType {
|
|||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: ['send'],
|
||||
resource: ['sms']
|
||||
}
|
||||
operation: [
|
||||
'send',
|
||||
],
|
||||
resource: [
|
||||
'sms',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The message to be send'
|
||||
},
|
||||
|
@ -119,91 +134,87 @@ export class MessageBird implements INodeType {
|
|||
placeholder: 'Add Fields',
|
||||
default: {},
|
||||
options: [
|
||||
//date-time format
|
||||
{
|
||||
displayName: 'Created Date-time',
|
||||
name: 'createdDatetime',
|
||||
type: 'dateTime',
|
||||
placeholder: '2011-08-30T09:30:16.768-04:00',
|
||||
default: '',
|
||||
description:
|
||||
'The date and time of the creation of the message in RFC3339 format (Y-m-dTH:i:sP).'
|
||||
description: 'The date and time of the creation of the message in RFC3339 format (Y-m-dTH:i:sP).',
|
||||
},
|
||||
{
|
||||
displayName: 'Datacoding',
|
||||
name: 'datacoding',
|
||||
type: 'string',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Auto',
|
||||
value: 'auto',
|
||||
},
|
||||
{
|
||||
name: 'Plain',
|
||||
value: 'plain',
|
||||
},
|
||||
{
|
||||
name: 'Unicode',
|
||||
value: 'unicode',
|
||||
},
|
||||
],
|
||||
default: '',
|
||||
description:
|
||||
'Using unicode will limit the maximum number of characters to 70 instead of 160'
|
||||
description: 'Using unicode will limit the maximum number of characters to 70 instead of 160',
|
||||
},
|
||||
{
|
||||
displayName: 'Gateway',
|
||||
name: 'gateway',
|
||||
type: 'number',
|
||||
default: '',
|
||||
description: 'The SMS route that is used to send the message.'
|
||||
description: 'The SMS route that is used to send the message.',
|
||||
},
|
||||
{
|
||||
displayName: 'Group Ids',
|
||||
displayName: 'Group IDs',
|
||||
name: 'groupIds',
|
||||
placeholder: '1,2',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'group ids separated by commas, If provided recipients can be omitted'
|
||||
description: 'Group IDs separated by commas, If provided recipients can be omitted',
|
||||
},
|
||||
{
|
||||
displayName: 'Mclass',
|
||||
displayName: 'Message Type',
|
||||
name: 'mclass',
|
||||
type: 'options',
|
||||
placeholder: 'permissible values from 0-3',
|
||||
placeholder: 'Permissible values from 0-3',
|
||||
options: [
|
||||
{
|
||||
name: '0',
|
||||
value: '0'
|
||||
name: 'Normal',
|
||||
value: 0
|
||||
},
|
||||
{
|
||||
name: '1',
|
||||
value: '1'
|
||||
name: 'Flash',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
name: '2',
|
||||
value: '2'
|
||||
},
|
||||
{
|
||||
name: '3',
|
||||
value: '3'
|
||||
}
|
||||
],
|
||||
default: '',
|
||||
description:
|
||||
'Indicated the message type. 1 is a normal message, 0 is a flash message.'
|
||||
default: 1,
|
||||
description: 'Indicated the message type. 1 is a normal message, 0 is a flash message.',
|
||||
},
|
||||
{
|
||||
displayName: 'Reference',
|
||||
name: 'reference',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'A client reference.'
|
||||
description: 'A client reference.',
|
||||
},
|
||||
{
|
||||
displayName: 'Report Url',
|
||||
name: 'reportUrl',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'The status report URL to be used on a per-message basis.<br /> Reference is required for a status report webhook to be sent.'
|
||||
description: 'The status report URL to be used on a per-message basis.<br /> Reference is required for a status report webhook to be sent.',
|
||||
},
|
||||
//date-time format
|
||||
{
|
||||
displayName: 'Scheduled Date-time',
|
||||
name: 'scheduledDatetime',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
placeholder: '2011-08-30T09:30:16.768-04:00',
|
||||
description:
|
||||
'The scheduled date and time of the message in RFC3339 format (Y-m-dTH:i:sP).'
|
||||
description: 'The scheduled date and time of the message in RFC3339 format (Y-m-dTH:i:sP).',
|
||||
},
|
||||
{
|
||||
displayName: 'Type',
|
||||
|
@ -211,44 +222,41 @@ export class MessageBird implements INodeType {
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'sms',
|
||||
name: 'SMS',
|
||||
value: 'sms'
|
||||
},
|
||||
{
|
||||
name: 'binary',
|
||||
name: 'Binary',
|
||||
value: 'binary'
|
||||
},
|
||||
{
|
||||
name: 'flash',
|
||||
name: 'Flash',
|
||||
value: 'flash'
|
||||
}
|
||||
],
|
||||
default: '',
|
||||
description:
|
||||
'The type of message.<br /> Values can be: sms, binary, or flash.'
|
||||
description: 'The type of message.<br /> Values can be: sms, binary, or flash.'
|
||||
},
|
||||
//hash
|
||||
{
|
||||
displayName: 'Type Details',
|
||||
name: 'typeDetails',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description:
|
||||
'A hash with extra information.<br /> Is only used when a binary message is sent.'
|
||||
description: 'A hash with extra information.<br /> Is only used when a binary message is sent.',
|
||||
},
|
||||
{
|
||||
displayName: 'Validity',
|
||||
name: 'validity',
|
||||
type: 'number',
|
||||
default: '',
|
||||
default: 1,
|
||||
typeOptions: {
|
||||
minValue: 1
|
||||
minValue: 1,
|
||||
},
|
||||
description: 'The amount of seconds that the message is valid.'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
description: 'The amount of seconds that the message is valid.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
|
|
Loading…
Reference in a new issue