Forums

bot with pyTelegramBotApi, flask. webhook

I made a echo bot with ngrok. and it works fine and now I want to set it on pythonanywhere. I want to know two things: WEBHOOK_PORT and WEBHOOK_LISTEN. in ngrok you can just start ngrok.exe http 3000. and the last - when I start app.run(host=WEBHOOK_LISTEN, port=3000, debug=False) I write port 3000, but in WEBHOOK_PORT it's 443 (with localhost). in python anywhere this ports are difference too?

Do not use app.run, use a webapp. If ngrok has a WSGI interface, use that in a web app. If it doesn't then you can't run it on PythonAnyhwere.

well... I ran it. with this code https://hastebin.com/inenegubib.py I only get 'Hello' when I send something (line 32), why my functions is not working? in localhost everything is fine.

They are using a different way of getting messages that doesn't work in webhooks mode. In your webhook function, you can check for commands and other things in the json you receive so you can include the actions from your other functions.

Do not use app.run, use a webapp.

if I understood it correcltly, bot connot see any updates, right? in local host I got it with app.run, but here (in python anywhere) is no app.run. so I need to add something else, right? if it is, what exactly I should add?

On PythonAnywhere, the equivalent of app.run is performed by our website hosting system, so you shouldn't use it -- you just need to configure the WSGI file correctly. This help page has more information.

well... for now my wsgi looks like this: https://hastebin.com/obadoyebew.py is it correct?

and that page is not helpful. I have already done what is said there

Okay, i fixed it

hey how yo fixed it?

@panrosk What problem do you have?

hi the thing is, with flask, you should create a route and process the telegram events (the json objects which is posted to the server and process it). and with telegram, you can set the webhook to your pythonanywhere account. whenever your bot receives a message, your app can then process it (using pytelegrambotapi). but keep in mind to set a secure webhook (a random string, or a generated guid might suffice).

Looks like you could have hit a wildcard cert problem described on top of our telegram tutorial. (I don't have enough details here tell if that's the case) See https://blog.pythonanywhere.com/148/