Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Version 4
Home
/
Chat
/
JavaScript
/
Message

Retrieve a message

Copy link

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

Copy link
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

Copy link

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.