almeira-web/test-evolution.js

31 lines
1.2 KiB
JavaScript

const axios = require('axios');
const fs = require('fs');
const EVOLUTION_API_URL = 'https://evolution.almeira.com.co';
const EVOLUTION_API_KEY = 'mgXxu2eAwyhWNnptFEouUE6qLkvwVm6K';
const EVOLUTION_INSTANCE_NAME = 'AutomataAlmeira';
const CHAT_ID = '573134848203-1408546044@g.us';
async function testGetBase64() {
try {
const response = await axios.post(
`${EVOLUTION_API_URL}/chat/findMessages/${EVOLUTION_INSTANCE_NAME}?page=1&limit=5`,
{ where: { "key": { "remoteJid": CHAT_ID } } },
{ headers: { 'apikey': EVOLUTION_API_KEY, 'Content-Type': 'application/json' } }
);
const msg = response.data.messages.records[0]; // Assuming it's the imageMessage we saw
const base64Res = await axios.post(
`${EVOLUTION_API_URL}/chat/getBase64FromMediaMessage/${EVOLUTION_INSTANCE_NAME}`,
{ message: msg },
{ headers: { 'apikey': EVOLUTION_API_KEY, 'Content-Type': 'application/json' } }
);
console.log("Success getting base64. Base64 length:", base64Res.data.base64 ? base64Res.data.base64.length : 'none');
} catch (e) {
console.error(e.response ? e.response.data : e.message);
}
}
testGetBase64();