UNPKG

n8n-nodes-alive5weather

Version:
211 lines 8.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Alive5SendSMS = void 0; class Alive5SendSMS { constructor() { this.description = { displayName: 'Alive5 Send SMS', name: 'alive5SendSMS', icon: 'file:icons/sms-icon.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'Send SMS messages via Alive5 API', defaults: { name: 'Alive5 Send SMS', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'alive5Api', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Send SMS', value: 'sendSms', description: 'Send an SMS message', action: 'Send an SMS message', }, ], default: 'sendSms', }, { displayName: 'Channel', name: 'channelId', type: 'options', typeOptions: { loadOptionsMethod: 'getChannels', }, displayOptions: { show: { operation: [ 'sendSms', ], }, }, default: '', description: 'Channel to use for sending the SMS', required: true, }, { displayName: 'User ID', name: 'userId', type: 'string', displayOptions: { show: { operation: [ 'sendSms', ], }, }, default: '', description: 'ID of the user sending the SMS', required: true, }, { displayName: 'From Phone Number', name: 'phoneNumberFrom', type: 'string', displayOptions: { show: { operation: [ 'sendSms', ], }, }, default: '', placeholder: '+15402173882', description: 'Phone number to send from (include country code with + prefix)', required: true, }, { displayName: 'To Phone Number', name: 'phoneNumberTo', type: 'string', displayOptions: { show: { operation: [ 'sendSms', ], }, }, default: '', placeholder: '+18888888888', description: 'Phone number to send the message to (include country code with + prefix)', required: true, }, { displayName: 'Message', name: 'message', type: 'string', displayOptions: { show: { operation: [ 'sendSms', ], }, }, default: '', description: 'The message content to send', required: true, typeOptions: { rows: 4, }, }, ], }; this.methods = { loadOptions: { async getChannels() { const credentials = await this.getCredentials('alive5Api'); try { const response = await this.helpers.requestWithAuthentication.call(this, 'alive5Api', { method: 'GET', url: 'https://api-v2.alive5.com/public/1.0/objects/channels-and-users/list', headers: { 'X-A5-APIKEY': credentials.apiKey, 'Accept': 'application/json', }, json: true, }); if (!response.data || !response.data.Items || !Array.isArray(response.data.Items)) { return []; } const options = []; for (const channel of response.data.Items) { options.push({ name: channel.channel_label, value: channel.channel_id, description: `Channel ID: ${channel.channel_id}`, }); } return options; } catch (error) { console.error('Error loading channels:', error); return []; } }, }, }; } async execute() { const items = this.getInputData(); const returnData = []; const credentials = await this.getCredentials('alive5Api'); if (!(credentials === null || credentials === void 0 ? void 0 : credentials.apiKey)) { throw new Error('No API key provided in credentials'); } for (let i = 0; i < items.length; i++) { try { const operation = this.getNodeParameter('operation', i); if (operation === 'sendSms') { const channelId = this.getNodeParameter('channelId', i); const userId = this.getNodeParameter('userId', i); const phoneNumberFrom = this.getNodeParameter('phoneNumberFrom', i); const phoneNumberTo = this.getNodeParameter('phoneNumberTo', i); const message = this.getNodeParameter('message', i); const form = { channel_id: channelId, user_id: userId, phone_number_from: phoneNumberFrom, phone_number_to: phoneNumberTo, message: message, }; const response = await this.helpers.request({ method: 'POST', url: 'https://api.alive5.com/public/1.0/conversations/sms/send', headers: { 'X-A5-APIKEY': credentials.apiKey, 'Accept': 'application/json' }, formData: form, json: true, }); const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(response), { 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.Alive5SendSMS = Alive5SendSMS; //# sourceMappingURL=Alive5SendSMS.node.js.map