n8n/packages/nodes-base/nodes/Msg91/Msg91.node.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

173 lines
3.7 KiB
TypeScript
Raw Normal View History

import type {
IExecuteFunctions,
2019-12-13 03:29:33 -08:00
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
IHttpRequestMethods,
2019-12-13 03:29:33 -08:00
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
2019-12-13 03:29:33 -08:00
import { msg91ApiRequest } from './GenericFunctions';
2019-12-13 03:29:33 -08:00
export class Msg91 implements INodeType {
description: INodeTypeDescription = {
displayName: 'MSG91',
2019-12-13 03:29:33 -08:00
name: 'msg91',
icon: { light: 'file:msg91.svg', dark: 'file:msg91.dark.svg' },
2019-12-13 03:29:33 -08:00
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
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',
refactor: Apply more nodelinting rules (#3324) * :pencil2: Alphabetize lint rules * :fire: Remove duplicates * :zap: Update `lintfix` script * :shirt: Apply `node-param-operation-without-no-data-expression` (#3329) * :shirt: Apply `node-param-operation-without-no-data-expression` * :shirt: Add exceptions * :shirt: Apply `node-param-description-weak` (#3328) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-value-duplicate` (#3331) * :shirt: Apply `node-param-description-miscased-json` (#3337) * :shirt: Apply `node-param-display-name-excess-inner-whitespace` (#3335) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-type-options-missing-from-limit` (#3336) * Rule workig as intended * :pencil2: Uncomment rules Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-name-duplicate` (#3338) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-wrong-for-simplify` (#3334) * :zap: fix * :zap: exceptions * :zap: changed rule ignoring from file to line * :shirt: Apply `node-param-resource-without-no-data-expression` (#3339) * :shirt: Apply `node-param-display-name-untrimmed` (#3341) * :shirt: Apply `node-param-display-name-miscased-id` (#3340) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-resource-with-plural-option` (#3342) * :shirt: Apply `node-param-description-wrong-for-upsert` (#3333) * :zap: fix * :zap: replaced record with contact in description * :zap: fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-description-identical-to-name` (#3343) * :shirt: Apply `node-param-option-name-containing-star` (#3347) * :shirt: Apply `node-param-display-name-wrong-for-update-fields` (#3348) * :shirt: Apply `node-param-option-name-wrong-for-get-all` (#3345) * :zap: fix * :zap: exceptions * :shirt: Apply node-param-display-name-wrong-for-simplify (#3344) * Rule working as intended * Uncomented other rules * :shirt: Undo and add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :zap: Alphabetize lint rules * :zap: Restore `lintfix` script Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com>
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',
refactor: Apply more nodelinting rules (#3324) * :pencil2: Alphabetize lint rules * :fire: Remove duplicates * :zap: Update `lintfix` script * :shirt: Apply `node-param-operation-without-no-data-expression` (#3329) * :shirt: Apply `node-param-operation-without-no-data-expression` * :shirt: Add exceptions * :shirt: Apply `node-param-description-weak` (#3328) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-value-duplicate` (#3331) * :shirt: Apply `node-param-description-miscased-json` (#3337) * :shirt: Apply `node-param-display-name-excess-inner-whitespace` (#3335) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-type-options-missing-from-limit` (#3336) * Rule workig as intended * :pencil2: Uncomment rules Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-name-duplicate` (#3338) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-wrong-for-simplify` (#3334) * :zap: fix * :zap: exceptions * :zap: changed rule ignoring from file to line * :shirt: Apply `node-param-resource-without-no-data-expression` (#3339) * :shirt: Apply `node-param-display-name-untrimmed` (#3341) * :shirt: Apply `node-param-display-name-miscased-id` (#3340) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-resource-with-plural-option` (#3342) * :shirt: Apply `node-param-description-wrong-for-upsert` (#3333) * :zap: fix * :zap: replaced record with contact in description * :zap: fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-description-identical-to-name` (#3343) * :shirt: Apply `node-param-option-name-containing-star` (#3347) * :shirt: Apply `node-param-display-name-wrong-for-update-fields` (#3348) * :shirt: Apply `node-param-option-name-wrong-for-get-all` (#3345) * :zap: fix * :zap: exceptions * :shirt: Apply node-param-display-name-wrong-for-simplify (#3344) * Rule working as intended * Uncomented other rules * :shirt: Undo and add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :zap: Alphabetize lint rules * :zap: Restore `lintfix` script Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com>
2022-05-20 14:47:24 -07:00
noDataExpression: true,
2019-12-13 03:29:33 -08:00
displayOptions: {
show: {
resource: ['sms'],
2019-12-13 03:29:33 -08:00
},
},
options: [
{
name: 'Send',
value: 'send',
description: 'Send SMS',
action: 'Send an SMS',
2019-12-13 03:29:33 -08:00
},
],
default: 'send',
},
{
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: {
operation: ['send'],
resource: ['sms'],
2019-12-13 03:29:33 -08: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: {
operation: ['send'],
resource: ['sms'],
2019-12-13 03:29:33 -08: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: {
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: IHttpRequestMethods;
2019-12-13 03:29:33 -08:00
let endpoint: string;
for (let i = 0; i < items.length; i++) {
endpoint = '';
body = {};
qs = {};
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 {
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not known!`,
{ itemIndex: i },
);
2019-12-13 03:29:33 -08:00
}
} else {
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)];
}
}