UNPKG

n8n-nodes-zuckzapgo

Version:

n8n community nodes for ZuckZapGo - WhatsApp Multi-Device REST API

132 lines 5.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZuckZapGoCall = void 0; const GenericFunctions_1 = require("../GenericFunctions"); class ZuckZapGoCall { constructor() { this.description = { displayName: 'ZuckZapGo Call', name: 'zuckzapgoCall', icon: 'file:zuckzapgo.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'Manage WhatsApp calls using ZuckZapGo API', defaults: { name: 'ZuckZapGo Call', }, inputs: ["main" /* NodeConnectionType.Main */], outputs: ["main" /* NodeConnectionType.Main */], credentials: [ { name: 'zuckzapgoApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Reject Call', value: 'rejectCall', description: 'Reject an incoming call', action: 'Reject call', }, ], default: 'rejectCall', }, { displayName: 'Call ID', name: 'callId', type: 'string', default: '', placeholder: 'call_id_here', description: 'The ID of the call to reject', required: true, }, { displayName: 'Call From', name: 'callFrom', type: 'string', default: '', placeholder: '5491155553934@s.whatsapp.net', description: 'The JID of the caller', required: true, }, { displayName: 'Reject Type', name: 'rejectType', type: 'options', default: 'declined', options: [ { name: 'Busy', value: 'busy', description: 'Line is busy', }, { name: 'Declined', value: 'declined', description: 'Call declined', }, { name: 'Unavailable', value: 'unavailable', description: 'Unavailable to answer', }, ], description: 'The type of rejection', }, { displayName: 'Custom Message', name: 'message', type: 'string', default: '', placeholder: 'Sorry, I cannot take calls at the moment.', description: 'Optional custom rejection message to send to the caller', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const operation = this.getNodeParameter('operation', i); if (operation === 'rejectCall') { const callId = this.getNodeParameter('callId', i); const callFrom = this.getNodeParameter('callFrom', i); const rejectType = this.getNodeParameter('rejectType', i); const message = this.getNodeParameter('message', i); const body = { call_id: callId, call_from: callFrom, reject_type: rejectType, }; if (message) { body.message = message; } const responseData = await GenericFunctions_1.zuckzapgoApiRequest.call(this, 'POST', '/call/reject/send', body); const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }); returnData.push(...executionData); } } catch (error) { if (this.continueOnFail()) { const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } }); returnData.push(...executionErrorData); continue; } throw error; } } return [returnData]; } } exports.ZuckZapGoCall = ZuckZapGoCall; //# sourceMappingURL=ZuckZapGoCall.node.js.map