How can I run my bot using webhooks instead of polling #1672
-
Hey I'm using node.js,mysql,javascript. How can I add webhooks to my telegram bot? Please provide an example or a help link. I would also like to know. Is there really a difference in performance/speed when it comes to webhooks and polling? Your assistance will be highly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Example: https://github.com/telegraf/telegraf/blob/v4/docs/examples/webhook-bot.js
This should only really be a concern if you're running a bot with a high amount of traffic per second. Most bots will not need to worry about setting up webhooks.
Very similar to running a webserver (because this is a webserver), you can listen on any localhost port, and reverse-proxy it with a server like nginx. If you really wish to your bot directly on the internet, then you must use port 443 and pass TLS options like so:
A long-polling bot (default) will be able to serve several thousand users a day with no problem. You might want to start using webhooks if you notice significantly bad performance due to a large number of users per second. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response and assistance. I really appreciate it. So is this the only code required in order to successfully add a webhook to a bot?
Whenever I use port 443 I get the following error:
Whenever I change the port to 3000 or 8080, I don't get this error but the bot doesn't respond to my messages. I'm not using reverse proxy so that could be the reason. Could you please tell me how I can add reverse-proxy. The bot is meant to be used by 200-300 users and It's currently being tested. |
Beta Was this translation helpful? Give feedback.
Example: https://github.com/telegraf/telegraf/blob/v4/docs/examples/webhook-bot.js
This should only really be a concern if you're running a bot with a high amount of traffic per second. Most bots will not need to worry about setting up webhooks.
Very similar to running a webserver (because this is a webserver), you can listen on any localhost port, and reverse-proxy it with a server like nginx. If you really wish to your bot directly on the internet, then you must use port 443 and pass TLS options like so:
bot.launch({ webhook: { ..., port: 443, tlsOptions: { ... } } })
. tlsOptions are the same as node's http…