Skip to content

Commit def0fb3

Browse files
committed
Add Pinned Messages section
1 parent 3f92f93 commit def0fb3

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

src/working-with-messages.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,64 @@ client.on("message", async (ctx) => {
239239
await ctx.forward(toChat); // This forwards the received message.
240240
});
241241
```
242+
243+
## Pinned Messages
244+
245+
Pinning a message keeps it at the top of a chat so members can find it easily. Both users and bots can pin messages, provided they have the rights to do so in the chat.
246+
247+
### Pinning a Message
248+
249+
Use {{ "pinMessage" |> m }} to pin a message.
250+
251+
```ts
252+
await client.pinMessage(chatId, messageId);
253+
```
254+
255+
In private chats, the pin is visible to both participants by default. Pass `isForBothSides` as `false` to pin it only for the current account.
256+
257+
```ts
258+
await client.pinMessage(chatId, messageId, {
259+
isForBothSides: false,
260+
});
261+
```
262+
263+
Pass `isSilent` to pin without notifying the chat.
264+
265+
```ts
266+
await client.pinMessage(chatId, messageId, {
267+
isSilent: true,
268+
});
269+
```
270+
271+
### Unpinning Messages
272+
273+
Use {{ "unpinMessage" |> m }} to unpin a single message.
274+
275+
```ts
276+
await client.unpinMessage(chatId, messageId);
277+
```
278+
279+
Use {{ "unpinMessages" |> m }} to unpin every pinned message in a chat at once.
280+
281+
```ts
282+
await client.unpinMessages(chatId);
283+
```
284+
285+
In a forum, pass a `topicId` to unpin only the messages in that topic.
286+
287+
```ts
288+
await client.unpinMessages(chatId, {
289+
topicId,
290+
});
291+
```
292+
293+
### Receiving Pin Notifications
294+
295+
When a message is pinned in a group, a service message of type `pinnedMessage` is added to the chat. Listen for it like any other message, and read the pinned message through `ctx.msg.pinnedMessage`.
296+
297+
```ts
298+
client.on("message:pinnedMessage", (ctx) => {
299+
const pinned = ctx.msg.pinnedMessage;
300+
console.log("Pinned:", pinned.id);
301+
});
302+
```

0 commit comments

Comments
 (0)