UNPKG

n8n-nodes-megaapi

Version:

N8N Community Node for MegaAPI WhatsApp automation - Complete WhatsApp integration with messaging, groups, media, and more

66 lines 2.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configureWebhook = configureWebhook; const megaapiRequest_1 = require("../megaapiRequest"); async function configureWebhook(itemIndex) { var _a; const credentials = await this.getCredentials('megaApiCredentialsApi'); const instanceKey = credentials.instanceKey; const webhookUrl = this.getNodeParameter('webhookUrl', itemIndex); const webhookEnabled = this.getNodeParameter('webhookEnabled', itemIndex); console.log('🔐 MegaAPI Credentials loaded'); console.log(`📋 Operation: configWebhook (item ${itemIndex + 1})`); console.log(`🔗 Instance Key: ${instanceKey}`); console.log(`🌐 Webhook URL: ${webhookUrl}`); console.log(`⚡ Webhook Enabled: ${webhookEnabled}`); try { const requestBody = { messageData: { webhookUrl: webhookUrl, webhookEnabled: webhookEnabled, }, }; const url = `/rest/webhook/${instanceKey}/configWebhook`; console.log(`🌐 Full URL: ${credentials.host}${url}`); console.log('📤 Request Options'); console.log(` Method: POST`); console.log(` Authorization: Bearer ${(_a = credentials.token) === null || _a === void 0 ? void 0 : _a.substring(0, 10)}...`); console.log(` Content-Type: application/json`); console.log('📦 Request Body:', requestBody); console.log('⚙️ Configuring webhook in MegaAPI...'); const response = await megaapiRequest_1.megaapiRequest.call(this, 'POST', url, requestBody); console.log('📥 Response received', typeof response === 'string' ? response.substring(0, 50) + '...' : response); let webhookData; if (typeof response === 'string') { try { webhookData = JSON.parse(response); } catch { webhookData = { message: response, status: 'unknown' }; } } else { webhookData = response; } console.log('✅ Webhook configuration completed successfully', typeof webhookData === 'string' ? webhookData.substring(0, 50) + '...' : 'Object received'); return { json: { success: true, operation: 'configWebhook', instanceKey, webhookUrl, webhookEnabled, message: 'Webhook configuration completed successfully', data: webhookData, timestamp: new Date().toISOString(), }, pairedItem: { item: itemIndex }, }; } catch (error) { console.log('💥 Error in MegaAPI Config Webhook operation'); console.log(error); throw error; } } //# sourceMappingURL=configWebhook.js.map