mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Small changes to Sms77 node
This commit is contained in:
parent
58d0cda0bf
commit
ae853ce602
|
@ -3,9 +3,9 @@ import {
|
||||||
NodePropertyTypes,
|
NodePropertyTypes,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export class Sms77 implements ICredentialType {
|
export class Sms77Api implements ICredentialType {
|
||||||
name = 'Sms77';
|
name = 'sms77Api';
|
||||||
displayName = 'Sms77';
|
displayName = 'Sms77 API';
|
||||||
properties = [
|
properties = [
|
||||||
{
|
{
|
||||||
displayName: 'API Key',
|
displayName: 'API Key',
|
|
@ -1,5 +1,12 @@
|
||||||
import {IExecuteFunctions, IHookFunctions,} from 'n8n-core';
|
import {
|
||||||
import {IDataObject,} from 'n8n-workflow';
|
IExecuteFunctions,
|
||||||
|
IHookFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
ICredentialDataDecryptedObject,
|
||||||
|
IDataObject,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an API request to MSG91
|
* Make an API request to MSG91
|
||||||
|
@ -12,7 +19,33 @@ import {IDataObject,} from 'n8n-workflow';
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
export async function sms77ApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, form: IDataObject, qs?: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
export async function sms77ApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, form: IDataObject, qs?: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
||||||
const setPayload = (o?: IDataObject) => {
|
const credentials = this.getCredentials('sms77Api');
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('GET' === method) {
|
||||||
|
qs = setPayload(credentials, qs);
|
||||||
|
} else {
|
||||||
|
form = setPayload(credentials, form);
|
||||||
|
}
|
||||||
|
const response = await this.helpers.request({
|
||||||
|
form,
|
||||||
|
json: true,
|
||||||
|
method,
|
||||||
|
qs,
|
||||||
|
uri: `https://gateway.sms77.io/api/${endpoint}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
if ('100' !== response.success) {
|
||||||
|
throw new Error('Invalid sms77 credentials or API error!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function setPayload(credentials: ICredentialDataDecryptedObject, o?: IDataObject) {
|
||||||
if (!o) {
|
if (!o) {
|
||||||
o = {};
|
o = {};
|
||||||
}
|
}
|
||||||
|
@ -22,26 +55,4 @@ export async function sms77ApiRequest(this: IHookFunctions | IExecuteFunctions,
|
||||||
o.sendwith = 'n8n';
|
o.sendwith = 'n8n';
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
};
|
|
||||||
|
|
||||||
const credentials = this.getCredentials('Sms77');
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
'GET' === method ? qs = setPayload(qs) : form = setPayload(form);
|
|
||||||
|
|
||||||
const res = await this.helpers.request({
|
|
||||||
form,
|
|
||||||
json: true,
|
|
||||||
method,
|
|
||||||
qs,
|
|
||||||
uri: `https://gateway.sms77.io/api/${endpoint}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
if ('100' !== res.success) {
|
|
||||||
throw new Error('Invalid sms77 credentials or API error!');
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class Sms77 implements INodeType {
|
||||||
outputs: ['main'],
|
outputs: ['main'],
|
||||||
credentials: [
|
credentials: [
|
||||||
{
|
{
|
||||||
name: 'Sms77',
|
name: 'sms77Api',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -131,13 +131,13 @@ export class Sms77 implements INodeType {
|
||||||
throw new Error(`The operation "${operation}" is not known!`);
|
throw new Error(`The operation "${operation}" is not known!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
returnData.push({
|
const responseData = await sms77ApiRequest.call(this, 'POST', 'sms', {}, {
|
||||||
requestId: await sms77ApiRequest.call(this, 'POST', 'sms', {}, {
|
|
||||||
from: this.getNodeParameter('from', i),
|
from: this.getNodeParameter('from', i),
|
||||||
to: this.getNodeParameter('to', i),
|
to: this.getNodeParameter('to', i),
|
||||||
text: this.getNodeParameter('message', i),
|
text: this.getNodeParameter('message', i),
|
||||||
} as IDataObject)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
returnData.push(responseData);
|
||||||
}
|
}
|
||||||
return [this.helpers.returnJsonArray(returnData)];
|
return [this.helpers.returnJsonArray(returnData)];
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 1.2 KiB |
|
@ -92,7 +92,7 @@
|
||||||
"dist/credentials/RundeckApi.credentials.js",
|
"dist/credentials/RundeckApi.credentials.js",
|
||||||
"dist/credentials/ShopifyApi.credentials.js",
|
"dist/credentials/ShopifyApi.credentials.js",
|
||||||
"dist/credentials/SlackApi.credentials.js",
|
"dist/credentials/SlackApi.credentials.js",
|
||||||
"dist/credentials/Sms77.credentials.js",
|
"dist/credentials/Sms77Api.credentials.js",
|
||||||
"dist/credentials/Smtp.credentials.js",
|
"dist/credentials/Smtp.credentials.js",
|
||||||
"dist/credentials/StripeApi.credentials.js",
|
"dist/credentials/StripeApi.credentials.js",
|
||||||
"dist/credentials/SalesmateApi.credentials.js",
|
"dist/credentials/SalesmateApi.credentials.js",
|
||||||
|
@ -220,6 +220,7 @@
|
||||||
"dist/nodes/Shopify/Shopify.node.js",
|
"dist/nodes/Shopify/Shopify.node.js",
|
||||||
"dist/nodes/Shopify/ShopifyTrigger.node.js",
|
"dist/nodes/Shopify/ShopifyTrigger.node.js",
|
||||||
"dist/nodes/Slack/Slack.node.js",
|
"dist/nodes/Slack/Slack.node.js",
|
||||||
|
"dist/nodes/Sms77/Sms77.node.js",
|
||||||
"dist/nodes/SplitInBatches.node.js",
|
"dist/nodes/SplitInBatches.node.js",
|
||||||
"dist/nodes/SpreadsheetFile.node.js",
|
"dist/nodes/SpreadsheetFile.node.js",
|
||||||
"dist/nodes/SseTrigger.node.js",
|
"dist/nodes/SseTrigger.node.js",
|
||||||
|
|
Loading…
Reference in a new issue