/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Cast or cancel a vote

Copy link

You can cast or cancel a vote by passing the pollIds and pollOptionIds parameters in the votePoll() method. Use the pollOptionIds property of the votePoll() method to update the user's final vote choice for a poll. This overrides previous vote actions, so to update previous votes, pass new pollOptionIds as a parameter. To cancel votes, pass an empty list as pollOptionIds.

JavaScriptTypeScript
const event = await channel.votePoll(pollId, pollOptionIds);

The votePoll() method returns a PollVoteEvent object. If you are using a message collection, no further action needs to be taken. However, if you are not a using message collection, then you need to apply this event to the poll by implementing the code below.

JavaScriptTypeScript
poll.applyPollVoteEvent(pollVoteEvent);