Skip to main content

Post Poll Conversation

The postPollConversation() method allows you to post a poll in a chatroom, either as a new conversation or as a reply. It requires a variety of parameters, including the chatroom ID, poll options, and additional configuration like anonymity and the expiry time.

Steps to Post a Poll Conversation

  1. Create a PostPollConversationRequest object using the builder pattern, providing the necessary parameters such as the chatroomId, text (poll text), polls (list of poll options), and other optional parameters like repliedConversationId, multipleSelectState, etc.
  2. Call the postPollConversation() function using the LMChatClient instance.
  3. Use the LMResponse<PostConversationResponse> to retrieve the conversation details, including the poll that was posted.
PostPollConversationRequest request = (PostPollConversationRequestBuilder()
..chatroomId("ENTER_CHATROOM_ID") // Provide the chatroom ID
..text("ENTER_POLL_QUESTION") // Provide the poll text
..polls([PollOption('Option 1'), PollOption('Option 2')]) // Provide poll options
..pollType(1) // Specify poll type
..isAnonymous(true) // Anonymize the poll
..allowAddOption(false) // Disable adding options
..expiryTime(3600) // Set expiry time for the poll
..temporaryId('temp123')) // Provide temporary ID for the poll
.build();

final LMResponse<PostConversationResponse> response =
await lmChatClient.postPollConversation(request);

if (response.success) {
// Handle the posted poll conversation
Conversation postedConversation = response.data?.conversation ?? Conversation();
handlePostedConversation(postedConversation);
} else {
// Handle error
handleError(response);
}
tip

Ensure that polls, chatroomId, text, and pollType are set before sending a request to post a poll.

Models

PostPollConversationRequest

List of parameters for the PostPollConversationRequest class:

VariableTypeDescriptionOptional
chatroomIdintThe ID of the chatroom where the poll will be posted
textStringThe poll text to be posted
stateintThe state of the poll (e.g., active, closed)
repliedConversationIdString?ID of the conversation being replied to✔️
pollsList<PollOption>List of poll options
pollTypeintThe type of poll (e.g., single choice, multiple choice)
multipleSelectStateint?The state of multiple selection (if applicable)✔️
multipleSelectNoint?The number of options allowed for multiple selection✔️
isAnonymousboolWhether the poll is anonymous
allowAddOptionboolWhether new options can be added to the poll
expiryTimeintThe expiry time for the poll
temporaryIdStringTemporary ID for the poll
noPollExpirybool?Whether the poll has no expiry✔️
allowVoteChangebool?Whether users can change their vote✔️

PostConversationResponse

List of parameters for the PostConversationResponse class:

VariableTypeDescriptionOptional
conversationConversationThe conversation object for the posted poll✔️
idintThe ID of the posted conversation✔️