States
You can use states to store user data
What are states?
Using states
import { Controller, GetState, OnCommand } from 'nestgram';
import { AppService } from './app.service';
export interface IMyState {
counter?: number;
}
@Controller()
export class AppController {
@GetState() state: IMyState;
constructor(private readonly appService?: AppService) {}
@OnCommand('start')
start(): string {
this.state.counter = (this.state.counter || 0) + 1;
return 'Hello!';
}
@OnCommand('stats')
stats(): string {
return `You entered /start ${this.state.counter || 0} times`;
}
}Default state value
Custom state getter
Your custom method can take arguments:
Argument
Description
1
2
3
Custom state setter
Your custom method can take arguments:
Argument
Description
1
2
3
4
Last updated