UNPKG

n8n-nodes-megaapi

Version:

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

66 lines 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendLinkPreview = sendLinkPreview; const megaapiRequest_1 = require("../megaapiRequest"); async function sendLinkPreview(itemIndex) { var _a; const credentials = await this.getCredentials('megaApiCredentialsApi'); const instanceKey = credentials.instanceKey; const to = this.getNodeParameter('to', itemIndex); const textWithLink = this.getNodeParameter('textWithLink', itemIndex); console.log('🔐 MegaAPI Credentials loaded'); console.log(`📋 Operation: sendLinkPreview (item ${itemIndex + 1})`); console.log(`📱 Instance Key: ${instanceKey}`); console.log(`👤 To: ${to}`); console.log(`🔗 Text with Link: ${textWithLink.substring(0, 100)}${textWithLink.length > 100 ? '...' : ''}`); try { const requestBody = { messageData: { to: to, textWithLink: textWithLink, }, }; const apiUrl = `/rest/sendMessage/${instanceKey}/sendLinkPreview`; 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 link preview 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('✅ Link preview sent successfully', typeof messageData === 'string' ? messageData.substring(0, 50) + '...' : 'Object received'); return { json: { success: true, operation: 'sendLinkPreview', instanceKey, to, textWithLink, message: 'Link preview sent successfully', data: messageData, timestamp: new Date().toISOString(), }, pairedItem: { item: itemIndex }, }; } catch (error) { console.log('💥 Error in MegaAPI Send Link Preview operation'); console.log(error); throw error; } } //# sourceMappingURL=sendLinkPreview.js.map