Migreer naar WuzAPI (chat/send/text, Token-header)
This commit is contained in:
parent
4f9b2c064e
commit
cfea478c2d
1 changed files with 5 additions and 4 deletions
9
index.js
9
index.js
|
|
@ -13,6 +13,7 @@ const CONFIG = {
|
|||
daLoginKey: process.env.DA_LOGIN_KEY,
|
||||
daDomain: process.env.DA_DOMAIN,
|
||||
whatsappApi: process.env.WHATSAPP_API_ENDPOINT || 'http://localhost:3001',
|
||||
whatsappToken: process.env.WHATSAPP_TOKEN || '',
|
||||
whatsappSession: process.env.WHATSAPP_SESSION || 'EdGpt',
|
||||
adminPhone: process.env.ADMIN_PHONE,
|
||||
matrixApi: process.env.MATRIX_API_ENDPOINT || 'https://whatsed.eddydevink.nl',
|
||||
|
|
@ -139,13 +140,13 @@ async function updateEuroDynDns(hostname, ip) {
|
|||
}
|
||||
|
||||
async function sendWhatsApp(message) {
|
||||
const url = `${CONFIG.whatsappApi}/client/sendMessage/${CONFIG.whatsappSession}`;
|
||||
const chatId = `${CONFIG.adminPhone}@c.us`;
|
||||
const url = `${CONFIG.whatsappApi}/chat/send/text`;
|
||||
const phone = `${CONFIG.adminPhone}`.replace(/[^0-9]/g, '');
|
||||
try {
|
||||
const resp = await fetchWithTimeout(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ chatId, content: message, contentType: 'string' }),
|
||||
headers: { 'Content-Type': 'application/json', Token: CONFIG.whatsappToken },
|
||||
body: JSON.stringify({ Phone: phone, Body: message }),
|
||||
}, 10000);
|
||||
if (!resp.ok) {
|
||||
logError(`WhatsApp send failed: ${resp.status}`);
|
||||
|
|
|
|||
Loading…
Reference in a new issue