Quoted messages
Quote previous messages to provide context when responding to older messages in a conversation.
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.
Sample code
Quote the message with the 16200000000000001 timetoken.
1channel.getMessage(16200000000000001).async { result ->
2 result.onSuccess { message: Message? ->
3 if (message != null) {
4 channel.sendText("Here's the message I'm talking about", quotedMessage = message).async {
5 it.onSuccess {
6 // message sent
7 }.onFailure {
8 // message sending failed
9 }
10 }
11 }
12 }.onFailure { exception: PubNubException ->
13 println("Exception occurred: ${exception.message}")
14 }
15}
Get quoted message
quotedMessage returns the original quoted message.
Sample code
Return a quote from the message with the 16200000000000001 timetoken.
1channel.getMessage(16200000000000001).async { result ->
2 result.onSuccess { message: Message? ->
3 val quote = message?.quotedMessage
4 if (quote != null) {
5 println("Quoted Message Details:")
6 println("Timetoken: ${quote.timetoken}")
7 println("Text: ${quote.text}")
8 println("User ID: ${quote.userId}")
9 } else {
10 println("No quoted message found")
11 }
12 }.onFailure { exception: PubNubException ->
13 println("Exception occurred: ${exception.message}")
14 }
15}
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.