rougeth / bottery

[DEVELOPMENT-HALTED] :battery: A bot framework with batteries included
MIT License
344 stars 51 forks source link

[Telegram] KeyError: 'text' when bot was added in a group #126

Closed lucasrcezimbra closed 6 years ago

lucasrcezimbra commented 6 years ago

When the bot was added in a group, it receives a message like Lucas Rangel Cezimbra invited bot but when bottery receives this message it comes without text, so raises an exception as below.

Traceback (most recent call last):
  File "/home/lucas/telegram-bot/.venv/lib/python3.6/site-packages/bottery/platform/telegram/engine.py", line 92, in polling
    await asyncio.gather(*tasks)
  File "/home/lucas/telegram-bot/.venv/lib/python3.6/site-packages/bottery/platform/telegram/engine.py", line 153, in message_handler
    message = self.build_message(data)
  File "/home/lucas/telegram-bot/.venv/lib/python3.6/site-packages/bottery/platform/telegram/engine.py", line 131, in build_message
    return Message(
KeyError: 'text

https://github.com/rougeth/bottery/blob/master/bottery/platform/telegram/engine.py#L133

Telegram documentation says that text is a optional field.

Is this a bug or am I doing something wrong?

If is a bug, how can we get around? We can use message_data.get('text') and set text to None when we do not have text? Or just return None instead of a message?

If it makes sense I can open a pull request.

rougeth commented 6 years ago

Hi @Lrcezimbra, never got this error before, but it's exactly what you describe. Would be good to have a method at Message that could identify if the message was actually a notification the the bot entered in a group (we discussed some possible changes on Message here: #120).

I believe for now the message_data.get('text') is perfect, but we'll need to figure out something more robust.

I would be glad if you open a pull request fixing this issue. Thank you very much for the contribution.