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