-
Notifications
You must be signed in to change notification settings - Fork 0
Backend API Endpoints
harishoke edited this page Jun 1, 2025
·
1 revision
The Node.js backend (server.js) exposes several HTTP API endpoints that the Python frontend uses for various operations. The server typically runs on http://localhost:3000.
-
GET /status- Description: Returns the current connection status of the Baileys WhatsApp client.
-
Response: JSON object containing:
-
status: String - e.g., "ready", "qr_pending", "disconnected", "logged_out". -
qrCode: String (Optional) - The QR code data string if status is "qr_pending". -
user: Object (Optional) - Information about the logged-in WhatsApp user if status is "ready".
-
-
POST /send-poll- Description: Sends a poll to a specified WhatsApp chat.
-
Request Body (JSON):
(Note:
{ "chatId": "string (whatsapp_jid)", "question": "string", "options": ["string", "string", ...], "allowMultipleAnswers": boolean }allowMultipleAnswers: truetranslates toselectableCount: 0in Baileys,falsetranslates toselectableCount: 1). -
Response (JSON):
- Success:
{ "success": true, "message": "Poll sent successfully!", "pollMsgId": "string" } - Failure:
{ "success": false, "message": "Error description", "error": "Optional error details" }
- Success:
-
GET /get-chats- Description: Fetches a list of the connected WhatsApp account's chats and groups.
-
Response (JSON):
- Success:
{ "success": true, "chats": [{"id": "string", "name": "string", "isGroup": boolean}, ...] } - Failure:
{ "success": false, "message": "Error description", "error": "Optional error details" }
- Success:
-
POST /logout- Description: Logs out the current WhatsApp session from Baileys and attempts to delete the local session authentication files.
-
Response (JSON):
- Success:
{ "success": true, "message": "Logged out and local session cleared..." } - Failure:
{ "success": false, "message": "Error description" }
- Success:
-
GET /get-all-poll-data- Description: Fetches data for all polls currently tracked as active by the server for the current session.
-
Response (JSON):
- Success:
{ "success": true, "polls": { "pollMsgId_1": { poll_data_object_1 }, ... } } - The
poll_data_objectstructure includesquestion,options,optionHashes,results,voters,chatId,timestamp,selectableCount.
- Success:
Socket.IO Events (Backend to Frontend):
The backend also communicates with the frontend using these Socket.IO events:
-
qr_code (qrData): Sends new QR code data. -
client_status (statusString): Sends updates on WhatsApp client connection status (e.g., "ready", "disconnected", "qr_pending", "logged_out"). -
whatsapp_user (userDataObject): Sends basic info about the logged-in WhatsApp user. -
initial_poll_data (allPollsObject): Sends all currently tracked poll data when a GUI client connects. -
new_poll_sent ({ pollMsgId, pollData }): Informs the GUI that a new poll has been successfully sent by the backend. -
poll_update_to_gui ({ pollMsgId, results, question, options, voters, selectableCount }): Sends real-time updates for a specific poll when new votes are received.