# 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](https://degreetpro.gitbook.io/nestgram/nestgram-features/services) 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 %}
