Skip to main content

Create Poll

LikeMinds Chat SDK Poll Features enables you to engage your users, to create and participate in polls right within your in-app community. The "Create Poll" method allows you to empower your users to craft their own polls with customized questions and response options. You can integrate the above by following the given steps.

Steps to Create Poll

  1. To create a poll, use the postPollConversation() method provided by the client.
  2. Pass in the required parameters to define the poll question and options.
  3. Process the response as per your requirement.
const payload = {
chatroomId: 89899, // The id of the chatroom where the conversation takes place.
text: "", // The title or main question for the conversation.
expiryTime: 1627700575500, // Time in epoch format when the poll will expire.
pollType: 0, // The type of poll, it can be "0 | 1".
isAnonymous: false, // Determines if the poll is anonymous (true/false).
allowAddOption: false, // Determines if participants can add their own options to the poll (true/false).
polls: [
{
text: "", // The text representing a poll option.
},
],
state: 10, // The state 10 signifies that the conversation is a poll .
};

const response = await lmChatClient.postPollsConversation(payload);

if (response.success) {
// your function to process the response data
processResponse(response);
} else {
// your function to process error message
processError(response);
}
note

Poll type can be 0 or 1

  • 0 refers to Instant Poll
  • 1 refers to Deferred Poll.

Create Poll Payload

VariableTypeDescriptionOptional
chatroomIdnumberChatroom Id.
textstringThe title/question for the poll.
expiryTimenumberTime in epoch format when the poll expires.
pollTypenumnberType of poll
- 0 for Instant Poll
- 1 for Deferred Poll
isAnonymousbooleanIndicates if the poll responses are anonymous.
allowAddOptionbooleanAllows users to add options to the poll.
pollsArray of objectsAn array of poll options.
statenumberState of the poll.
multipleSelectStatenumberState of multiple-choice poll:
- 0 for Exactly
- 1 for At max
- 2 for At least.
multipleSelectNonumberNumber of options that can be selected (used with multipleSelectState).

Create Poll Response

List of parameters in the response.

VariableTypeDescriptionOptional
successbooleanAPI success status
error_messagestringError message in case of failure✔️
conversationobjectPoll Conversation object✔️