Get message details
Get message details, retrieve content, and check if the message was deleted.
Get message details
getMessage()
fetches the Message
object from Message Persistence based on the message timetoken.
Method signature
This method takes the following parameters:
channel.getMessage(
timetoken: string
): Promise<Message>
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
timetoken | string | Yes | n/a | Timetoken of the message you want to retrieve from Message Persistence. |
Output
Type | Description |
---|---|
Promise<Message> | Returned Message object. |
Basic usage
Get the message with the 16200000000000001
timetoken.
// reference the "incident-management" channel
const channel = await chat.getChannel("incident-management")
// get the timetoken of the last message on the channel
const messageTimetoken = (await channel.getHistory({count: 1})).messages[0].timetoken
// return the message object
const message = await channel.getMessage("16200000000000001")
Get historical details
If you have Message Persistence enabled on your keyset, PubNub stores all historical info about messages, their metadata, and reactions.
If you want to fetch historical details of a given message, use the getHistory()
method. By default, when you fetch historical messages, PubNub returns all message reactions and metadata attached to the retrieved messages.
Get message content
You can use the getter method to access the Message
object and receive its text content using the text
method.
Method signature
This method has the following signature:
message.text: string
Properties
Property | Type | Description |
---|---|---|
text | string | Text content of the returned message. |
Basic usage
Get the content of the message with the 16200000000000000
timetoken.
// reference the "message" that you're interested in
const message = await channel.getMessage("16200000000000000")
// get message content
message.text
Check deletion status
You can use the getter methods to access the Message
object and check if it was deleted using the deleted
method.
Method signature
This method has the following signature:
message.deleted: boolean
Properties
Property | Type | Description |
---|---|---|
deleted | boolean | Info on whether the message has the deleted status (because it was previously soft-deleted) or not. |
Basic usage
Get the status of the message with the 16200000000000000
timetoken.
// reference the "message" that you're interested in
const message = await channel.getMessage("16200000000000000")
// get message deletion status
message.deleted