I’ve done a bot for telegram and it worked but some days ago it appears a problem.
"can’t use getUpdates
method while webhook is active; use deleteWebhook
to delete the webhook first"
I use the deleteWebhook
but it doesn’t work (with the python-telegram-bot).
I use the Python 3.6.12 version
data = {"url": ""}
bot = telegram.Bot('XXXXXX ')
if (normalize(update.message.text).upper() == 'HOLA'):
chat_id = update.message.chat_id
bot.sendMessage(chat_id, 'HOLA')
#pload = {'chat_id':chat_id,'message_id':'123'}
#r = requests.get('https://api.telegram.org/botXXXXXX/deleteWebhook')
#r = requests.post('https://api.telegram.org/botXXXXXX/deleteWebhook',data = pload)
r = requests.post('https://api.telegram.org/botXXXXXX/setWebhook',data = data)
respuesta = bot.deleteWebhook()
bot.sendMessage(chat_id, respuesta)
respuesta = bot.deleteWebhook()
Could you tell me if there is a problem with that? How I can fix it?
Thank you
3
Answers
First off, I would highly recommend that if you are new to python telegram bot that you follow their bot tutorial. Using the bare metal API as you are doing is hard and prone to errors, just follow this step by step until you’re more comfortable getting a basic bot up and running:
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-Your-first-Bot
As for the problem, your code at "r = requests…." is setting up a webhook. This isn’t something you just toggle on and off, it’s a completely different way of receiving and sending information to the Telegram servers and requires a lot of setup. I can’t really recommend a fix as your code is mixing a lot of stuff up.
It usually happens when your bot token is occupied with online service or site. If you register your bot in any site, delete it.
I know it’s late to answer but I write for other people.
It happens because you provided your token somewhere and they set the webhook.
To remove it add the following line right after the line where you define your bot:
After you run it once, you can then remove this line from your code.