Forums

Came back to check my bot but it does not work

Hi! Have a problem with my telegram bot. I use Flask and pyTelegramBotAPI.

I have uploaded new files into the folder on 14th of February and checked it. The bot has worked. But now it is obviously no connection, I have restarted it several times on server including redownloading of the website etc. Nothing helped. There is also no trace of any errors in logs. Could you help me with any ideas, how it can be improved? Many thanks in advance.

If there are no tracebacks, then there are no errors. That suggests that your bot is just not getting messages from telegram. That would be something you would need to investigate on telegram

Hi, Glenn! When I open my webhook connected to the Pythonanywhere site address, I see that there are requests from Telegram: "'pending_update_count': 18". It means that telegram works. Could you, please look through my code (webhook and app part)? It had worked for three years till March.

from flask import Flask, request
from flask_sslify import SSLify

bot = telebot.TeleBot(config.token, threaded=False)

app = Flask(__name__)
app.config["DEBUG"] = True
sslify =SSLify(app)

@app.route("/")
def webhook():
    bot.remove_webhook()
    bot.set_webhook(url="{my_site_address}" + config.token)
    return "ok", 200

@app.route('/' + config.token, methods=['POST'])
def getMessage():
    uppdate = telebot.types.Update.de_json(request.stream.read().decode("utf-8"))
    bot.process_new_updates([uppdate])
    return "ok", 200

Are you seeing those requests in your access log?

I see only 4 of requests made manually from the browser. No other requests from telegram-bot since 16th of February.

It sounds like Telegram are for some reason just not sending updates to the bot. We have heard of similar behaviour in the past; our working hypothesis is that they are incorrectly treating different subdomains of pythonanywhere.com as if they're the same site, so if one bot stops responding, they block other bots too. The weird thing is that this doesn't seem to happen to everyone at the same time, so it doesn't appear to be they block all bots on all subdomains, just some of them.

Unfortunately all we can really suggest is that you get in touch with Telegram -- if our hypothesis is correct, then it's a bug on their side. pythonanywhere.com is on the Public Suffix List, which means that subdomains should be treated as independent, separately owned websites rather than as part of the same website.

Hi! Thank you for your help. I found the solution for the problem.

I will describe my solution to help the others who may face the same problem. For instance, your bot does not respond but you code is correct and you didn't change it, you checked everything and found no errors in logs. At first, if you have paid account, you should change the name of your site. If you have the free one, you should create the new one. At second, you should CREATE NEW BOT using BOTFather in Telegram. Then move all your code and files, to the new account or change a token if you use the old one. In any case do not forget to change the address for your webhook. That's it.