3

When I'm starting a bot after 10 minutes - 2 hours appears exception: can't use getUpdates method while webhook is active.

I already tried to delete webhook like that: https://api.telegram.org/bot{token}/deleteWebhook, but it did not help.

Also, I noticed that after an exception was raised, bot replies to any message with a sticker. here is screenshot

Here is the part of main file of the bot (The whole project you can see on my GitHub - https://github.com/MartsinovichDanya/Task_manager_telegram)

 from telegram.ext import Updater, MessageHandler, Filters, CommandHandler from telegram import ReplyKeyboardRemove # ... updater = Updater(TOKEN) dp = updater.dispatcher dp.add_handler(CommandHandler("start", start)) # Клавиатура Босса dp.add_handler(MessageHandler(Filters.regex('Добавить задачу в проект'), write_proj_add_task)) dp.add_handler(MessageHandler(Filters.regex('Удалить задачу из проекта'), write_proj_delete_task)) dp.add_handler(MessageHandler(Filters.regex('Проекты'), project_options)) dp.add_handler(MessageHandler(Filters.regex('Задачи'), task_options)) dp.add_handler(MessageHandler(Filters.regex('Сотрудники'), employee_options)) dp.add_handler(MessageHandler(Filters.regex('Добавить проект'), write_add_project)) dp.add_handler(MessageHandler(Filters.regex('Удалить проект'), write_delete_project)) dp.add_handler(MessageHandler(Filters.regex('Просмотр проектов'), select_project)) dp.add_handler(MessageHandler(Filters.regex('Добавить задачу'), write_add_task)) dp.add_handler(MessageHandler(Filters.regex('Удалить задачу'), write_delete_task)) dp.add_handler(MessageHandler(Filters.regex('Просмотр задач'), task_preview)) dp.add_handler(MessageHandler(Filters.regex('Добавить сотрудника'), write_add_employee)) dp.add_handler(MessageHandler(Filters.regex('Удалить сотрудника'), write_delete_employee)) dp.add_handler(MessageHandler(Filters.regex('Просмотр сотрудников'), select_employee)) dp.add_handler(MessageHandler(Filters.regex('Главное меню'), start)) dp.add_handler(MessageHandler(Filters.regex('Отчёты по Проектам'), project_report)) dp.add_handler(MessageHandler(Filters.regex('Отчёты по Задачам'), task_report)) dp.add_handler(MessageHandler(Filters.regex('Отчёты по Сотрудникам'), employee_report)) dp.add_handler(MessageHandler(Filters.regex('Отчёты'), report)) dp.add_handler(MessageHandler(Filters.regex('Назад'), back_to_report)) # Клавиатура сотрудника dp.add_handler(MessageHandler(Filters.regex('Просмотр моих задач'), employee_task_preview)) dp.add_handler(MessageHandler(Filters.regex('Выполнено'), select_done_task)) # Создаём и удаляем тестовый обработчик текстовых сообщений (команд) projects_list = [] employee_list = [] em = EmployeeModel(db.get_connection()) for e in em.get_all(): employee_list.append(e[1]) pm = ProjectModel(db.get_connection()) for p in pm.get_all(): projects_list.append(p[1]) # Создаём обработчик текстовых сообщений типа Filters.text text_handler = MessageHandler(Filters.text, global_function) # Регистрируем обработчик в диспетчере. dp.add_handler(text_handler) # Запускаем цикл приема и обработки сообщений updater.start_polling() # Отправляем http запрос url = 'https://api.telegram.org/<bot_name_here>:<bot_token_here>/deleteWebhook' req = requests.get(url) print(req.status_code) # Ждём завершения приложения при нажатии клавиш Ctrl+C updater.idle() 

If somebody knows how to solve that problem, please help me!

1
  • 2
    You just posted the bot secret token. Nobody must see it. Go to @BotFather and change it with the command /revoke. Never ever post a token again :) Edit: and do not include the token in a GitHub repo Commented Aug 29, 2020 at 17:50

1 Answer 1

1

You posted your TOKEN publicly and anybody can run your bot without your permission. And also reply with sticker or anything else.

Polling mode (with getUpdates) can be running only once at the same time and only if Webhooks are not set. And looks like someone repeatedly sets a webhook after some time (10 minutes - 2 hours).

To avoid that - delete this file (token) from GitHub and remove everywhere from code. Use environment variables instead.
And put token file to .gitignore file.

After that revoke token of your bot using @BotFather and update it everywhere you are using it.

Sign up to request clarification or add additional context in comments.

4 Comments

This should be added as a comment, not a answer!
@0stone0 why? Her problem is that somebody else uses bot and setting webhook. Plus sending stickers as response. If she will fix that - problem will be solved.
Ahh, I'm sorry, didn't see that the token is probably getting abused by somebody else, maybe you could clarify that each token can only be used once?
@0stone0 added more explanation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.