n8n-nodes-megaapi
Version:
N8N Community Node for MegaAPI WhatsApp automation - Complete WhatsApp integration with messaging, groups, media, and more
53 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInstanceStatus = getInstanceStatus;
const megaapiRequest_1 = require("../megaapiRequest");
async function getInstanceStatus(itemIndex) {
var _a;
const credentials = await this.getCredentials('megaApiCredentialsApi');
const instanceKey = credentials.instanceKey;
console.log('🔐 MegaAPI Credentials loaded');
console.log(`📋 Operation: status (item ${itemIndex + 1})`);
console.log(`📊 Instance Key: ${instanceKey}`);
try {
const url = `/rest/instance/${instanceKey}`;
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('📊 Getting instance status from MegaAPI...');
const response = await megaapiRequest_1.megaapiRequest.call(this, 'GET', url, {});
console.log('📥 Response received', typeof response === 'string' ? response.substring(0, 50) + '...' : response);
let statusData;
if (typeof response === 'string') {
try {
statusData = JSON.parse(response);
}
catch {
statusData = { message: response, status: 'unknown' };
}
}
else {
statusData = response;
}
console.log('✅ Instance status retrieved successfully', typeof statusData === 'string' ? statusData.substring(0, 50) + '...' : 'Object received');
return {
json: {
success: true,
operation: 'status',
instanceKey,
message: 'Instance status retrieved successfully',
data: statusData,
timestamp: new Date().toISOString(),
},
pairedItem: { item: itemIndex },
};
}
catch (error) {
console.log('💥 Error in MegaAPI Status operation');
console.log(error);
throw error;
}
}
//# sourceMappingURL=status.js.map