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.

Add a reference to the telegraf bot instance to the telegrafContext

See original GitHub issue

Is your feature request related to a problem? Please describe. Trying to write a middleware that wants to access the bots api currently requires you to pass the instance of the bot to the middlewares constructor. It would be easier if the bot would be available in every context that is passed to the middleware handler.

Describe the solution you’d like Add a reference to the telegraf bot instance to TelegrafContext

bot.use((ctx, next)=>{
  console.log(ctx.bot);
  next();
});

Describe alternatives you’ve considered The alternative would be something like (in case the middleware is not living inside the scope of the bots creation)

bot.use(((bot)=>(ctx, next)=>{
  console.log(bot);
  next();
})(bot));

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wojpawlikcommented, May 29, 2018
bot.context.bot = bot
1reaction
lucaelincommented, May 22, 2018

Yes something like that. Not entirely useful with this example because the middleware already gets everything ever send to the bot, but in my case I want to modify the inner workings of the bot upon request… It’s not like that it is impossible right now, I just think that this addition would make some code a little nicer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

telegraf.js - v4.11.2
Documentation for telegraf.js - v4.11.2. ... Bots are special Telegram accounts designed to handle messages automatically. ... yarn add telegraf.
Read more >
Telegraf: Modern Telegram Bot Framework for Node.js
Context. A Telegraf Context encapsulates telegram update. Context is created per request and contains following props: Property, Description ...
Read more >
Telegraf Context - YouTube
Build Telegram Chat Bots with Node.js using the Modern Telegraf Framework ...
Read more >
How To Build a Telegram Quotes Generator Bot With Node.js ...
In this tutorial, you will use Node.js, Telegraf, Jimp, and the Pexels API to ... add the following code to create an instance...
Read more >
Build a Telegram Bot using TypeScript, Node.js, and Telegraf ...
Add TypeScript. TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. Add ...
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