# Pin or unpin messages

## Pin message

You can pin message using **Pin class-method** or `.pin` **answer/api method**

#### Pin class-method or .pin answer method take arguments:

<table><thead><tr><th width="166.39014373716634" data-type="number">Argument</th><th width="331.89787587875117">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Message id you want to pin</td><td>Optional. Current message id by default</td></tr><tr><td>2</td><td>Chat id in which message you want to edit is located</td><td>Optional. Current chat id by default</td></tr><tr><td>3</td><td>Disable notification. Pass <code>true</code> to disable notification on pin</td><td>Optional</td></tr></tbody></table>

{% hint style="info" %}
If you want to know what arguments an API method takes, see the IDE hint
{% endhint %}

{% code title="app.controller.ts" %}

```typescript
import { Controller, OnCommand, Pin } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @OnCommand('pin_me')
  pinMe() {
    return new Pin();
  }
}
```

{% endcode %}

## Unpin message

To unpin message, use **Unpin class-method** or `.unpin` **answer/api method**. It takes message id you want to unpin as 1st argument (pass 'all' to unpin all messages, by default), and chat id in which you want to unpin message/messages as 2nd argument (optional, current chat id by default)

#### Unpin class-method or .unpin answer method take arguments:

<table><thead><tr><th width="150" data-type="number">Argument</th><th width="393.4742332774719">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Message id you want to unpin. Pass <code>'all'</code> to unpin all messages</td><td>Optional</td></tr><tr><td>2</td><td>Chat id in which message you want to unpin is located</td><td>Optional. Current chat id by default</td></tr></tbody></table>

{% hint style="info" %}
If you want to know what arguments an API method takes, see the IDE hint
{% endhint %}

{% code title="app.controller.ts" %}

```typescript
import { Controller, IMessage, Message, OnCommand, Pin, Unpin } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  pinnedMessageId: number = 0;
  constructor(private readonly appService: AppService) {}

  @OnCommand('pin_me')
  pinMessage(@Message() message: IMessage) {
    this.pinnedMessageId = message.message_id;
    return new Pin();
  }

  @OnCommand('unpin')
  unpinMessage() {
    return new Unpin(this.pinnedMessageId);
  }
}
```

{% endcode %}

{% hint style="warning" %}
We recommend using [services](/nestgram/nestgram-features/services.md) to save data
{% endhint %}

## Unpin all messages

To unpin all messages, use **Unpin class-method**, and pass `'all'` to it as argument

{% code title="app.controller.ts" %}

```typescript
import { Controller, OnCommand, Unpin } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @OnCommand('unpin_all')
  unpinAll() {
    return new Unpin('all');
  }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://degreetpro.gitbook.io/nestgram/api-reference/pin-or-unpin-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
