Message actions
In this section we will review what actions we can take to modify the message state.
Mark as received
When your app receives a message the sdk is marking it as received by default. This behavior can be changed by modifying passing a specific parameter to on_message, at the same time you can mark a message as read on your convenience, let’s see how.
@app.chat.on_message mark_as_delivered: false do |msg|
msg.mark_as_delivered # explicitly mark the message as delivered
end
client.ChatService().OnMessage(func(cm *chat.Message) {
cm.MarkAsDelivered()
}, chat.OnMessageOptions{ MarkAsDelivered: false })
sdk.chat().OnMessage(async (cm: ChatMessage) => {
cm.markAsDelivered()
}, { 'mark_as_delivered': false })
Default behavior for on_message is to mark the message as received as soon as it’s received.
Mark as read
Similarly to the previous example, you can modify on_message to automatically mark all messages as read with a specific option.
@app.chat.on_message mark_as_read: true do |msg|
# ...
end
client.ChatService().OnMessage(func(cm *chat.Message) {
// ...
}, chat.OnMessageOptions{ MarkAsRead: true })
sdk.chat().OnMessage(async (cm: ChatMessage) => {
// ...
}, { 'mark_as_read': true })
Additionally you can explicitly mark a received message as read with your own logic.
@app.chat.on_message do |msg|
msg.mark_as_read
end
client.ChatService().OnMessage(func(cm *chat.Message) {
cm.MarkAsRead()
})
sdk.chat().OnMessage(async (cm: ChatMessage) => {
cm.MarkAsRead()
})
Edit
For a message you’ve already sent you can modify its body.
m = @app.chat.message user, "one"
m.edit "two"
m := @app.chat.message user, "one"
m.Edit("two")
let m = @app.chat.message user, "one"
m.Edit("two")
You’re only allowed to modify your own messages.
Delete
Deleting a message is as simple as modifying it, but using delete
method instead.
m = @app.chat.message user, "one"
m.delete
m := @app.chat.message user, "one"
m.Delete()
let m = @app.chat.message user, "one"
m.Delete()
You’re only allowed to delete your own messages.