Skip to content

How to use Typescript with matched actions #1974

Answered by MKRhere
TacoV asked this question in Q&A
Discussion options

You must be logged in to vote

You can do that, But the better way is to use Composers to split your bot.

// @file: part.ts

const composer = new Composer();
composer.action(
    'callback-value',
    ctx => {
        console.log(
            "We got a callback from "+ctx.from?.first_name
        );
    }
);

export default composer;
// @file: index.ts

import part from "./part.js";

const bot = new Telegraf();

// session, stage, etc goes here

// finally

bot.use(part);

This way you can split your bot into parts without having to do the hard work of typing it correctly yourself. If you have a custom context type, you can pass it to composer like new Composer<MyCtx>() as well.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@MKRhere
Comment options

Answer selected by TacoV
@TacoV
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants