feat: complete interactive audio player, contact resolver, unread clearance, and media sending
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user