UNPKG

n8n-nodes-megaapi

Version:

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

78 lines 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendLocation = sendLocation; const megaapiRequest_1 = require("../megaapiRequest"); async function sendLocation(itemIndex) { var _a; const credentials = await this.getCredentials('megaApiCredentialsApi'); const instanceKey = credentials.instanceKey; const to = this.getNodeParameter('to', itemIndex); const address = this.getNodeParameter('address', itemIndex); const latitude = this.getNodeParameter('latitude', itemIndex); const longitude = this.getNodeParameter('longitude', itemIndex); const caption = this.getNodeParameter('caption', itemIndex, ''); console.log('🔐 MegaAPI Credentials loaded'); console.log(`📋 Operation: sendLocation (item ${itemIndex + 1})`); console.log(`📱 Instance Key: ${instanceKey}`); console.log(`👤 To: ${to}`); console.log(`📍 Address: ${address}`); console.log(`🌐 Latitude: ${latitude}`); console.log(`🌐 Longitude: ${longitude}`); console.log(`💬 Caption: ${caption || 'No caption'}`); try { const requestBody = { messageData: { to: to, address: address, caption: caption, latitude: latitude, longitude: longitude, }, }; const apiUrl = `/rest/sendMessage/${instanceKey}/location`; console.log(`🌐 Full URL: ${credentials.host}${apiUrl}`); 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('📍 Sending location via MegaAPI...'); const response = await megaapiRequest_1.megaapiRequest.call(this, 'POST', apiUrl, requestBody); console.log('📥 Response received', typeof response === 'string' ? response.substring(0, 50) + '...' : response); let messageData; if (typeof response === 'string') { try { messageData = JSON.parse(response); } catch { messageData = { message: response, status: 'unknown' }; } } else { messageData = response; } console.log('✅ Location sent successfully', typeof messageData === 'string' ? messageData.substring(0, 50) + '...' : 'Object received'); return { json: { success: true, operation: 'sendLocation', instanceKey, to, address, latitude, longitude, caption, message: 'Location sent successfully', data: messageData, timestamp: new Date().toISOString(), }, pairedItem: { item: itemIndex }, }; } catch (error) { console.log('💥 Error in MegaAPI Send Location operation'); console.log(error); throw error; } } //# sourceMappingURL=sendLocation.js.map