Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Message
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Cast or cancel a vote

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.

const event: PollVoteEvent = 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.

poll.applyPollVoteEvent(pollVoteEvent);