feat: complete interactive audio player, contact resolver, unread clearance, and media sending

This commit is contained in:
Hamza-Ayed
2026-05-18 16:51:29 +03:00
parent 56f29b8306
commit 25bdf1fba1
6 changed files with 267 additions and 30 deletions

View File

@@ -441,6 +441,31 @@ async function handleMessage(ws, raw) {
});
}
// ── Send Media ──────────────────────────────────────────────────────
case 'send_media': {
if (!clientReady) {
return respond({ type: 'error', message: 'WhatsApp is not ready' });
}
const { chatId, base64, mimetype, filename, caption } = payload;
if (!chatId || !base64 || !mimetype) {
return respond({ type: 'error', message: 'chatId, base64, and mimetype are required' });
}
try {
const { MessageMedia } = require('whatsapp-web.js');
const media = new MessageMedia(mimetype, base64, filename || 'file');
const sentMsg = await waClient.sendMessage(chatId, media, { caption: caption || '' });
return respond({
type: 'message_sent',
chatId: chatId,
data: formatMessage(sentMsg),
requestId
});
} catch (err) {
console.error('[WS] send_media failed:', err.message);
return respond({ type: 'error', message: err.message || 'Failed to send media', requestId });
}
}
// ── Mark as Read ───────────────────────────────────────────────────
case 'mark_read': {
if (!clientReady) {