UNPKG

n8n-nodes-megaapi

Version:

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

82 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendMediaUrl = sendMediaUrl; const megaapiRequest_1 = require("../megaapiRequest"); async function sendMediaUrl(itemIndex) { var _a; const credentials = await this.getCredentials('megaApiCredentialsApi'); const instanceKey = credentials.instanceKey; const to = this.getNodeParameter('to', itemIndex); const url = this.getNodeParameter('url', itemIndex); const fileName = this.getNodeParameter('fileName', itemIndex); const type = this.getNodeParameter('type', itemIndex); const mimeType = this.getNodeParameter('mimeType', itemIndex); const caption = this.getNodeParameter('caption', itemIndex, ''); console.log('🔐 MegaAPI Credentials loaded'); console.log(`📋 Operation: sendMediaUrl (item ${itemIndex + 1})`); console.log(`📱 Instance Key: ${instanceKey}`); console.log(`👤 To: ${to}`); console.log(`🌐 Media URL: ${url}`); console.log(`📄 File Name: ${fileName}`); console.log(`📎 Media Type: ${type}`); console.log(`🏷️ MIME Type: ${mimeType}`); console.log(`💬 Caption: ${caption || 'No caption'}`); try { const requestBody = { messageData: { to: to, url: url, fileName: fileName, type: type, caption: caption, mimeType: mimeType, }, }; const apiUrl = `/rest/sendMessage/${instanceKey}/mediaUrl`; 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 media URL 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('✅ Media URL sent successfully', typeof messageData === 'string' ? messageData.substring(0, 50) + '...' : 'Object received'); return { json: { success: true, operation: 'sendMediaUrl', instanceKey, to, url, fileName, type, mimeType, caption, message: 'Media URL sent successfully', data: messageData, timestamp: new Date().toISOString(), }, pairedItem: { item: itemIndex }, }; } catch (error) { console.log('💥 Error in MegaAPI Send Media URL operation'); console.log(error); throw error; } } //# sourceMappingURL=sendMediaUrl.js.map