Reputation: 236
I have created a bot for telegram groups but whenever someone sends a poll this error keeps appearing again and again..
API message that keeps giving error:
{"update_id":869921319,
"poll":{"id":"5427146762856956026","question":"[4/10] Qui \u00e9tait le ma\u00eetre de Grey","options":[{"text":"Oul","voter_count":6},{"text":"Grandin\u00e9","voter_count":0},{"text":"Leon","voter_count":0},{"text":"Mavis","voter_count":2}],"total_voter_count":8,"is_closed":true,"is_anonymous":false,"type":"quiz","allows_multiple_answers":false,"correct_option_id":0}}
My Code:
import telepot
def on_chat_message(msg):
try:
content_type, chat_type, chat_id = telepot.glance(msg)
except Exception as e:
return "Oops!", e.__class__, "occurred."
def on_callback_query(msg):
query_id, chat_id, query_data = telepot.glance(msg, flavor='callback_query')
TOKEN = "BOT TOKEN"
bot = telepot.Bot(TOKEN)
MessageLoop(bot, {'chat': on_chat_message,
'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')
while 1:
time.sleep(10)
Error:
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\telepot\loop.py", line 67, in run_forever
self._update_handler(update)
File "C:\Python38\lib\site-packages\telepot\loop.py", line 153, in <lambda>
collectloop.input_queue.put(_extract_message(update)[1]))
File "C:\Python38\lib\site-packages\telepot\loop.py", line 103, in _extract_message
key = _find_first_key(update, ['message',
File "C:\Python38\lib\site-packages\telepot\__init__.py", line 68, in _find_first_key
raise KeyError('No suggested keys %s in %s' % (str(keys), str(d)))
KeyError: "No suggested keys ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'callback_query', 'inline_query', 'chosen_inline_result', 'shipping_query', 'pre_checkout_query'] in {'update_id': 869921319, 'poll': {'id': '5427146762856956026', 'question': '[4/10] Qui était le maître de Grey', 'options': [{'text': 'Oul', 'voter_count': 6}, {'text': 'Grandiné', 'voter_count': 0}, {'text': 'Leon', 'voter_count': 0}, {'text': 'Mavis', 'voter_count': 2}], 'total_voter_count': 8, 'is_closed': True, 'is_anonymous': False, 'type': 'quiz', 'allows_multiple_answers': False, 'correct_option_id': 0}}"
Upvotes: 3
Views: 1793
Reputation: 6156
As you may be aware, telepot has not been maintained any longer for a while now. It looks to me like this pull request attempts to solve this issue but was never merged. It is probably not advisable to continue using telepot.
However, you can have a look at the forks. Perhaps one of those actually still works.
It is likely that this problem was caused by a change of API on the side of telegram, combined with unclean handling of unexpected values in telepot.
My own bot has recently also stopped working due to such a message. I have, without performing much vetting, switched to this fork - I am no longer invested in my bot, so that'll have to do. Depending on your usage, that might or might not be a good route to take.
If you choose to do it, it's simply a
python2.7 -m pip install --user https://github.com/MoumenKhadr/telepot.git
or just
pip install https://github.com/MoumenKhadr/telepot.git
depending on your setup.
Upvotes: 1