The Polls feature provides a comprehensive API that enables seamless integration of polling capabilities within your application, enhancing engagement and interaction among users. Through this API, developers can effortlessly create, manage, and utilize polls as part of messages, gather user opinions, and make informed decisions based on real-time feedback.

Key Features Include:

Copied!
  • Easy Poll Creation and Configuration: Developers can create polls with customizable options, descriptions, and configurations, including setting voting visibility (public or anonymous), enforcing unique votes, and specifying the maximum votes a user can cast. Polls can also be designed to allow user-suggested options or open-ended answers, providing flexibility in how you engage with your audience.

  • Seamless Integration with Messages: Once created, polls can be sent as part of messages, allowing for a seamless user experience. Users can view poll details and participate directly within the context of a conversation.

  • Dynamic Poll Management: Polls are not static. You can update poll details, add or modify options, and even close polls to further responses. These actions can be performed through full or partial updates, giving you control over the poll's lifecycle.

  • Robust Voting System: Users can cast votes on options or provide answers to open-ended questions, with the API supporting both single and multiple choice responses. Votes can be changed or removed, ensuring users' opinions are accurately captured.

  • Comprehensive Query Capabilities: Retrieve detailed information about polls and votes based on various criteria, including poll status, creation time, and user responses. This enables developers to implement rich, data-driven features in their applications.

  • Customizability and Extensibility: In addition to predefined poll properties, the API supports custom properties, allowing developers to tailor polls and options to their specific needs while maintaining performance and scalability.

Polls is currently in beta and as such by default not enabled. Please reach out to customer support to have polls enabled on your account in order to try it out.
Polls is currently available as an API and in the JS / Node.js SDK. Support for other SDKs is planned for later this year.

APIs

Copied!

Creating a poll and sending it as part of a message

Copied!

Creating a poll is easy. You simply create a poll with your desired configuration, and once created, you send a message with the poll id.

Please take into account that the poll can be sent only by the user who created it in the first place.

When creating a poll, the following properties can be configured:

nametypedescriptiondefaultoptional
namestringThe name of the poll-
descriptionstringThe description of the poll-
voting_visibilityenumDesignates whether the votes are casted anonymouslypublic
enforce_unique_votebooleanDesignates whether the poll is multiple choice or single choicefalse
max_votes_allowednumber

Designates how many votes a single user is allowed to cast on a poll. Allowed value is in range from 1 to 10. If null, no limits applied.

null

allow_user_suggested_options

boolean

Designates weather user can add custom options to the poll

false

allow_answers

boolean

Designates whether user can add an answer to the poll. Max 1 answer is allowed. This is for open ended polls.

false
is_closedboolean

Whether the poll is closed for voting or not

false

options

array of poll option objects

One or more options users can vote on. See below for more information on poll options

-

Poll options

Copied!
nametypedescriptiondefaultoptional
textstring

The text of the poll option

-

Besides the above mentioned properties, it is also possible to supply your own custom properties for both polls and options:

The total size of all custom properties on a poll cannot exceed 5KB.

Example poll response as part of a message:

Copied!
The latest_votes_by_option will contain at most the 10 latest votes for that particular option.

Casting a vote

Copied!

Once a poll has been send as part of a message (and as long as the poll isn’t closed for voting). Votes can be casted

Send vote on option

Copied!

Send an answer (if answers are configured to be allowed)

Copied!

Few points to note here:

Copied!
  • If enforce_unique_votes is set to true on poll, then any vote casted on option will replace the previous vote. Also this api will broadcast an event:

    • poll.vote_changed if enforce_unique_votes is true

    • Otherwise poll.vote_casted event will be broadcasted

  • Adding an answer will always replace the previous answer. This ensures that user can add maximum 1 answer (similar to what Polly app has)

  • You need CastVote permission to be able to cast a vote

  • API will return an error if poll is not attached to a message.

Removing a vote

Copied!

A vote can be removed as well:

Closing a poll

Copied!

If you want to prevent any further votes on a poll, you can close a poll for voting:

Retrieving a poll

Copied!

If you know the id of a poll you can easily retrieve the poll by using the getPoll method. If you don’t know the id or if you want to retrieve multiple polls, use the query polls method (see below)

Updating a poll

Copied!

There are two ways to update a poll: a full poll update and a partial update.

Full update:

Copied!
All the poll properties that are omitted in the update request will either be removed or set to their default values.

Partial update:

Copied!

Deleting a poll

Copied!

Deleting a poll removes the poll, its associated options as well as all the votes on that poll. Be aware that removing a poll can’t be undone.

Adding, updating and deleting poll options

Copied!

Poll options can be added, updated or deleted after a poll has been created:

Add poll option

Copied!
If allow_user_suggested_options is set to true on poll, then user only needs CastVote permission to access this endpoint. Otherwise user needs UpdatePoll permission.

Update poll option

Copied!

Delete poll option

Copied!

Querying votes

Copied!

You are able to query the votes on a poll:

Votes Queryable Built-In Fields

Copied!

Name

Type

Description

Supported operators

Example

id

string or list of strings

the ID of the vote

$in, $eq

{

id: { $in: [ 'abcd', 'defg' ] }

}

user_id

string or list of strings

the ID of the user who casted the vote

$in, $eq

{

$user_id: { $eq: 'abcd' }

}

created_at

string, must be formatted as an RFC3339 timestamp

the time the vote was created

$eq, $gt, $lt, $gte, $lte

{

created_at: {

$gte: '2023-12-04T09:30:20.45Z'

}

}

is_answer

boolean

whether or not the vote is suggested by the user

$eq

{

is_answer: { $eq: true }

}

option_id

string or list of strings

The ID of the option the vote was casted on

$in, $eq, $exists

{

option_id: {

$in: [ 'abcd', 'defg' ]

}

}

Querying polls

Copied!

It is also possible to query for polls based on certain filter criteria:

Poll Queryable Built-In Fields

Copied!

Name

type

Description

Supported operations

Example

id

string or list of strings

the ID of the vote

$in, $eq

{ id: { $in: [ 'abcd', 'defg' ] } }

poll_id

string or list of strings

the ID of the poll

$in, $eq

{ poll_id: { $in: [ 'abcd', 'defg' ] } }

name

string or list of strings

the ID of the user who casted the vote

$in, $eq

{ name: { $eq: 'abcd' } }

voting_visibility

string

indicates whether the votes are casted anonymously

$eq

{ voting_visibility: { $eq: 'anonymous' } }

max_votes_allowed

number

the maximum amount of votes per user

$eq, $ne, $gt, $lt, $gte, $lte

{ max_votes_allowed: { $gte: 5 } }

allow_user_suggested_options

boolean

indicates whether the poll allows user suggested options

$eq

{ allow_user_suggested_options: { $eq: false } }

allow_answers

boolean

indicates whether the poll allows user answers

$eq

{ allow_answers: { $eq: false } }

is_closed

boolean

indicates whether the poll is closed for voting

$eq

{ is_closed: { $eq: true } }

created_at

string, must be formatted as an RFC3339 timestamp

the time the poll was created

$eq, $gt, $lt, $gte, $lte

{ created_at: {$gte: ‘2023-12-04T09:30:20.45Z’ }

updated_at

string, must be formatted as an RFC3339 timestamp

the time the poll was updated

$eq, $gt, $lt, $gte, $lte

{ updated_at: {$gte: ‘2023-12-04T09:30:20.45Z’ }

created_by_id

string or list of strings

the ID of the user who created the poll

$in, $eq

{ id: { $in: [ 'abcd', 'defg' ] } }

Events

Copied!

The following websocket events will be emitted:

  • poll.updated whenever a poll (or its options) gets updated.

  • poll.closed whenever a poll is closed for voting.

  • poll.deleted whenever a poll gets deleted.

  • poll.vote_casted whenever a vote is casted.

  • poll.vote_removed whenever a vote is removed.

  • poll.vote_changed whenever a vote is changed (case of enforce_unique_vote as true)

Poll updated event

Copied!

Poll closed event

Copied!

Poll deleted event

Copied!

Vote casted event

Copied!

Vote removed event

Copied!

Vote changed event

Copied!

Permissions

Copied!

The following permissions can be configured to allow or disallow certain actions on Polls:

App permissions

Copied!
  • CreatePoll allows or disallows a user to create polls.

  • UpdatePoll allows or disallows a user to update polls.

  • DeletePoll allows or disallows a user to delete polls.

  • ClosePoll allows or disallows a user to close a poll.

  • QueryPolls allows or disallows a user to query polls.

Channel permissions:

Copied!
  • SendPoll allows or disallows a user to send a poll as part of a message.

  • CastVote allows or disallows a user to cast vote(s) on a poll.

  • QueryVotes allows or disallows a user to query the vote(s) on a poll.