onTextMessageReceived
Triggers when a new text message arrives in a conversation.
Use it to process, reply to, or analyze incoming messages.
Received properties
Apart from Base, Ephemeral, and Replyable properties,
a WireMessage.Text object contains the following fields:
| Name | Description |
|---|---|
text | The message content. |
mentions | List of mentions in the message. Empty if none. |
quotedMessageId | ID of the message being quoted, if it's a reply. |
quotedMessageSha256 | SHA-256 hash of the quoted message, required if quotedMessageId is present. |
linkPreviews | List of link previews generated from URLs in the message. Empty if none. |
Sample usage
Echo received message
- Kotlin
- Java
override suspend fun onTextMessageReceived(wireMessage: WireMessage.Text) {
val message = WireMessage.Text.create(
conversationId = wireMessage.conversationId,
text = wireMessage.text
)
manager.sendMessageSuspending(message = message)
}
@Override
public void onTextMessageReceived(@NotNull WireMessage.Text wireMessage) {
final WireMessage message = WireMessage.Text.create(
wireMessage.conversationId(),
wireMessage.text(),
wireMessage.mentions(),
wireMessage.linkPreviews(),
null
);
getManager().sendMessage(message);
}