Post Poll Conversation
Creates a new poll conversation in a chatroom. This function allows posting a poll with various settings such as poll type, multiple select options, anonymous voting, and expiration time. The function returns a response containing the created conversation details.
Steps to post a poll conversation
- Create a PostPollConversationRequest object using the builder pattern.
- Call the
postPollConversation()
function using the instance ofLMChatClient
, passing therequest
object and an optional response handler. - Process the response LMResponse<PostPollConversationResponse> to handle the created poll conversation or any errors.
let request = PostPollConversationRequest.builder()
.chatroomId("ENTER_CHATROOM_ID")
.text("YOUR_TEXT")
.polls([Poll(question: "Feature 1"), Poll(question: "Feature 2")])
.pollType(1)
.isAnonymous(true)
.allowAddOption(false)
.expiryTime(86400) // 1 day in seconds
.build()
PollClient.shared.postPollConversation(request: request) { response in
if let result = response?.data {
// Handle success
print("Poll conversation created: \(result.conversation?.id ?? "N/A")")
} else if let error = response?.error {
// Handle error
print("Error posting poll conversation: \(error.localizedDescription)")
}
}
Models
PostPollConversationRequest
VARIABLE | TYPE | DESCRIPTION | OPTIONAL |
---|---|---|---|
chatroomId | String | ID of the chatroom where the poll conversation is posted | |
text | String | The poll question or prompt | |
repliedConversationId | String? | ID of the conversation this poll is replying to (if any) | ✔️ |
polls | [Poll] | Array of poll options for the conversation | |
pollType | Int | Type of poll (e.g., single or multiple choice) | |
multipleSelectState | Int? | State for multiple select options | ✔️ |
multipleSelectNo | Int? | Number of options users can select if multiple choice | ✔️ |
isAnonymous | Bool | Whether the poll is anonymous | |
allowAddOption | Bool | Whether users can add their own poll options | |
expiryTime | Int | Expiration time of the poll in seconds | |
temporaryId | String? | Temporary ID for the poll conversation | ✔️ |
state | Int | State of the conversation (default is active) |
PostPollConversationResponse
VARIABLE | TYPE | DESCRIPTION | OPTIONAL |
---|---|---|---|
id | String? | ID of the created poll conversation | ✔️ |
conversation | Conversation? | The full conversation object created with the poll | ✔️ |