Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Message
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Retrieve a message

You can retrieve a specific message in an open or group channel by creating and passing the MessageRetrievalParams object to the getMessage() method as a parameter.

const params: MessageRetrievalParams = {
    messageId: MESSAGE_ID,
    channelType: CHANNEL_TYPE,
    channelUrl: CHANNEL_URL,
};
// ...
const message = await sb.message.getMessage(params);

List of parameters

Parameter nameTypeDescription

messageId

long

Specifies the unique ID of the message.

channelType

string

Specifies the type of the channel.

channelUrl

string

Specifies the URL of the channel.


Retrieve the last message of a group channel

You can retrieve and view the last message sent in a group channel.

const lastMessage: BaseMessage = groupChannel.lastMessage;

Depending on the type of message, cast BaseMessage to UserMessage, FileMessage, or AdminMessage to access the properties you need.