Handling text messages

Handle when user writes a text messages (e.g. "Hello, world!")

Handling text messages

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

Optional. @Entity takes text you want to listen to as argument. If you don't pass it, you will handle all text messages

Get the text of the message

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

Example

app.controller.ts
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;
  }
}

Last updated