# Sending messages correctly

## Sending message as answer

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

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

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

  @OnCommand('start')
  async start(): Promise<string> {
    return 'Hello, world!';
  }
}
```

{% endcode %}

In this code in `start` method, you can see when the user writes command **/start**, the user gets the message `Hello, world!`. What's method returns will be sent to the user

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

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

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

  @OnCommand('start')
  async start(): Promise<MessageSend> {
    return new MessageSend('Hello, world!');
  }
}
```

{% endcode %}

MessageSend class-method is a wrapper for the message: it allows you to add keyboard, options, photo, or media to the message

If you don't know what will return your method (e.g. MessageSend or Edit) you can use MessageCreator class as return type (import from root)

#### MessageSend class-method take arguments:

<table><thead><tr><th width="150" data-type="number">Argument</th><th width="384.3333333333333">Description</th><th>Required</th></tr></thead><tbody><tr><td>1</td><td>Content (media or text)</td><td><strong>Required</strong></td></tr><tr><td>2</td><td><a href="/pages/JoJKUhuojTcGfzEp0lPK">Keyboard</a></td><td>Optional</td></tr><tr><td>3</td><td><a href="https://core.telegram.org/bots/api#sendmessage">Options</a></td><td>Optional</td></tr></tbody></table>

{% hint style="info" %}
Sometimes you can't use the class methods, for example when you want to get some info about the current chat, for that you can use the [**Answer class**](/nestgram/nestgram-features/answer-class.md)
{% endhint %}

## Sending message line

You can also send more than one message, use the `.next` method on the **MessageSend class**

{% hint style="info" %}
**.next method** takes argument: content you want to send (it can be **MessageSend class**). It also can be a function or an async function
{% endhint %}

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

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

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

  @OnCommand('start')
  start() {
    return new MessageSend('Hello, world!')
      .next('Second message')
      .next(new MessageSend('Third message'));
  }
}
```

{% 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/nestgram-features/sending-messages-correctly.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.
