question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Are types actually supported?

See original GitHub issue

I wanted to use Telegram with TypeScript but it seems that typings are just wrong. For example, Context doesn’t have updateType, updateSubTypes, it doesn’t have update as well, how am I supposed to get update object from API? No match, state, etc. Maybe I miss something but it seems like types are incompatible with Telegraf docs and actually are pretty much useless because you have to use any to access all properties from Context and other objects. I mean, it’s easy to fix by extending Context interface but still, I guess that such big library could have better TypeScript support.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
mxs42commented, Jun 30, 2018

@tplk actually I just stopped using Telegraf and wrote my own library in TypeScript using interfaces, decorators and reflection. Example:

export class TgApp {
    private startDate: number;
    private telegram: Telegram;

    public constructor(username: string, token: string) {
        this.startDate = Date.now() / 1000 | 0;

        this.telegram = new Telegram({
            username,
            token
        });

        // middleware to discard "old" updates (for example when bot was offline)
        this.telegram.Use(this.MiddlewareDiscardOldUpdates);

        // do not process forward messages as commands
        this.telegram.Use(this.MiddlewareDiscardForwardCommands);

        // "magical" method, makes library automatically load methods decorated by @Command or @Action decorators (@Action is a decorator that listens for specific callbackquery events)
        this.telegram.AttachTo(this);
    }

    // simply replies to user with current chat ID
    // @Command decorator specifies that trigger is /chatid command
    // no need to "add" this callback to somewhere, as long as you use telegram.AttachTo, library will load it automatically
    // if you don't need to use this method, just comment out decorator and /chatid command is gone
    // it's damn good lol
    @Command(/chatid/)
    private async CommandChatID(ctx: Context) {
        ctx.sendMessage({
            text: `<b>Chat ID:</b> <code>${ctx.chat!.id}</code>`,
            parse_mode: "HTML"
        });
    }
    
    // Updates decorator says that this middleware will only listen for "message" update type
    @Updates("message")
    // autobind is from andreypopp/autobind-decorator to bind callback to object instance
    @autobind
    private async MiddlewareDiscardOldUpdates(ctx: Context) {
        if (ctx.update.message!.date < this.startDate) {
            return false;
        }
    }

    @Updates("message")
    @autobind
    private async MiddlewareDiscardForwardCommands(ctx: Context) {
        if (ctx.update.message!.forward_from) {
            if (ctx.commandString) { // ctx.commandString is a Context prop that exists if lib detects that message contains command
                return false;
            }
        }
    }
}

I also wrote Markup helpers for generating keyboard, passing data to callback buttons, etc. Sadly I can’t release it because it’s still in development, I created it because I just need it to develop another project and for me it’s already 100x times better than Telegraf (at least for TypeScript). Some time later I will release it I guess but for now it’s too early.

3reactions
KnorpelSenfcommented, Nov 30, 2020

Seriously? Please stop whining and start contributing.

written >70% in typescript

@SoundAsleep192 that is wrong.

This project is traditionally not a TypeScript project. I submitted #1108 three months ago that actually brings us up the the 75+ % TS, and typegram had to be published before we could do any meaningful stuff. The current version on npm is completely written in JS with a few manually created types to the side. This has nothing to do with “being written in TS”.

The code that fixes our problems is already pushed, but given that none of you guys bothers to review the respective pull requests (#1194, #1195, #1200, just to name the currently open ones) and confirming that they actually work, how do you think anyone of us will be able to benefit from the work behind it?

It is 2020 and type State is not exist in TelegrafContext.

@skmohammadi it does exist. I submitted it. Can you please confirm that it works (so we can arrive in 2020)? #1194

Are the typings fixed yet?

@mfissehaye they are. @wojpawlik and I submitted them. If you are interested in them, can you then please review the above PRs and confirm that we can merge them?

My point is: People are investing their spare free time here, and taking that for granted while dropping snappy comments does in no way accelerate it. Joining in does.</outrage>

I’m looking forward to the contributions of you all! Please try out what is written, and provide feedback. This is essential. (Also, IMO it would be good to have more docs. What do you think?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

PostScript Type 1 fonts end of support - Adobe Support
Users will no longer have the ability to author content using Type 1 fonts after that time.
Read more >
Support and Connection Types
The three common types of connections which join a built structure to its foundation are; roller, pinned and fixed. A fourth type, not...
Read more >
MIME types (IANA media types) - HTTP - MDN Web Docs
Each type has its own set of possible subtypes. A MIME type always has both a type and a subtype, never just one...
Read more >
Supporting Organizations - Requirements and Types - IRS
Supporting organizations are classified as Type I, Type II or Type III supporting organizations based on how they satisfy the relationship ...
Read more >
What are type I and type II errors? - Minitab - Support
When you do a hypothesis test, two types of errors are possible: type I and ... you will be less likely to detect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found