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
- Create a
PostPollConversationRequest
object using the builder pattern, providing the necessary parameters such as thechatroomId
,text
(poll text),polls
(list of poll options), and other optional parameters likerepliedConversationId
,multipleSelectState
, etc. - Call the
postPollConversation()
function using theLMChatClient
instance. - 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:
Variable | Type | Description | Optional |
---|---|---|---|
chatroomId | int | The ID of the chatroom where the poll will be posted | |
text | String | The poll text to be posted | |
state | int | The state of the poll (e.g., active, closed) | |
repliedConversationId | String? | ID of the conversation being replied to | ✔️ |
polls | List<PollOption> | List of poll options | |
pollType | int | The type of poll (e.g., single choice, multiple choice) | |
multipleSelectState | int? | The state of multiple selection (if applicable) | ✔️ |
multipleSelectNo | int? | The number of options allowed for multiple selection | ✔️ |
isAnonymous | bool | Whether the poll is anonymous | |
allowAddOption | bool | Whether new options can be added to the poll | |
expiryTime | int | The expiry time for the poll | |
temporaryId | String | Temporary ID for the poll | |
noPollExpiry | bool? | Whether the poll has no expiry | ✔️ |
allowVoteChange | bool? | Whether users can change their vote | ✔️ |
PostConversationResponse
List of parameters for the PostConversationResponse
class:
Variable | Type | Description | Optional |
---|---|---|---|
conversation | Conversation | The conversation object for the posted poll | ✔️ |
id | int | The ID of the posted conversation | ✔️ |