Skip to main content

Pin Message

Extension settings

  1. Login to CometChat and select your app.
  2. Go to the Extensions section and enable the Pin message extension.

How does it work?

Pin message extension provides you the ability to:

  1. Pin messages
  2. Unpin messages
  3. Fetch all the pinned messages for a conversation.

Messages pinned in a conversation (be it one-on-one or group) are visible to the receiver(s) as well.

1. Pin a message

To pin a message, use the callExtension method provided by the SDK to make an HTTP POST request with the parameters as shown below. You need to pass the msgId that has to be pinned.

CometChat.callExtension('pin-message', 'POST', 'v1/pin', {
"msgId": 280 // The ID of the message to be pinned. Here 280.
}).then(response => {
// { success: true }
})
.catch(error => {
// Error occurred
});

2. Unpin a message

To unpin a message, use the callExtension method provided by the SDK to make an HTTP DELETE request with the parameters as shown below. You need to pass the msgId, receiverType and the receiver (can be either UID or GUID based on receiverType).

CometChat.callExtension('pin-message', 'DELETE', 'v1/unpin', {
"msgId": 111,
"receiverType": "group",
"receiver": "cometchat-guid-1"
}).then(response => {
// { success: true }
})
.catch(error => {
// Error occurred
});

3. Fetch pinned messages

To fetch the pinned messages for a conversation, use the callExtension method provided by the SDK to make an HTTP GET request with the query parameters as shown below. You need to pass the receiverType and the receiver (can be either UID or GUID based on receiverType).

const URL = `v1/fetch?receiverType=${RECEIVER_TYPE}&receiver=${RECEIVER}`;
CometChat.callExtension('pin-message', 'GET', URL, null).then(response => {
// {pinnedMessages: []}
})
.catch(error => {
// Error occured
});