UNPKG

@negreanucalin8x8/n8n-nodes-8x8

Version:
120 lines 5.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EightByEight = void 0; const n8n_workflow_1 = require("n8n-workflow"); const apiDef_helper_1 = require("./helpers/apiDef.helper"); const request_helper_1 = require("./helpers/request.helper"); const apiDefinition_1 = require("./apiDefinition"); class EightByEight { constructor() { this.description = { displayName: "EightByEight (8x8)", name: "eightByEight", icon: "file:logo.svg", group: ["input"], version: 1, subtitle: '={{$parameter["operation"]}}', description: "8x8 API operations", defaults: { name: "EightByEight", }, inputs: ["main"], outputs: ["main"], credentials: [ { name: "eightByEightApi", required: true, }, ], properties: [ { displayName: "Resource", name: "resource", type: "options", noDataExpression: true, options: apiDef_helper_1.ApiDefHelper.getResources(), default: apiDefinition_1.RESOURCE_SMS, }, apiDef_helper_1.ApiDefHelper.generateApiFromOperation(apiDefinition_1.RESOURCE_SMS), ...apiDef_helper_1.ApiDefHelper.getParameters(), ], }; } async execute() { const requestHelper = new request_helper_1.RequestHelper(); const items = this.getInputData(); const returnData = []; const resource = this.getNodeParameter("resource", 0); const operation = this.getNodeParameter("operation", 0); for (let i = 0; i < items.length; i++) { try { const requestUriParams = {}; const uriParamList = requestHelper.getAllUriParams(resource, operation); for (const uriParam of uriParamList) { requestUriParams[uriParam] = this.getNodeParameter(uriParam, i); } let formParams = {}; if (resource === apiDefinition_1.RESOURCE_SMS) { switch (operation) { case "sendSMS": { formParams = request_helper_1.RequestHelper.getCleanFormData(this.getNodeParameter("message.message", i)); break; } case "sendSMSBatch": { const parameterList = ['clientBatchId', 'includeMessagesInResponse', 'clientIp']; for (const parameterString of parameterList) { formParams[parameterString] = this.getNodeParameter(parameterString, i); } try { const destinations = this.getNodeParameter('destinations.destinations', i); formParams['destinations'] = destinations.map(d => d.destination); } catch (_) { } try { const template = this.getNodeParameter('template.template', i); formParams['template'] = template; } catch (_) { } try { console.log('Messages', this.getNodeParameter('messages', i)); const messages = this.getNodeParameter('messages.messages', i); formParams['message'] = messages; } catch (_) { } formParams = request_helper_1.RequestHelper.getCleanFormData(formParams); break; } case "cancelTheScheduledSMS": case "cancelBatchScheduledSMS": { break; } default: throw new Error(`The operation "${operation}" is currently under development.`); } } const request = requestHelper.buildRequest(resource, operation, requestUriParams, formParams); const response = await this.helpers.requestWithAuthentication.call(this, 'eightByEightApi', request); if (Array.isArray(response.data)) { returnData.push(...response.data.map((response) => ({ json: response }))); } else { returnData.push({ json: response }); } } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message } }); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), error); } } } return [this.helpers.returnJsonArray(returnData)]; } } exports.EightByEight = EightByEight; //# sourceMappingURL=EightByEight.node.js.map