omnichannel-backend/test-api.js

21 lines
666 B
JavaScript
Raw Permalink Normal View History

const fs = require('fs');
const fetch = require('node-fetch') || global.fetch;
async function run() {
try {
const chatsRes = await fetch('http://localhost:3001/whatsapp/chats');
const chats = await chatsRes.json();
if (chats.length > 0) {
const firstChatId = chats[0].id._serialized;
const msgsRes = await fetch(`http://localhost:3001/whatsapp/messages/${firstChatId}`);
if (!msgsRes.ok) return;
const msgs = await msgsRes.json();
fs.writeFileSync('test-api-out.json', JSON.stringify(msgs, null, 2));
console.log('Saved to test-api-out.json');
}
} catch (err) {
console.error('Error:', err);
}
}
run();