node-telegram-api icon indicating copy to clipboard operation
node-telegram-api copied to clipboard

Way to use Webhooks

Open themasch opened this issue 10 years ago • 4 comments

Currently this API uses polling for updates (i guess). It would be nice if you could configure it to not poll for updates and offer a method to input messages received by webhooks.

This way the user could fire up a express/koa/hapi server and feed the payload from webhookts to the bot.

Would that be clever?

themasch avatar Jun 29 '15 12:06 themasch

Hi, that is planned, I'm going to implement it in the coming days, if you want to contribute, I accept pull requests.

Thanks!

mdibaiee avatar Jun 29 '15 19:06 mdibaiee

Hey @themasch, I just pushed a commit which adds support for webhooks, but as I don't have an HTTPS certification or any experience using HTTPS, I'm not sure if it will work with HTTPS connections. b55fb3c

I tested it with HTTP and it was OK, can you please test this and give feedback? Also if you manage to get it running, please give me your code so I can add it to our examples.

To use webhooks:

bot.start({
  url: 'YOUR_HTTPS_URL', // this is sent to Telegram API's setWebhook, telegram will send requests to this URL
  server: { // This object is passed to https.createServer
    key: 'something'
  }
});

Thanks!

mdibaiee avatar Jun 29 '15 22:06 mdibaiee

@mdibaiee You could use https://ngrok.com or https://letsencrypt.org if you're looking for SSL - I'm currently using letsencrypt for my personal dedi with a Telegram API endpoint, over SSL, and letsencrypt has meant I don't have to send a SSL certification to Telegram's setWebhook either! :wink:

jdrydn avatar Feb 07 '16 22:02 jdrydn

@jdrydn You're right! Thank you for mentioning this! :+1:

mdibaiee avatar Feb 08 '16 05:02 mdibaiee