Get message details

Get message details, retrieve content, and check if the message was deleted.

Get message details

TryGetMessage() fetches the Message object from Message Persistence based on the message timetoken.

Method signature

This method takes the following parameters:

channel.TryGetMessage(
string timeToken,
out Message message
)

Input

ParameterTypeRequiredDefaultDescription
timeTokenstringYesn/aTimetoken of the message you want to retrieve from Message Persistence.
messageout MessageYesn/aThe message to populate with the appropriate Message object if the method returns true. If it returns false, the message remains uninitialized.

Output

If the method returns true, the out message parameter is populated with the appropriate Message object. If it returns false, the message remains uninitialized.

Basic usage

Get the message with the 16200000000000001 timetoken.

// reference the "support" channel
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};

// get the message
if (channel.TryGetMessage("16200000000000001", out var message))
{
Console.WriteLine($"Message: {message.MessageText}");
}

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 GetMessageHistory() 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 access the MessageText property of the Message object to receive its text content.

Method signature

This is how you can access the property:

message.MessageText: string

Properties

PropertyTypeDescription
MessageTextstringText content of the returned message.

Basic usage

Get the content of the message with the 16200000000000000 timetoken.

// reference the "support" channel
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};

// get the message
if (channel.TryGetMessage("16200000000000001", out var message))
{
Console.WriteLine($"Message: {message.MessageText}");
}

Check deletion status

You can access the IsDeleted property of the Message object to check if it's deleted.

Method signature

This is how you can access the property:

message.IsDeleted: bool

Properties

PropertyTypeDescription
IsDeletedboolInfo on whether the message has the IsDeleted flag set to true or not.

Basic usage

Get the status of the message with the 16200000000000000 timetoken.

// get the message
// reference the "support" channel
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};

// get the message
if (channel.TryGetMessage("16200000000000000", out var message))
{
Console.WriteLine($"Is deleted?: {message.IsDeleted}");
}
Last updated on