2024-08-29 06:55:53 -07:00
|
|
|
import {
|
|
|
|
NodeConnectionType,
|
|
|
|
type IDataObject,
|
|
|
|
type IExecuteFunctions,
|
|
|
|
type INodeExecutionData,
|
|
|
|
type INodeType,
|
|
|
|
type INodeTypeDescription,
|
2023-01-27 03:22:44 -08:00
|
|
|
} from 'n8n-workflow';
|
2021-09-05 03:25:28 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { sms77ApiRequest } from './GenericFunctions';
|
2020-04-29 07:51:49 -07:00
|
|
|
|
|
|
|
export class Sms77 implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
2023-09-19 01:26:53 -07:00
|
|
|
displayName: 'seven',
|
2020-04-29 07:51:49 -07:00
|
|
|
name: 'sms77',
|
2023-09-19 01:26:53 -07:00
|
|
|
icon: 'file:seven.svg',
|
2020-04-29 07:51:49 -07:00
|
|
|
group: ['transform'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2021-09-05 03:25:28 -07:00
|
|
|
description: 'Send SMS and make text-to-speech calls',
|
2020-04-29 07:51:49 -07:00
|
|
|
defaults: {
|
2023-09-19 01:26:53 -07:00
|
|
|
name: 'seven',
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
2024-08-29 06:55:53 -07:00
|
|
|
inputs: [NodeConnectionType.Main],
|
|
|
|
outputs: [NodeConnectionType.Main],
|
2020-04-29 07:51:49 -07:00
|
|
|
credentials: [
|
|
|
|
{
|
2020-05-02 04:09:16 -07:00
|
|
|
name: 'sms77Api',
|
2020-04-29 07:51:49 -07:00
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-04-29 07:51:49 -07:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-04-29 07:51:49 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'SMS',
|
|
|
|
value: 'sms',
|
|
|
|
},
|
2021-09-05 03:25:28 -07:00
|
|
|
{
|
|
|
|
name: 'Voice Call',
|
|
|
|
value: 'voice',
|
|
|
|
},
|
2020-04-29 07:51:49 -07:00
|
|
|
],
|
|
|
|
default: 'sms',
|
|
|
|
},
|
2021-09-05 03:25:28 -07:00
|
|
|
|
|
|
|
// operations
|
2020-04-29 07:51:49 -07:00
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-04-29 07:51:49 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
resource: ['sms'],
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Send',
|
|
|
|
value: 'send',
|
|
|
|
description: 'Send SMS',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Send an SMS',
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'send',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2021-09-05 03:25:28 -07:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
resource: ['voice'],
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Send',
|
|
|
|
value: 'send',
|
|
|
|
description: 'Converts text to voice and calls a given number',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Convert text to voice',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'send',
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'From',
|
|
|
|
name: 'from',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
placeholder: '+4901234567890',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms'],
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'The caller ID displayed in the receivers display. Max 16 numeric or 11 alphanumeric characters.',
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'To',
|
|
|
|
name: 'to',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2021-09-05 03:25:28 -07:00
|
|
|
placeholder: '+49876543210, MyGroup',
|
2020-04-29 07:51:49 -07:00
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms', 'voice'],
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
2023-09-19 01:26:53 -07:00
|
|
|
'The number of your recipient(s) separated by comma. Can be regular numbers or contact/groups from seven.',
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Message',
|
|
|
|
name: 'message',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms', 'voice'],
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
},
|
2021-09-05 03:25:28 -07:00
|
|
|
description: 'The message to send. Max. 1520 characters',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Options',
|
|
|
|
name: 'options',
|
|
|
|
type: 'collection',
|
|
|
|
placeholder: 'Add Opton',
|
|
|
|
default: {},
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms'],
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
displayName: 'Debug',
|
|
|
|
name: 'debug',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
description: 'Whether the API returns fake responses like in a sandbox',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Delay',
|
|
|
|
name: 'delay',
|
|
|
|
type: 'dateTime',
|
|
|
|
default: '',
|
|
|
|
description: 'Pick a date for time delayed dispatch',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Foreign ID',
|
|
|
|
name: 'foreign_id',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
placeholder: 'MyCustomForeignID',
|
|
|
|
description: 'Custom foreign ID returned in DLR callbacks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Flash',
|
|
|
|
name: 'flash',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
|
2022-08-17 08:50:24 -07:00
|
|
|
description: "Send as flash message being displayed directly the receiver's display",
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Label',
|
|
|
|
name: 'label',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
placeholder: 'MyCustomLabel',
|
|
|
|
description: 'Custom label used to group analytics',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'No Reload',
|
|
|
|
name: 'no_reload',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
description: 'Whether to disable reload lock to allow sending duplicate messages',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Performance Tracking',
|
|
|
|
name: 'performance_tracking',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Whether to enable performance tracking for URLs found in the message text',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'TTL',
|
|
|
|
name: 'ttl',
|
|
|
|
type: 'number',
|
|
|
|
default: 2880,
|
|
|
|
typeOptions: {
|
|
|
|
minValue: 1,
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Custom time to live specifying the validity period of a message in minutes',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Options',
|
|
|
|
name: 'options',
|
|
|
|
type: 'collection',
|
|
|
|
placeholder: 'Add Opton',
|
|
|
|
default: {},
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['voice'],
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
displayName: 'Debug',
|
|
|
|
name: 'debug',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
description: 'Whether the API returns fake responses like in a sandbox',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'From',
|
|
|
|
name: 'from',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
placeholder: '+4901234567890',
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'The caller ID. Please use only verified sender IDs, one of your virtual inbound numbers or one of our shared virtual numbers.',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'XML',
|
|
|
|
name: 'xml',
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
description: 'Whether the text is in XML format',
|
2021-09-05 03:25:28 -07:00
|
|
|
},
|
|
|
|
],
|
2020-04-29 07:51:49 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
|
|
|
|
for (let i = 0; i < this.getInputData().length; i++) {
|
|
|
|
const resource = this.getNodeParameter('resource', i);
|
|
|
|
const operation = this.getNodeParameter('operation', i);
|
2021-09-05 03:25:28 -07:00
|
|
|
let responseData;
|
|
|
|
try {
|
|
|
|
if (resource === 'sms') {
|
|
|
|
if (operation === 'send') {
|
|
|
|
const from = this.getNodeParameter('from', i) as string;
|
|
|
|
const to = this.getNodeParameter('to', i) as string;
|
|
|
|
const text = this.getNodeParameter('message', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-09-05 03:25:28 -07:00
|
|
|
const body = {
|
|
|
|
from,
|
|
|
|
to,
|
|
|
|
text,
|
|
|
|
...options,
|
|
|
|
};
|
|
|
|
responseData = await sms77ApiRequest.call(this, 'POST', '/sms', body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource === 'voice') {
|
|
|
|
if (operation === 'send') {
|
|
|
|
const to = this.getNodeParameter('to', i) as string;
|
|
|
|
const text = this.getNodeParameter('message', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-09-05 03:25:28 -07:00
|
|
|
const body = {
|
|
|
|
to,
|
|
|
|
text,
|
|
|
|
...options,
|
|
|
|
};
|
|
|
|
responseData = await sms77ApiRequest.call(this, 'POST', '/voice', body);
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 07:51:49 -07:00
|
|
|
|
2021-09-05 03:25:28 -07:00
|
|
|
if (Array.isArray(responseData)) {
|
|
|
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
|
|
|
} else if (responseData !== undefined) {
|
|
|
|
returnData.push(responseData as IDataObject);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2024-08-30 00:59:30 -07:00
|
|
|
if (this.continueOnFail()) {
|
2021-09-05 03:25:28 -07:00
|
|
|
returnData.push({ error: error.message });
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
2020-04-29 07:51:49 -07:00
|
|
|
}
|
2021-09-05 03:25:28 -07:00
|
|
|
|
2020-04-29 07:51:49 -07:00
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|