Message Customization
Chat SDK supports fully custom message types. To enable this, several steps are required.
Define a new message type
Make a way to send the message
Add UI to send the message
Display the message in the chat view controller
1. Message type
The message type is an integer which should be unique. You can look at the PMessage
.h to see which message types are already in use. It would be safe to use a type over 100.
You can define your message type as an enum or using #define
.
2. Hook into chat options to send the message
In the chat view controller, there is a plus button that shows a list of options when clicked. This can be useful as a way to send custom messages.
To do this, subclass BChatOption
and implement the functions:
Here you can return an optional icon, a title and there is a function that is executed when the option is selected. You also have access to the view controller which allows you to present a custom view controller if necessary.
Register this option with the framework after Chat SDK initialization
3. Send the message
oThe message can be sent like this. The most important thing is that it has the message type and the ID of the thread you want it to be sent to. You can also assign custom meta values to the message. These will be serialized and sent with the message.
4. Render the message
First, you need to make a custom table view cell by subclassing BMessageCell
. There are some important functions you can override to customize the cell:
You can use the setMessage
function to bind the message to your cell contents. You can also specify a custom contents view using cellContentView
. The width and height of the cell are specified using static override functions. Look at BMessageCell.h
for more details.
The final step is to bind this cell type to your message type. After Chat SDK initialization add the following code:
Last updated