1.0.12 • Published 2 years ago

nestjs-telegraf-state v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Nestjs telegraf state

The "Nestjs-telegraf-state" library is an extension for the NestJS framework and the Telegraf bot framework, designed to manage states inside scenes and process scripts in Telegram bots.

Key features

  • State mechanism inside scenes: The library provides a mechanism for managing states inside Telegram bot scenes. With Nestjs-telegraf-state you can define different states within each scene and store the data associated with each state.

  • Scene Utilities: The library provides convenient utilities for working with scenes in Telegram bots. You can define scenes, switch between them, perform certain actions when entering and exiting a scene.

  • Integration with NestJS and Telegraf: The library allows you to easily integrate the state engine and scene utilities into your applications developed using the NestJS framework and the Telegraf bot framework.

Install

$ npm install nestjs-telegraf-state

Usage

  1. Create a entity of your state.
import { StateEntity } from 'nestjs-telegraf-state'

export interface InitState {
    title: string
}

interface State extends InitState {
    description?: string 
}

@StateEntity()
export class MyStateEntity {
    constructor(private state: State) {}
    
    get title(): string {
        return this.state.title
    }
    
    get description(): string | undefined {
        return this.state.description
    }
}
  1. Usage state entity in scene
import { Scene, InFn, BaseScene, UpdateSceneContextType } from 'nestjs-telegraf-state'
import { Ctx, SceneEnter } from 'nestjs-telegraf'

@Scene()
export class MyScene implements BaseScene {
    static in: InFn<InitState>
    
    @SceneEnter()
    enter(
        @Ctx() context: UpdateSceneContextType, 
        @State(MyStateEntity) entity: MyStateEntity
    ) {
        context.reply(entity.title)
    }
}
1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago