This section shows how to add custom data in messages globally across the application. You can use the SendbirdUIKit.setCustomParamsHandler method to gather all events prior to the message being sent. The properties of each class that gets passed to the handler can be checked in this params reference. It's recommended to register the event handler in the onCreate() method of the Application. Global custom params, when declared, have a lower priority than those declared within a fragment.
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
SendbirdUIKit.setCustomParamsHandler(object : CustomParamsHandler {
override fun onBeforeSendUserMessage(params: UserMessageCreateParams) {
// Edit UserMessageCreateParams here.
}
override fun onBeforeSendFileMessage(params: FileMessageCreateParams) {
// Edit FileMessageCreateParams here.
}
override fun onBeforeUpdateUserMessage(params: UserMessageUpdateParams) {
// Edit UserMessageUpdateParams here.
}
override fun onBeforeSendMultipleFilesMessage(params: MultipleFilesMessageCreateParams) {
// Edit MultipleFilesMessageCreateParams here.
}
})
}
}
This section shows how to add custom data to messages in a specific fragment. You can use custom parameters only for specific channels by inhering and implementing a Fragment. The custom implementations declared within a fragment have a higher priority than the global settings.
class MessageDataSampleFragment : ChannelFragment() {
override fun onBeforeSendUserMessage(params: UserMessageCreateParams) {
// Edit UserMessageCreateParams here.
}
override fun onBeforeSendFileMessage(params: FileMessageCreateParams) {
// Edit FileMessageCreateParams here.
}
override fun onBeforeUpdateUserMessage(params: UserMessageUpdateParams) {
// Edit UserMessageUpdateParams here.
}
override fun onBeforeSendMultipleFilesMessage(params: MultipleFilesMessageCreateParams) {
// Edit MultipleFilesMessageCreateParams here.
}
}
For an in-depth practical demonstration, see our sample code.