Quoted messages

Quoted Messages feature lets users reference previous messages within a conversation. By quoting a message, users can provide additional context or relevant details, ensuring coherence even when referencing older messages.

Quote message

There is no dedicated method for quoting messages. You must use sendText() - the same method you use for sending text messages - and attach the required quoted message information.

Method signature

Head over to the sendText() method section for details.

Basic Usage

Quote the message with the 16200000000000001 timetoken.

channel.getMessage(16200000000000001).async { result ->
result.onSuccess { message: Message? ->
if (message != null) {
channel.sendText("Here's the message I'm talking about", quotedMessage = message).async {
it.onSuccess {
// message sent
}.onFailure {
// message sending failed
}
}
}
}.onFailure { exception: PubNubException ->
println("Exception occurred: ${exception.message}")
}
}

Get quoted message

You can access the quotedMessage property of the Message object to list the original quoted message.

Basic usage

Return a quote from the message with the 16200000000000001 timetoken.

channel.getMessage(16200000000000001).async { result ->
result.onSuccess { message: Message? ->
val quote = message?.quotedMessage
if (quote != null) {
println("Quoted Message Details:")
println("Timetoken: ${quote.timetoken}")
println("Text: ${quote.text}")
println("User ID: ${quote.userId}")
} else {
println("No quoted message found")
}
}.onFailure { exception: PubNubException ->
println("Exception occurred: ${exception.message}")
}
}

quotedMessage returns only values for the timetoken, text, and userId parameters. If you want to return the full quoted Message object, use the getMessage() method and the timetoken from the quote that you can extract from the quotedMessage parameter added to the published message.

Last updated on