feat: add /api/avatar endpoint and real-time poll vote event WS broadaster
This commit is contained in:
@@ -364,6 +364,22 @@ function initWhatsApp() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Poll Vote updates (Listen to real-time votes on polls!)
|
||||||
|
waClient.on('vote', (vote) => {
|
||||||
|
try {
|
||||||
|
console.log(`[WA] Poll vote received from: ${vote.sender} for poll message: ${vote.pollMessageId}`);
|
||||||
|
broadcast({
|
||||||
|
type: 'poll_vote',
|
||||||
|
pollMessageId: vote.pollMessageId,
|
||||||
|
sender: vote.sender,
|
||||||
|
selectedOptions: vote.selectedOptions,
|
||||||
|
timestamp: vote.timestamp
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[WA] Error broadcasting poll_vote event:', err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Disconnected
|
// Disconnected
|
||||||
waClient.on('disconnected', (reason) => {
|
waClient.on('disconnected', (reason) => {
|
||||||
console.warn('[WA] Disconnected! Reason:', reason);
|
console.warn('[WA] Disconnected! Reason:', reason);
|
||||||
@@ -766,6 +782,22 @@ app.post('/api/send-poll', async (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ─── HTTP Profile Pic Avatar Endpoint ───────────────────────────────────────
|
||||||
|
app.get('/api/avatar', async (req, res) => {
|
||||||
|
if (!clientReady) return res.status(503).json({ error: 'WhatsApp is not ready' });
|
||||||
|
const { phone } = req.query;
|
||||||
|
if (!phone) return res.status(400).json({ error: 'phone parameter is required' });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const chatId = phone.includes('@') ? phone : `${phone}@c.us`;
|
||||||
|
const avatarUrl = await waClient.getProfilePicUrl(chatId);
|
||||||
|
res.status(200).json({ success: true, avatarUrl: avatarUrl || null });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('[API] Avatar error:', err.message);
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ─── HTTP Health Endpoint ──────────────────────────────────────────────────
|
// ─── HTTP Health Endpoint ──────────────────────────────────────────────────
|
||||||
app.get('/health', (req, res) => {
|
app.get('/health', (req, res) => {
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
|
|||||||
Reference in New Issue
Block a user