mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
✨ Update operation selection on Twilio-Node
This commit is contained in:
parent
c6a55113e3
commit
1851ce0dbb
|
@ -12,8 +12,6 @@ import {
|
||||||
twilioApiRequest,
|
twilioApiRequest,
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
|
|
||||||
import { OptionsWithUri } from 'request';
|
|
||||||
|
|
||||||
export class Twilio implements INodeType {
|
export class Twilio implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Twilio',
|
displayName: 'Twilio',
|
||||||
|
@ -21,6 +19,7 @@ export class Twilio implements INodeType {
|
||||||
icon: 'file:twilio.png',
|
icon: 'file:twilio.png',
|
||||||
group: ['transform'],
|
group: ['transform'],
|
||||||
version: 1,
|
version: 1,
|
||||||
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
description: 'Send SMS and WhatsApp messages or make phone calls',
|
description: 'Send SMS and WhatsApp messages or make phone calls',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: 'Twilio',
|
name: 'Twilio',
|
||||||
|
@ -36,23 +35,48 @@ export class Twilio implements INodeType {
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Resource',
|
||||||
name: 'operation',
|
name: 'resource',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Send Message',
|
name: 'SMS',
|
||||||
value: 'sendMessage',
|
value: 'sms',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'sms',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'sms',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Send',
|
||||||
|
value: 'send',
|
||||||
description: 'Send SMS/MMS/WhatsApp message',
|
description: 'Send SMS/MMS/WhatsApp message',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'sendMessage',
|
default: 'send',
|
||||||
description: 'The operation to perform.',
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// sendMessage
|
// sms
|
||||||
|
// ----------------------------------
|
||||||
|
|
||||||
|
// ----------------------------------
|
||||||
|
// sms:send
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
displayName: 'From',
|
displayName: 'From',
|
||||||
|
@ -64,7 +88,10 @@ export class Twilio implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'sendMessage',
|
'send',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'sms',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -80,7 +107,10 @@ export class Twilio implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'sendMessage',
|
'send',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'sms',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -94,7 +124,10 @@ export class Twilio implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'sendMessage',
|
'send',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'sms',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -109,7 +142,10 @@ export class Twilio implements INodeType {
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
operation: [
|
operation: [
|
||||||
'sendMessage',
|
'send',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'sms',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -123,7 +159,8 @@ export class Twilio implements INodeType {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
let operation: string;
|
||||||
|
let resource: string;
|
||||||
|
|
||||||
// For Post
|
// For Post
|
||||||
let body: IDataObject;
|
let body: IDataObject;
|
||||||
|
@ -139,9 +176,13 @@ export class Twilio implements INodeType {
|
||||||
body = {};
|
body = {};
|
||||||
qs = {};
|
qs = {};
|
||||||
|
|
||||||
if (operation === 'sendMessage') {
|
resource = this.getNodeParameter('resource', i) as string;
|
||||||
|
operation = this.getNodeParameter('operation', i) as string;
|
||||||
|
|
||||||
|
if (resource === 'sms') {
|
||||||
|
if (operation === 'send') {
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
// sendMessage
|
// sms:send
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
|
||||||
requestMethod = 'POST';
|
requestMethod = 'POST';
|
||||||
|
@ -160,6 +201,9 @@ export class Twilio implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`The operation "${operation}" is not known!`);
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`The resource "${resource}" is not known!`);
|
||||||
|
}
|
||||||
|
|
||||||
const responseData = await twilioApiRequest.call(this, requestMethod, endpoint, body, qs);
|
const responseData = await twilioApiRequest.call(this, requestMethod, endpoint, body, qs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue