diff --git a/whatsapp_bridge/server.js b/whatsapp_bridge/server.js index b4f23e1..7102245 100644 --- a/whatsapp_bridge/server.js +++ b/whatsapp_bridge/server.js @@ -743,6 +743,28 @@ app.post('/api/send-media', async (req, res) => { } }); +app.post('/api/send-poll', async (req, res) => { + if (!clientReady) return res.status(503).json({ error: 'WhatsApp is not ready' }); + const { phone, question, options, allowMultiple } = req.body; + if (!phone || !question || !options || !Array.isArray(options)) { + return res.status(400).json({ error: 'phone, question, and options (array of strings) are required' }); + } + + try { + const { Poll } = require('whatsapp-web.js'); + const poll = new Poll(question, options, { + allowMultipleAnswers: allowMultiple !== false // default to true + }); + const chatId = phone.includes('@') ? phone : `${phone}@c.us`; + const sentMsg = await waClient.sendMessage(chatId, poll); + res.status(200).json({ success: true, messageId: sentMsg.id.id }); + } catch (err) { + console.error('[API] Send poll error:', err.message); + res.status(500).json({ error: err.message }); + } +}); + + // ─── HTTP Health Endpoint ────────────────────────────────────────────────── app.get('/health', (req, res) => {