mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add Plivo Node (#1563)
* add Plivo Node * fixed package.json * added Git user in CLI to validate CLA * 🎨 Replace PNG with SVG icon * ⚡ Ajust per codebase conventions * 🔨 Fix operation ID * ✏️ Specify geo-restriction for MMS * ⚡ Improvements * ⚡ Fix node name and operation order Co-authored-by: Nixon <nixon@Nixons-MacBook-Pro.local> Co-authored-by: Nixon <nixon@plivo.com> Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
62
packages/nodes-base/nodes/Plivo/GenericFunctions.ts
Normal file
62
packages/nodes-base/nodes/Plivo/GenericFunctions.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
/**
|
||||
* Make an API request to Plivo.
|
||||
*
|
||||
* @param {IHookFunctions} this
|
||||
* @param {string} method
|
||||
* @param {string} url
|
||||
* @param {object} body
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function plivoApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
qs: IDataObject = {},
|
||||
) {
|
||||
|
||||
const credentials = this.getCredentials('plivoApi') as { authId: string, authToken: string };
|
||||
|
||||
if (!credentials) {
|
||||
throw new Error('No credentials returned!');
|
||||
}
|
||||
|
||||
const options = {
|
||||
method,
|
||||
form: body,
|
||||
qs,
|
||||
uri: `https://api.plivo.com/v1/Account/${credentials.authId}${endpoint}/`,
|
||||
auth: {
|
||||
user: credentials.authId,
|
||||
pass: credentials.authToken,
|
||||
},
|
||||
json: true,
|
||||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.request(options);
|
||||
} catch (error) {
|
||||
if (error.statusCode === 401) {
|
||||
throw new Error('Invalid Plivo credentials');
|
||||
}
|
||||
if (error?.response?.body?.error) {
|
||||
let errorMessage = `Plivo error response [${error.statusCode}]: ${error.response.body.error}`;
|
||||
if (error.response.body.more_info) {
|
||||
errorMessage = `errorMessage (${error.response.body.more_info})`;
|
||||
}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user