Skip to main content

Text Commands

Create a simple command handler for messages using @TextCommand.

src/app.service.ts
import { Injectable } from '@nestjs/common';
import { Context, TextCommand, TextCommandContext } from '@nestgramjs/core';

@Injectable()
export class AppService {
@TextCommand({
name: 'start',
description: 'Start command!',
})
public onStart(@Context() [ctx]: TextCommandContext) {
return ctx.reply('Start command triggered!');
}
}

If all goes well, you should see something like this:

Text Command

Arguments

You can also use arguments with text commands. Arguments are the words after the command name.

src/app.service.ts
import { Injectable } from '@nestjs/common';
import { Context, TextCommand, TextCommandContext, Arguments } from '@nestgramjs/core';

@Injectable()
export class AppService {
@TextCommand({
name: 'start',
description: 'Start command!',
})
public onStart(@Context() [ctx]: TextCommandContext, @Arguments() args: string[]) {
return ctx.reply(args.join(' '));
}
}