UNPKG

n8n-walichat

Version:

n8n plugin for WaliChat

103 lines (102 loc) 3.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidateNumbers = void 0; const BaseNode_1 = require("../Base/BaseNode"); const globalProperties_1 = require("../globalProperties"); const constants_1 = require("../../constants"); class ValidateNumbers extends BaseNode_1.BaseNode { constructor() { super(...arguments); this.description = { displayName: 'Validate phone numbers', name: 'walichatValidateNumbers', group: ['Validate'], version: 1, icon: 'file:../../../icon.png', description: 'Validate and normalize a list of phone numbers using the WaliChat API', defaults: { name: 'Validate Numbers', color: '#1A82e2', }, inputs: ["main" /* NodeConnectionType.Main */], outputs: ["main" /* NodeConnectionType.Main */], credentials: [ { name: 'WaliChatApiKey', required: true, }, ], properties: [ ...globalProperties_1.globalProperties, { displayName: 'Country', name: 'country', type: 'options', options: constants_1.countries.map(country => ({ name: country.name, value: country.code })), default: '', placeholder: 'Select the country code...', description: 'The country code for the phone numbers.', required: false, }, { displayName: 'Phone Numbers', name: 'phoneNumbers', type: 'string', default: '', placeholder: 'Enter the phone numbers separated by commas...', description: 'The phone numbers to validate and normalize.', required: true, }, { displayName: 'Poll Options', name: 'pollOptions', type: 'string', default: '', placeholder: 'Enter the poll options separated by commas...', description: 'The poll options to include in the poll.', required: false, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { const apiKey = this.getNodeParameter('apiKey', i); const country = this.getNodeParameter('country', i); const phoneNumbers = this.getNodeParameter('phoneNumbers', i); const pollOptions = this.getNodeParameter('pollOptions', i); const requestBody = { country, numbers: phoneNumbers.split(',').map(phone => ({ phone: phone.trim() })), poll: { name: 'Vote for your favorite color', options: pollOptions.split(',').map(option => option.trim()), }, }; try { const response = await super.request({ path: '/numbers/validate', method: 'POST', body: requestBody, headers: { 'Authorization': `Bearer ${apiKey}`, }, }); returnData.push({ json: response, }); } catch (error) { returnData.push({ json: { error: error.message, }, }); } } return [returnData]; } } exports.ValidateNumbers = ValidateNumbers;