telegraf: Hi! Cant run simple webhook bot from your example ((((((

Context

On webserver:

  • Telegraf.js Version: “telegraf”: “^3.24.0”
  • Node.js Version: v9/2/0
  • Operating System: Ubuntu 18

And winows local machine fails too:

  • Telegraf.js Version: “telegraf”: “^3.24.0”
  • Node.js Version: v9/2/0
  • Operating System: Win 10 Pro x64

Expected Behavior

Bot listens and answers. I have Centos

Current Behavior

Bot not answers. Not listen (

Steps to Reproduce

This is my code:

const Telegraf = require('telegraf')

const bot = new Telegraf(process.env.BOT_TOKEN || 'xxxxxxx')
bot.command('image', (ctx) => ctx.replyWithPhoto({ url: 'https://picsum.photos/200/300/?random' }))
bot.on('text', ({ replyWithHTML }) => {console.log('Incoming');return replyWithHTML('<b>Hello</b>')})

// Set telegram webhook
// npm install -g localtunnel && lt --port 6000
bot.telegram.setWebhook('https://-----.localtunnel.me/secret-path')

// Start https webhook
bot.startWebhook('/secret-path', null, 6000)



On windows i see next text:

(node:11672) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): FetchError: request to https://api.telegram.org/botxxxxxxxx/setWebhook failed, reason: certificate has expired

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 31 (11 by maintainers)

Most upvoted comments

https://github.com/telegraf/telegraf/issues/524#issuecomment-427011881

{ method: ‘setWebhook’, payload: { url: ‘https://-----.localtunnel.me/secret-path’ } } }

When you are trying to use localtunnel, you need to run lt --port 3000 first Then it generate you your private link, which you should use instead of "https://-----.localtunnel.me" This will proxy all queries and apply them at 127.0.0.1:3000

@eugen35, Nope If you are using Localtunnel, you don’t need to install tls and send cert to the telegram. Because it should provide own valid certificate

But if you run your own web server on white IP address, you can run https server (express, nginx, … or inside startWebhook) with your TLS options without using Localtunnel proxy If you don’t have white IP, try to use Polling mode or forward port

Second thing/ When you send selfsinged certificate, you should send content of file, not that file name Mb that thing raise cert expired error, but it is invalid certificate also

It should be looks like

bot.telegram.setWebhook('https://190.1.50.51:8443/secret-path',{ source: fs.readFileSync(  './pathTo/cert.pem') })
  .catch(err=>console.log(err))

bot.startWebhook('/secret-path', tlsOptions, 8443, '190.1.50.51')

If you are using port forwarding

// also need to add rule 190.1.50.51:8443 -> 192.168.0.10: 3000
bot.telegram.setWebhook('https://190.1.50.51:8443/secret-path',{ source: fs.readFileSync(  './pathTo/cert.pem') })
  .catch(err=>console.log(err))

bot.startWebhook('/secret-path', tlsOptions, 3000, '192.168.0.10')

Notes

  1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
  2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
  3. Ports currently supported for Webhooks : 443, 80, 88, 8443 .

NEW! If you’re having any trouble setting up webhooks, please check out this amazing guide to Webhooks .

{ method: ‘setWebhook’, payload: { url: ‘https://-----.localtunnel.me/secret-path’ } } }

When you are trying to use localtunnel, you need to run lt --port 3000 first Then it generate you your private link, which you should use instead of "https://-----.localtunnel.me" This will proxy all queries and apply them at 127.0.0.1:3000

Its working ))))