# Handling text messages

## Handling text messages

To handle a text message, you can use the `@OnText` decorator

{% hint style="info" %}
Optional. `@Entity` takes text you want to listen to as argument. If you don't pass it, you will handle all text messages
{% endhint %}

## Get the text of the message

You can also get the text of the message by `@Text` parameter decorator

## Example

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

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

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

  @OnText('Hello, world!')
  async start(): Promise<string> {
    return 'Hello!';
  }
  
  @OnText() // handle other text messages, optional
  async text(@Text() text: string): Promise<string> {
    return text;
  }
}
```

{% 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/handling-updates/handling-text-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.
