Extension settings
- Login to CometChat and select your app.
- Go to the Extensions section and enable the Polls extension.
How do polls work?
Polls extension has the following 3 parts:- Creating a poll by submitting a question along with the possible options.
- Voting in a poll.
- Fetching the results for a particular poll.
1. Creating a Poll
In order to create a poll, you need to submit the following details:- Question
- Array of options
- Receiver (UID/GUID)
- Receiver type (user/group)
callExtension
method provided by our SDKs:

2. Receiving a poll
Polls are custom messages. So, you have to implement ouronCustomMessageReceived
listener in order to receive the Poll-related message. Please refer to our Receive Messages documentation under the SDK of your choice.
The metadata
stores all the information about the poll. You will find the following details in metadata
-> @injected
-> extensions
-> polls
.
Key | Value |
---|---|
id | A String representing a unique ID for the poll. |
options | An Object with the option number as the key and the option description as the value. |
question | A string representing the question asked in the poll. |
results | An object that stores voting results. |
metadata
will also contain incrementUnreadCount
with value as true
. This will be useful for incrementing the unread count every time a poll is received.
3. Voting in a poll
Voting in a poll simply requires you to provide theid
of the poll and the option you intend to vote for. The vote
parameter is basically the option number.
You can allow users to vote for a poll by using the callExtension
method provided by our SDKs:


4. Getting Results
There are 2 ways to fetch the results of the poll:- Real-time updates from the
metadata
- Fetch the results by using the
callExtension
method.
Real-time updates
As mentioned earlier, a Poll is a message of the category:custom
. When the votes are cast by the users, the metadata for the message will be updated accordingly. To get real-time voting information, you need to implement the onMessageEdited
listener. Please check our Edit message documentation under the SDK of your choice.
The updated details will be available in the metadata of the message. Here is a sample response:
Using callExtension() method
For fetching results, the only parameter required is the id of the poll. You can use this method only when you are the creator of the poll. Others cannot call this method to get the poll results. Result for a poll can be fetched using acallExtension
method provided by our SDKs: