How to Send and Receive Message Events
Product deprecation notice
Effective April 30th, 2026, Vonage In-App Messaging will no longer be available. Access for new users will be closed, and the service will be discontinued for all existing users.
If you have any questions regarding this product’s discontinuation, please contact your account manager or our support team.
This guide covers how to send and receive Message Events with the Vonage Client SDK. Before you begin, make sure you added the SDK to your app, created a Session (Android, iOS, JS), and joined a Conversation.
Sending Message Text Events
Given a Conversation ID, you can send a Text Message Event.
client.sendMessageTextEvent(conversationId, "Hi Vonage!")
.then(timestamp => {
console.log("Successfully sent text message at ", timestamp);
}).catch(error => {
console.error("Error sending text message: ", error);
});
client.sendMessageTextEvent("CONV_ID", "Hello world!") { error, timestamp ->
error?.takeIf { it is VGError }?.let {/* Handle Vonage Error */ } ?:
error?.let {/* Handle generic Error */ }
timestamp?.let { /* Message sent at timestamp */ }
}
Sending Message Image Events
Given a Conversation ID and URL for an image, you can send an Image Message Event.
client.sendMessageImageEvent(conversationId, imageURL)
.then(timestamp => {
console.log("Successfully sent image message at ", timestamp);
}).catch(error => {
console.error("Error sending image message: ", error);
});
client.sendMessageImageEvent("CONV_ID", URL("MY_IMAGE_URL")) { error, timestamp ->
error?.takeIf { it is VGError }?.let {/* Handle Vonage Error */ } ?:
error?.let {/* Handle generic Error */ }
timestamp?.let { /* Message sent at timestamp */ }
}
Sending Message Custom Events
Along with a Conversation ID, you can send a completely custom payload as a Custom Message Event. This is useful if you want a Message Event type that is specific to your application.
const attachmentPayload = {
key1: "value 1",
key2: "value 2"
};
client.sendMessageCustomEvent(conversationId, attachmentPayload)
.then(timestamp => {
console.log("Successfully sent custom message at ", timestamp);
}).catch(error => {
console.error("Error sending custom message: ", error);
});
client.sendMessageCustomEvent("CONV_ID", "MY_CUSTOM_DATA") { error, timestamp ->
error?.takeIf { it is VGError }?.let {/* Handle Vonage Error */ } ?:
error?.let {/* Handle generic Error */ }
timestamp?.let { /* Message sent at timestamp */ }
}
Receiving Message Events
You can receive all Conversation Message Events in your application by setting up an Event Listener/Delegate Function. Message Events received via this Listener/Delegate will automatically be updated to the delivered state. Here you can check the kind of incoming Message Event.
client.on("conversationEvent", event => {
switch (event.kind) {
case "message:text":
handleTextMessage(event);
break;
case "message:image":
handleImageMessage(event);
break;
case "message:custom":
handleCustomMessage(event);
break;
};
});
client.setOnConversationEventListener {
when(it) {
is MessageCustomEvent -> {} // Handle Message Custom
is MessageImageEvent -> {} // Handle Message Image
is MessageTextEvent -> {} // Handle Message Text
}
}
Marking Message Events as Seen
Once you have received a Message Event, you can mark it as seen.
client.sendMessageSeenEvent(eventId, conversationId)
.then(timestamp => {
console.log("Successfully sent seen event at ", timestamp);
}).catch(error => {
console.error("Error sending seen event: ", error);
});
client.sendMessageSeenEvent("EVENT_ID", "CONV_ID") { error, timestamp ->
error?.takeIf { it is VGError }?.let {/* Handle Vonage Error */ } ?:
error?.let {/* Handle generic Error */ }
timestamp?.let { /* Message seen sent at timestamp */ }
}