app-min-ser-nest/scripts/probe-openwa.mjs
2026-10-17 19:40:29 -04:00

58 lines
2.2 KiB
JavaScript

import { readFileSync } from 'fs';
const env = readFileSync('.env', 'utf8');
const get = (k) => {
const m = env.match(new RegExp('^' + k + '=(.*)$', 'm'));
return m ? m[1].trim() : '';
};
const base = get('OPENWA_URL');
const key = get('OPENWA_API_KEY');
const headers = { 'X-API-Key': key, 'Content-Type': 'application/json' };
const js = await (await fetch(base + '/assets/api-Cyx1hppX.js')).text();
console.log('api js len', js.length);
const idx = js.toLowerCase().indexOf('send-text');
console.log('send-text idx', idx);
if (idx >= 0) {
console.log('--- context ---');
console.log(js.slice(Math.max(0, idx - 400), idx + 600));
}
// also search sendText, send_text, message body fields
for (const term of ['sendText', 'send_text', 'chatId', 'text', 'sessionId', 'phone', 'recipient']) {
const c = (js.match(new RegExp(term, 'g')) || []).length;
console.log(term, c);
}
// try many body shapes against real route (invalid numbers only - 400 vs other)
const sessions = await (await fetch(base + '/api/sessions', { headers })).json();
const sid = sessions[0].id;
const url = `${base}/api/sessions/${sid}/messages/send-text`;
const shapes = [
{ to: '591000000', text: 'x' },
{ phone: '591000000', text: 'x' },
{ number: '591000000', text: 'x' },
{ chatId: '591000000@c.us', text: 'x' },
{ chat_id: '591000000@c.us', text: 'x' },
{ recipient: '591000000', text: 'x' },
{ target: '591000000', text: 'x' },
{ body: 'x', to: '591000000' },
{ content: 'x', to: '591000000' },
{ message: 'x', to: '591000000' },
{ text: 'x', number: '591000000', sessionId: sid },
{ text: 'x', chatId: '591000000@c.us', sessionId: sid },
{ data: { to: '591000000', text: 'x' } },
{ payload: { chatId: '591000000@c.us', text: 'x' } },
{ to: '59178124224@c.us', text: 'x' }, // self - might work if valid shape
{ chatId: '59178124224@c.us', text: 'self-probe-no-send' },
{ phone: '59178124224', text: 'x' },
{ number: '59178124224', text: 'x' },
];
console.log('--- body shapes (invalid number first) ---');
for (const body of shapes) {
const res = await fetch(url, { method: 'POST', headers, body: JSON.stringify(body) });
const t = await res.text();
console.log(JSON.stringify(body).slice(0, 80), '=>', res.status, t.slice(0, 160).replace(/\n/g, ' '));
}