2019-12-13 03:29:33 -08:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeOperationError,
|
2019-12-13 03:29:33 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { msg91ApiRequest } from './GenericFunctions';
|
2019-12-13 03:29:33 -08:00
|
|
|
|
|
|
|
export class Msg91 implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
2020-07-24 03:56:41 -07:00
|
|
|
displayName: 'MSG91',
|
2019-12-13 03:29:33 -08:00
|
|
|
name: 'msg91',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2019-12-13 03:29:33 -08:00
|
|
|
icon: 'file:msg91.png',
|
|
|
|
group: ['transform'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Sends transactional SMS via MSG91',
|
2019-12-13 03:29:33 -08:00
|
|
|
defaults: {
|
feat(editor): Node creator actions (#4696)
* WIP: Node Actions List UI
* WIP: Recommended Actions and preseting of fields
* WIP: Resource category
* :art: Moved actions categorisation to the server
* :label: Add missing INodeAction type
* :sparkles: Improve SSR categorisation, fix adding of mixed actions
* :recycle: Refactor CategorizedItems to composition api, style fixes
* WIP: Adding multiple nodes
* :recycle: Refactor rest of the NodeCreator component to composition API, conver globalLinkActions to composable
* :sparkles: Allow actions dragging, fix search and refactor passing of actions to categorized items
* :lipstick: Fix node actions title
* Migrate to the pinia store, add posthog feature and various fixes
* :bug: Fix filtering of trigger actions when not merged
* fix: N8N-5439 — Do not use simple node item when at NodeHelperPanel root
* :bug: Design review fixes
* :bug: Fix disabling of merged actions
* Fix trigger root filtering
* :sparkles: Allow for custom node actions parser, introduce hubspot parser
* :bug: Fix initial node params validation, fix position of second added node
* :bug: Introduce operations category, removed canvas node names overrride, fix API actions display and prevent dragging of action nodes
* :sparkles: Prevent NDV auto-open feature flag
* :bug: Inject recommened action for trigger nodes without actions
* Refactored NodeCreatorNode to Storybook, change filtering of merged nodes for the trigger helper panel, minor fixes
* Improve rendering of app nodes and animation
* Cleanup, any only enable accordion transition on triggerhelperpanel
* Hide node creator scrollbars in Firefox
* Minor styles fixes
* Do not copy the array in rendering method
* Removed unused props
* Fix memory leak
* Fix categorisation of regular nodes with a single resource
* Implement telemetry calls for node actions
* Move categorization to FE
* Fix client side actions categorisation
* Skip custom action show
* Only load tooltip for NodeIcon if necessary
* Fix lodash startCase import
* Remove lodash.startcase
* Cleanup
* Fix node creator autofocus on "tab"
* Prevent posthog getFeatureFlag from crashing
* Debugging preview env search issues
* Remove logs
* Make sure the pre-filled params are update not overwritten
* Get rid of transition in itemiterator
* WIP: Rough version of NodeActions keyboard navigation, replace nodeCreator composable with Pinia store module
* Rewrite to add support for ActionItem to ItemIterator and make CategorizedItems accept items props
* Fix category item counter & cleanup
* Add APIHint to actions search no-result, clean up NodeCreatorNode
* Improve node actions no results message
* Remove logging, fix filtering of recommended placeholder category
* Remove unused NodeActions component and node merging feature falg
* Do not show regular nodes without actions
* Make sure to add manual trigger when adding http node via actions hint
* Fixed api hint footer line height
* Prevent pointer-events od NodeIcon img and remove "this" from template
* Address PR points
* Fix e2e specs
* Make sure canvas ia loaded
* Make sure canvas ia loaded before opening nodeCreator in e2e spec
* Fix flaky workflows tags e2e getter
* Imrpove node creator click outside UX, add manual node to regular nodes added from trigger panel
* Add manual trigger node if dragging regular from trigger panel
2022-12-09 01:56:36 -08:00
|
|
|
name: 'MSG91',
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'msg91Api',
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2019-12-13 03:29:33 -08:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2019-12-13 03:29:33 -08:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'SMS',
|
|
|
|
value: 'sms',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'sms',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2019-12-13 03:29:33 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
resource: ['sms'],
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Send',
|
|
|
|
value: 'send',
|
|
|
|
description: 'Send SMS',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Send an SMS',
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'send',
|
|
|
|
},
|
|
|
|
{
|
2020-07-14 03:39:42 -07:00
|
|
|
displayName: 'Sender ID',
|
2019-12-20 14:35:00 -08:00
|
|
|
name: 'from',
|
2019-12-13 03:29:33 -08:00
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2019-12-20 14:35:00 -08:00
|
|
|
placeholder: '4155238886',
|
2019-12-13 03:29:33 -08:00
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms'],
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
},
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The number from which to send the message',
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'To',
|
2019-12-20 14:35:00 -08:00
|
|
|
name: 'to',
|
2019-12-13 03:29:33 -08:00
|
|
|
type: 'string',
|
|
|
|
default: '',
|
2019-12-20 14:35:00 -08:00
|
|
|
placeholder: '+14155238886',
|
2019-12-13 03:29:33 -08:00
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms'],
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
},
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The number, with coutry code, to which to send the message',
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Message',
|
|
|
|
name: 'message',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['send'],
|
|
|
|
resource: ['sms'],
|
2019-12-13 03:29:33 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
description: 'The message to send',
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2019-12-13 03:29:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
|
|
|
|
let operation: string;
|
|
|
|
let resource: string;
|
|
|
|
|
|
|
|
// For Post
|
|
|
|
let body: IDataObject;
|
|
|
|
// For Query string
|
|
|
|
let qs: IDataObject;
|
|
|
|
|
|
|
|
let requestMethod: string;
|
|
|
|
let endpoint: string;
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
endpoint = '';
|
|
|
|
body = {};
|
|
|
|
qs = {};
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
resource = this.getNodeParameter('resource', i);
|
|
|
|
operation = this.getNodeParameter('operation', i);
|
2019-12-13 03:29:33 -08:00
|
|
|
|
|
|
|
if (resource === 'sms') {
|
|
|
|
if (operation === 'send') {
|
|
|
|
// ----------------------------------
|
|
|
|
// sms:send
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'GET';
|
2019-12-20 14:35:00 -08:00
|
|
|
endpoint = '/sendhttp.php';
|
2019-12-13 03:29:33 -08:00
|
|
|
|
|
|
|
qs.route = 4;
|
|
|
|
qs.country = 0;
|
2019-12-20 14:35:00 -08:00
|
|
|
qs.sender = this.getNodeParameter('from', i) as string;
|
|
|
|
qs.mobiles = this.getNodeParameter('to', i) as string;
|
2019-12-13 03:29:33 -08:00
|
|
|
qs.message = this.getNodeParameter('message', i) as string;
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2019-12-13 03:29:33 -08:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`, {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2019-12-13 03:29:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const responseData = await msg91ApiRequest.call(this, requestMethod, endpoint, body, qs);
|
|
|
|
|
2019-12-20 14:35:00 -08:00
|
|
|
returnData.push({ requestId: responseData });
|
2019-12-13 03:29:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|