Creating Poll Object

I am trying to create a Poll Object for specific Group Channels. I read the documentation below about creating a poll object, but I am confused about how to actually attach it to a specific group channel. It keeps saying that it needs to be sent as a regular Text message and not a file or admin message, but I dont see any field for the text messages where I could specify the poll ID or some other way to link it.

Hi @PatrickAzul !

Thanks for trying out. You can attach Poll (its id) as a param in the message object. You can find the Android reference here. For other platforms, we will soon update the snippets.

In a nutshell, you can include pollId in the messageParams and include it in the sendUserMessage . Let me know if this helps!

Hello @sangha !
Thank you! That did help! I am now able to create the poll object, and to create a message object with the poll id attached. The issue that I am having now is that even when I send the message with the poll ID, I am not seeing the poll actually appearing in the Sendbird Dashboard for that channel or in the chat on my IOS device using UIKit. I attached the response below, and it is showing that it created a message with the poll credentials, but it isnt showing the different options at all.

{‘type’: ‘MESG’, ‘message_id’: 6961637587, ‘message’: ‘Does the poll functionality work?’, ‘data’: “{‘font-size’: ‘24px’, ‘font-weight’: ‘bold’}”, ‘custom_type’: ‘’, ‘file’: {}, ‘created_at’: 1670516282256, ‘user’: {‘user_id’: ‘OMITTED’, ‘profile_url’: ‘OMITTED’, ‘require_auth_for_profile_image’: False, ‘nickname’: ‘Bot’, ‘metadata’: {}, ‘role’: ‘’, ‘is_active’: True}, ‘channel_url’: ‘CHANNEL_ID_THAT I OMITTED’, ‘updated_at’: 0, ‘message_survival_seconds’: -1, ‘mentioned_users’: , ‘mention_type’: ‘users’, ‘silent’: False, ‘message_retention_hour’: -1, ‘poll’: {‘id’: 101, ‘title’: ‘TESTING’, ‘allow_user_suggestion’: False, ‘allow_multiple_votes’: False, ‘_details_included’: True, ‘voter_count’: 0, ‘status’: ‘open’, ‘options’: [{‘id’: 305, ‘text’: ‘Yes’, ‘created_by’: ‘319991’, ‘poll_id’: 101, ‘vote_count’: 0, ‘created_at’: 1670516281, ‘updated_at’: 1670516281}, {‘id’: 306, ‘text’: ‘No’, ‘created_by’: ‘319991’, ‘poll_id’: 101, ‘vote_count’: 0, ‘created_at’: 1670516281, ‘updated_at’: 1670516281}, {‘id’: 307, ‘text’: ‘Maybe’, ‘created_by’: ‘319991’, ‘poll_id’: 101, ‘vote_count’: 0, ‘created_at’: 1670516281, ‘updated_at’: 1670516281}], ‘created_by’: ‘319991’, ‘close_at’: -1, ‘message_id’: 6961637587, ‘created_at’: 1670516281, ‘updated_at’: 1670516281}, ‘channel_type’: ‘group’, ‘translations’: {}, ‘is_removed’: False, ‘is_op_msg’: False, ‘message_events’: {‘send_push_notification’: ‘receivers’, ‘update_unread_count’: True, ‘update_mention_count’: True, ‘update_last_message’: True}}

Hi @PatrickAzul ! When you create a poll, the poll does not automatically generate a new UI layout. Therefore, it isn’t appearing on your IOS device.

Once you create a poll, the user message will contain poll data. With this information, you can check if the user message contains ‘poll’, then render a custom component with your own UI design.

Please note, polls will be added to the dashboard in the near future.

Lastly, I see that the response you received does include an ‘options’ array that holds your option objects.

Let me know if you have any other questions!

Thank you! That helps me a lot! Have a great day!

Hello again @Michelle_Wong
Is there any documentation for hooking into the onMessageReceive() function for UIKit for IOS ( or something similar)? I have been going through the documentation to try and find the method that I can override so that it can scan the incomming message to see if it contains “poll_id” so I can create the custom UI Design for the poll messages, but UIKit doesnt seem to have the documentation for that. Can you help me with hooking into where the messages would be read and how I should override the messages to allow for me to read the poll objects?

Hi @PatrickAzul - The documentation for polls can be found here.

A similar scenario using UIKit for React is when you use the Channel component, which renders the group channel, use its renderMessage property and pass in a custom component. renderMessage returns the message and determines how you display each message that is passed in the channel. Within the custom component, you can do a check to see if the message (that is being passed in from renderMessage) contains “poll_id”, if so, return the custom UI design for a poll.

A sample of this will be public within the next few days! I hope this helps!

@Michelle_Wong
Thank you so much! That will help tremendously! Do you know if that sample will be live in the Github repository when it is released? Also, can you please respond in this thread when that sample is live?

@PatrickAzul No problem! Yes, the sample will be live when it is released. I will be sure to respond in this thread when it is live!

@Michelle_Wong @sangha

I managed to create a custom Message type for UserMessages that will show when the message contains a poll object. (All of this in SendbirdUIKit since I need the format that is provided by it)

I am currently displaying the different poll options onto the screen in the specific message type. The problem that I am having is with reporting the option that the user clicked on/selected. I know that SendbirdUIKit has a method called baseChannelModule(_ listComponent: SBUBaseChannelModule.List, didReactToMessage message: BaseMessage, withEmoji key: String, selected: Bool) to send the emoji results to the server, is there any way that I could do something similar for the poll option that the user clicked on?

I did take a look at the Github below that has a working example of how to implement Poll Messages for SendbirdChat, but the UI seems to be completely barebones and I need the UI that is provided in UIKit. Additionally, the structure of the files and the functionality used in this example seems to be completely different from what is in UIKit. An example is in GroupChannelViewController+PollEvents where the pollUseCase method refes to messages.first which is very clearly not in UIKit since all of the messages is in listcomponent