pyTelegramBotAPI icon indicating copy to clipboard operation
pyTelegramBotAPI copied to clipboard

Webhooks on flask

Open timkin1 opened this issue 8 years ago • 9 comments

  1. What OS are you using? ubuntu 17.10
  2. What version of python are you using? 3.6

Hello! I used your example (https://github.com/eternnoir/pyTelegramBotAPI/blob/master/examples/webhook_examples/webhook_flask_echo_bot.py) of installing the bot on the server, but for some reason my bot does not respond to the sent commands. I'm working on the digitalocean servers.

When going to the site:port/token page, an error is displayed: Method Not Allowed The method is not allowed for the requested URL.

Please tell me how to solve this issue.

Thanks in advance!

timkin1 avatar Jul 25 '18 17:07 timkin1

When going to the site:port/token page, an error is displayed: Method Not Allowed The method is not allowed for the requested URL.

  1. You should see nothing when you manually touch this address: this is the URL for telegram server to contact your bot.

2. @app.route(WEBHOOK_URL_PATH, methods=['POST']) The "POST" here should give you the hint that this application waits for POST request. Touching this address you make "GET" request. That's why you see "Method Not Allowed".

Badiboy avatar Jul 26 '18 08:07 Badiboy

Well, then why doesn't the bot react to commands?

timkin1 avatar Jul 26 '18 08:07 timkin1

It depends. Did you set breakpoints or print() to see if your program at least receives the POST requests from telegram? At least between lines 44-45, 50-51, 51-52, 56-57?

Additionally set the debug level to DEBUG here: telebot.logger.setLevel(logging.INFO) ->telebot.logger.setLevel(logging.DEBUG) to see what's going on in interaction between bot and Telegram.

Badiboy avatar Jul 26 '18 08:07 Badiboy

2018-07-26 11:14:04,339 (apihelper.py:55 MainThread) DEBUG - TeleBot: "The server returned: 'b'{"ok":true,"result":true,"description":"Webhook was set"}''"

timkin1 avatar Jul 26 '18 08:07 timkin1

Seems that Telegram cannot connect to you server with the given URL. Maybe something is wrong with server settings/certificates etc.

As far as I remember you need the web-server (like nginx) to route queries to given /url:

	location /url {
		proxy_pass http://127.0.0.1:xxxx;
	}

where url is the WEBHOOK_URL_PATH and port is the WEBHOOK_PORT I'm not shure that it is the best way but in that way it starts work for me...

Badiboy avatar Jul 26 '18 08:07 Badiboy

it is possible more in detail?

timkin1 avatar Jul 26 '18 09:07 timkin1

I have such certificate on the domain 2018-07-26 22 20 44

timkin1 avatar Jul 26 '18 19:07 timkin1

first check get_webhook_info

heyyyoyy avatar Aug 03 '18 00:08 heyyyoyy

Hello! Everything works, but there is one problem. I run the flask application in the supervisor and it works. But after 2 days the bot stops responding. In the supervisor, the process is listed as running. Help, please, to understand.

timkin1 avatar Aug 09 '18 16:08 timkin1