Pinned messages
Using Chat SDK methods, you can implement UI features allowing users to "pin" a message to a channel by selecting a sent message and placing it on top of the channel for everyone to see and access it easily.
They can also "unpin" the message if it's no longer important or "pin" another one to replace an already pinned message (there can be only one pinned message on a channel at a time).
Additionally, they can check which message is pinned to the selected channel since the Chat SDK uses the channel metadata to store information on such messages in Message Persistence.
Pinned Messages let users highlight messages in channels for:
-
Essential information - pin critical updates or announcements, ensuring important information remains easily accessible to all participants and reducing the chance of missing key details.
-
Action items and reminders - by pinning action items or reminders, users and their teams can have a centralized location for reference, making it easier to stay organized, prioritize tasks, and ensure accountability.
-
Polling - pin a poll to a channel, allowing a pollster to persist their questions and not have them lost in a chat flow.
Requires App Context and Message Persistence
To store modified data about messages, you must enable App Context and Message Persistence for your app's keyset in the Admin Portal.
Pin
pin()
and pinMessage()
attach a message to the channel.
Both of these methods give the same result. The only difference between them is that you may or may not be required to provide input parameters, and you call them on different objects: message (pin()
) or channel (pinMessage()
).
Alternatively, you can also use other Chat SDK methods to pin a message in a thread (thread message) to the thread channel or the parent channel.
Method signature
These methods take the following parameters:
-
pin()
message.pin(): Promise<void>
-
pinMessage()
channel.pinMessage(
message: Message
): Promise<Channel>
Input
Parameter | Type | Required in pin() | Required in pinMessage() | Default | Description |
---|---|---|---|---|---|
message | Message | No | Yes | n/a | Message object that you want to pin to the selected channel. |
Output
Type | In pin() | In pinMessage() | Description |
---|---|---|---|
Promise<void> | Yes | No | Method returns no output data. |
Promise<Channel> | No | Yes | Object returning the channel metadata updated with these custom fields: pinnedMessageTimetoken to mark the timetoken when the message was pinned pinnedMessageChannelID to mark the channel on which the message was pinned to the given channel (pinning was performed either directly on the parent channel or on a thread channel). |
Basic usage
Pin the last message on the incident-management
channel.
-
pin()
// reference the "incident-management" channel
const channel = await chat.getChannel("incident-management")
// get the last message on the channel
const lastMessage = (await channel.getHistory({count: 1})).messages[0]
// pin the message to the channel
const pinnedMessage = await lastMessage.pin() -
pinMessage()
// reference the "incident-management" channel
const channel = await chat.getChannel("incident-management")
// get the last message on the channel
const lastMessage = (await channel.getHistory({count: 1})).messages[0]
// pin the message to the channel
const pinnedMessage = await channel.pinMessage(lastMessage)
Get
getPinnedMessage()
fetches the message that is currently pinned to the channel.
Method signature
This method has the following signature:
channel.getPinnedMessage(): Promise<Message | null>
Input
This method doesn't take any parameters.
Output
Type | Description |
---|---|
Promise<Message> or Promise<null> | Object returning either the pinned Message object or null value if no message is currently pinned to the channel. |
Basic usage
Get the message pinned to the incident-management
channel.
// reference the "incident-management" channel
const channel = await chat.getChannel("incident-management")
// get the pinned message
const pinnedMessage = await channel.getPinnedMessage()
Unpin
unpinMessage()
unpins a message from the channel.
Alternatively, you can also use other Chat SDK methods to unpin a message in a thread (thread message) from the thread channel or the parent channel.
Method signature
This method has the following signature:
channel.unpinMessage(): Promise<Channel>
Input
This method doesn't take any parameters.
Output
Type | Description |
---|---|
Promise<Channel> | Object returning the channel metadata updated with these custom fields: pinnedMessageTimetoken to mark the timetoken when the message was unpinned pinnedMessageChannelID to mark the channel on which the message was unpinned from the given channel (unpinning was performed either directly on the parent channel or on a thread channel). |
Basic usage
Unpin the message from the incident-management
channel.
// reference the "incident-management" channel
const channel = await chat.getChannel("incident-management")
// unpin the message from the channel
const unpinnedMessage = await channel.unpinMessage()