n8n-nodes-megaapi
Version:
N8N Community Node for MegaAPI WhatsApp automation - Complete WhatsApp integration with messaging, groups, media, and more
58 lines • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkIsOnWhatsapp = checkIsOnWhatsapp;
const megaapiRequest_1 = require("../megaapiRequest");
async function checkIsOnWhatsapp(itemIndex) {
var _a;
const credentials = await this.getCredentials('megaApiCredentialsApi');
const instanceKey = credentials.instanceKey;
const jid = this.getNodeParameter('jid', itemIndex);
console.log('🔐 MegaAPI Credentials loaded');
console.log(`📋 Operation: isOnWhatsapp (item ${itemIndex + 1})`);
console.log(`📱 Instance Key: ${instanceKey}`);
console.log(`👤 Contact JID: ${jid}`);
try {
const url = `/rest/instance/isOnWhatsApp/${instanceKey}`;
const queryParams = { jid };
console.log(`🌐 Full URL: ${credentials.host}${url}`);
console.log('📤 Request Options');
console.log(` Method: GET`);
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(` Query Params:`, queryParams);
console.log('🔍 Checking if contact is on WhatsApp...');
const response = await megaapiRequest_1.megaapiRequest.call(this, 'GET', url, {}, queryParams);
console.log('📥 Response received', typeof response === 'string' ? response.substring(0, 50) + '...' : response);
let whatsappData;
if (typeof response === 'string') {
try {
whatsappData = JSON.parse(response);
}
catch {
whatsappData = { message: response, status: 'unknown' };
}
}
else {
whatsappData = response;
}
console.log('✅ WhatsApp contact check completed successfully', typeof whatsappData === 'string' ? whatsappData.substring(0, 50) + '...' : 'Object received');
return {
json: {
success: true,
operation: 'isOnWhatsapp',
instanceKey,
contactJid: jid,
message: 'WhatsApp contact check completed successfully',
data: whatsappData,
timestamp: new Date().toISOString(),
},
pairedItem: { item: itemIndex },
};
}
catch (error) {
console.log('💥 Error in MegaAPI isOnWhatsapp operation');
console.log(error);
throw error;
}
}
//# sourceMappingURL=isOnWhatsapp.js.map