التصويت الآلي في الاستطلاعات (Poll Vote)

تسجيل الأصوات والتفاعل مع استطلاعات الواتساب برمجياً.

POST
https://api.wawp.net/v2/send/poll/vote?access_token=123456789&chatId=201234567890%40c.us&instance_id=123456789&messageId=ABC123456789&votes=%5B%22Awesome%21%22%5D

تسجيل الدخول مطلوب

سجل الدخول لاستبدال المعرفات (Instance ID) ورمز الوصول (Access Token) بمعلومات حسابك الحقيقي لاختبار ال API مباشرة.

تسجيل الدخول
اختبار /v2/send/poll/vote
POST
POST

لا توجد معاملات استعلام مطلوبة

هذه النهاية الطرفية لا تتوقع بيانات في الرابط.

Programmatic Participation: Mastering the Poll Vote Engine

In highly automated environments, bots often need to participate in the decision-making process alongside human users. The /v2/send/poll/vote endpoint provides the capability to cast, change, or rescind votes on existing WhatsApp polls programmatically. This enables complex "Bot-in-the-Loop" scenarios where an AI agent can express its findings, preferences, or status via the native interactive poll UI.


🏗️ The Programmatic Voting Architecture

Dynamic voting via an API requires a precise understanding of the poll's state machine:

  1. Target Attachment: The engine requires a valid messageId of a previously sent poll. This ensures the vote is anchored to the correct interactive context.

  2. Option Indexing: Wawp allows you to vote using either the literal string name of an option (e.g., "Awesome!") or its 0-indexed position within the poll. Our engine automatically resolves these to the internal binary IDs required by the WhatsApp network, preventing "Ghost Vote" errors.

  3. State Overwriting: WhatsApp follows an "Overwrite" model for voting. When you call this endpoint, your new votes array completely replaces your previous selection for that poll. If you send an empty array [], tips: [ { type: 'info', title: 'Mechanism', content: 'Casts a vote on an existing poll message.' }, { type: 'warning', title: 'Validation', content: 'Fails if the poll is closed or the option ID is invalid.' } ], recommendations: [ "Verify the Poll Message ID before attempting to vote.", "Use this for automated testing of poll workflows." ]

    your previous vote is retracted entirely.


🛡️ Strategic Best Practices for Bot Participation

1. Verification Before Voting

To ensure high reliability, your system should verify the poll exists and is still "active."

  • Implementation: Before voting, check your local database or use a listener to confirm the poll hasn't been deleted. Programmatically voting on a non-existent or expired poll will return a Message Not Found error.
  • Timing: Avoid voting immediately (within milliseconds) after a poll is created by another user. Adding a small delay (1–2 seconds) mimics natural processing time and ensures the poll has fully propagated across the WhatsApp WebSocket mesh.

2. Managing Multi-Answer Logic

The votes parameter is an array for a reason.

  • Checkboxes vs. Radio Buttons: If the original poll was created with multipleAnswers: true, your array can contain multiple indices (e.g., [0, 2]). If it was a single-choice poll, provided arrays with more than one element will typically result in only the last item being counted by the WhatsApp client UI.
  • UX Consistency: Ensure your bot's votes align with any previous text-based statements it made to avoid confusing human participants.

3. The Power of Selective Retraction

Programmatic voting allows for "Temporary Consensus."

  • Scenario: Your bot can vote for an option while it's "investigating" a problem, and then retract its vote or switch to a "Success" option once the investigation is complete. This provides a visual progress indicator that is much more subtle and professional than spamming the chat with status messages.

🧩 Advanced Use Cases

Automated Consensus Building

Build a "Moderator Bot" that monitors a group poll. Once a specific option reaches a threshold (e.g., 5 votes), the bot can cast its own vote for that option to "Seal the Deal" and then automatically trigger a coordination message or calendar invite.

Sentiment Re-alignment

In an AI-driven support flow, if a user starts a poll to rate their experience, the bot can programmatically vote for the "Neutral" option initially. As the conversation improves and sentiment analysis scores rise, the bot can update its vote to "Positive," providing the human agent with a visual cue of the AI's current assessment of the interaction.


🛠️ Common Pitfalls and Solutions

  • License Barriers: Ensure your instance is correctly provisioned before integrating programmatic voting into your production workflow.
  • Case Sensitivity: When voting via string names, ensured your strings match the poll options exactly (including case and trailing spaces). A mismatch will cause the vote to be ignored or return an error. Using Indices (integers) is the recommended best practice for high-reliability systems.
  • Race Conditions: If multiple instances of your bot attempt to update a vote on the same poll simultaneously, the last request received by the Wawp proxy will define the final state. Use a centralized queue or locking mechanism in your backend if you have multiple bot clusters interacting with the same chat.

Summary of Capabilities:

  • Programmatically cast, update, or retract votes on native WhatsApp polls.
  • Support for voting by literal option strings or numeric indices.
  • Exclusive for advanced automation and AI integration.
  • Full support for multi-choice (checkbox) and single-choice (radio) poll architectures.
  • Real-time synchronization with the WhatsApp network for instantaneous UI updates on recipient devices.

البارامترات

قم بتهيئة المعاملات المطلوبة للتفاعل مع نقطة النهاية هذه. جميع وسائط الاستعلام والبيانات مدرجة أدناه مع تفاصيلها.

محتوى الطلب

يرسل كـ JSON
string

Your unique WhatsApp Instance ID

مثال:
string

Your API Access Token

مثال:
string

Target phone number or group ID

مثال:
string

The unique ID of the poll message

مثال:
array

Array of selected option names or indices

مثال:

برمج بالذكاء الاصطناعي باستخدام Wawp MCP

MCP READY

قم بربط الـ API مباشرة مع Cursor أو Windsurf أو Claude Desktop، ودع الذكاء الاصطناعي يكتب لك كود الربط وينفذه تلقائياً!

طريقة الربط والإعداد

أمثلة الكود

استخدم أمثلة الكود الجاهزة لدمج واجهة برمجة التطبيقات (API) في مشروعك بسرعة وكفاءة. اختر لغة البرمجة والمكتبة التي تفضلها.

1const baseUrl = "https://api.wawp.net";
2const endpoint = "/v2/send/poll/vote";
3const params = new URLSearchParams({
4 "instance_id": "123456789",
5 "access_token": "123456789"
6}).toString();
7const body = {
8 "chatId": "201234567890@c.us",
9 "messageId": "ABC123456789",
10 "votes": [
11 "Awesome!"
12 ]
13};
14
15fetch(`${baseUrl}${endpoint}${params ? '?' + params : ''}`, {
16 method: "POST",
17 headers: { "Content-Type": "application/json" },
18 body: JSON.stringify(body)
19})
20 .then(async (response) => {
21 if (response.ok) {
22 const data = await response.json();
23 console.log("Success:", data);
24 return data;
25 }
26
27 // Error Handling
28 if (response.status === 400) {
29 console.error("Error 400: طلب غير صالح - معاملات مطلوبة مفقودة");
30 }
31 if (response.status === 400) {
32 console.error("Error 400: طلب غير صالح - الرقم المستهدف في قائمة الحظر الخاصة بك");
33 }
34 if (response.status === 400) {
35 console.error("Error 400: طلب غير صالح - المستلم قام بإلغاء الاشتراك تلقائياً");
36 }
37 if (response.status === 400) {
38 console.error("Error 400: Bad Request - Invalid Number (Egypt)");
39 }
40 if (response.status === 400) {
41 console.error("Error 400: Bad Request - Invalid Number (Saudi Arabia)");
42 }
43 if (response.status === 400) {
44 console.error("Error 400: Bad Request - Invalid Number (Unknown)");
45 }
46 if (response.status === 400) {
47 console.error("Error 400: طلب غير صالح (تنسيق XML)");
48 }
49 if (response.status === 400) {
50 console.error("Error 400: طلب غير صالح (نص عادي)");
51 }
52 if (response.status === 401) {
53 console.error("Error 401: غير مصرح - مفتاح الوصول غير صالح أو مفقود");
54 }
55 if (response.status === 401) {
56 console.error("Error 401: غير مصرح (تنسيق XML)");
57 }
58 if (response.status === 404) {
59 console.error("Error 404: غير موجود - الجلسة غير موجودة");
60 }
61 if (response.status === 404) {
62 console.error("Error 404: غير موجود (تنسيق XML)");
63 }
64 if (response.status === 429) {
65 console.error("Error 429: طلبات كثيرة جداً - تم تجاوز حد المعدل");
66 }
67 if (response.status === 500) {
68 console.error("Error 500: خطأ في الخادم الداخلي - فشل غير متوقع");
69 }
70 if (response.status === 500) {
71 console.error("Error 500: خطأ في الخادم الداخلي (HTML)");
72 }
73 if (response.status === 502) {
74 console.error("Error 502: بوابة غير صالحة - فشل الاتصال بالخادم الرئيسي");
75 }
76 if (response.status === 502) {
77 console.error("Error 502: بوابة غير صالحة (تنسيق XML)");
78 }
79
80 const errorText = await response.text();
81 console.error(`Error ${response.status}: ${errorText}`);
82 })
83 .catch((error) => console.error("Network Error:", error));
عينات تفاعلية
Ln 83, Col 1javascript

الردود المتوقعة

استكشف كافة الردود والنتائج المحتملة من الخادم. قمنا بتوثيق كل كود حالة (Status Code) مع أمثلة للبيانات لتسهيل معالجة الأخطاء والنجاح.

تم إرسال الرسالة بنجاح
النوع:
application/json
object *
string *
object *
number *
boolean *
string *
string *
number *
string *
string *
string *
boolean *
number *
boolean *
boolean *
boolean *
boolean *
boolean *
array *
array *
array *
boolean *
array *

Example

{
"_data": {
  "id": {
    "fromMe": true,
    "remote": "000000000000@c.us",
    "id": "MSG_ID_123456",
    "_serialized": "true_000000000000@c.us_MSG_ID_123456"
    },
  "viewed": false,
  "body": "BASE64_IMAGE_DATA",
  "type": "image",
  "t": 1759108866,
  "from": {
    "server": "c.us",
    "user": "111111111111",
    "_serialized": "111111111111@c.us"
    },
  "to": {
    "server": "c.us",
    "user": "000000000000",
    "_serialized": "000000000000@c.us"
    },
  "ack": 0,
  "isNewMsg": true,
  "star": false,
  "kicNotified": false,
  "caption": "Here's your requested image.",
  "deprecatedMms3Url": "https://example.com/media-url",
  "directPath": "/media/direct/path/example",
  "mimetype": "image/jpeg",
  "filehash": "FILE_HASH_PLACEHOLDER",
  "encFilehash": "ENC_FILE_HASH_PLACEHOLDER",
  "size": 192487,
  "mediaKey": "MEDIA_KEY_PLACEHOLDER",
  "mediaKeyTimestamp": 1759108865,
  "streamable": false,
  "mediaHandle": null,
  "isFromTemplate": false,
  "pollInvalidated": false,
  "isSentCagPollCreation": false,
  "latestEditMsgKey": null,
  "latestEditSenderTimestampMs": null,
  "mentionedJidList": {
    },
  "groupMentions": {
    },
  "isEventCanceled": false,
  "eventInvalidated": false,
  "isVcardOverMmsDocument": false,
  "isForwarded": false,
  "isQuestion": false,
  "questionReplyQuotedMessage": null,
  "questionResponsesCount": 0,
  "readQuestionResponsesCount": 0,
  "labels": {
    },
  "hasReaction": false,
  "disappearingModeInitiator": "chat",
  "disappearingModeTrigger": "chat_settings",
  "productHeaderImageRejected": false,
  "lastPlaybackProgress": 0,
  "isDynamicReplyButtonsMsg": false,
  "isCarouselCard": false,
  "parentMsgId": null,
  "callSilenceReason": null,
  "isVideoCall": false,
  "callDuration": null,
  "callCreator": null,
  "callParticipants": null,
  "isCallLink": null,
  "callLinkToken": null,
  "isMdHistoryMsg": false,
  "stickerSentTs": 0,
  "lastUpdateFromServerTs": 0,
  "invokedBotWid": null,
  "bizBotType": null,
  "botResponseTargetId": null,
  "botPluginType": null,
  "botPluginReferenceIndex": null,
  "botPluginSearchProvider": null,
  "botPluginSearchUrl": null,
  "botPluginSearchQuery": null,
  "botPluginMaybeParent": false,
  "botReelPluginThumbnailCdnUrl": null,
  "botMessageDisclaimerText": null,
  "botMsgBodyType": null,
  "requiresDirectConnection": false,
  "bizContentPlaceholderType": null,
  "hostedBizEncStateMismatch": false,
  "senderOrRecipientAccountTypeHosted": false,
  "placeholderCreatedWhenAccountIsHosted": false,
  "galaxyFlowDisabled": false,
  "links": {
    }
  },
"mediaKey": "MEDIA_KEY_PLACEHOLDER",
"id": {
  "fromMe": true,
  "remote": "000000000000@c.us",
  "id": "MSG_ID_123456",
  "_serialized": "true_000000000000@c.us_MSG_ID_123456"
  },
"ack": 0,
"hasMedia": true,
"body": "Here's your requested image.",
"type": "image",
"timestamp": 1759108866,
"from": "111111111111@c.us",
"to": "000000000000@c.us",
"deviceType": "android",
"isForwarded": false,
"forwardingScore": 0,
"isStatus": false,
"isStarred": false,
"fromMe": true,
"hasQuotedMsg": false,
"hasReaction": false,
"vCards": {
  },
"mentionedIds": {
  },
"groupMentions": {
  },
"isGif": false,
"links": {
  }
}
طلب غير صالح - معاملات مطلوبة مفقودة
غير مصرح - مفتاح الوصول غير صالح أو مفقود
غير موجود - الجلسة غير موجودة
طلبات كثيرة جداً - تم تجاوز حد المعدل
خطأ في الخادم الداخلي - فشل غير متوقع
بوابة غير صالحة - فشل الاتصال بالخادم الرئيسي
الموضوع السابقإرسال استطلاع رأي (Poll)
الموضوع التاليإرسال بطاقة جهة اتصال (vCard)

Command Palette

Search for a command to run...