opsdroid: Telegram Connector : Parsing edited message cause process to freeze

Description

Hi,

I am experiencing a strange behaviour, when opsdroid is not active and someone send many messages and call them back for modification and send them back. this cause parsing error when opsdroid start receiving those messages and parsing them.

The problem is that the function async def _parse_message(self, response): try to parse a json with looking for message in it’s tests but in our case the entry name became edited_message

An example of an edited message :

{'update_id': 987978987, 'edited_message': {'message_id': 142, 'from': {'id': 65464848, 'is_bot': False, 'first_name': 'IOBreaker', 'language_code': 'en'}, 'chat': {'id': 9849489499, 'first_name': 'IOBreaker', 'type': 'private'}, 'date': 1551697059, 'edit_date': 1551697076, 'text': 'test message'}}

Steps to Reproduce

  • Stop opsdroid
  • Send messages
  • edit the message by clicking on up arrow
  • send edited message back
  • doing this 4 times 😃
  • activate opsdroid

Expected Functionality

detect if the message is an edited one or an “original” one in case of an edited one, use the edited_message entry instead of message entry

Experienced Functionality

here is some logs to help understanding the freeze when the function try to test

if “channel” in result[“message”][“chat”][“type”]

or any other message instead of edited_message

{'ok': True, 'result': [{'update_id': 684648646, 'edited_message': {'message_id': 142, 'from': {'id': 987456897, 'is_bot': False, 'first_name': 'IOBreaker', 'language_code': 'en'}, 'chat': {'id': 987456897, 'first_name': 'IOBreaker', 'type': 'private'}, 'date': 1551697059, 'edit_date': 1551697076, 'text': 'please launch a vmware instance with those paramaters --os=windows --template=windows2016'}}, {'update_id': 246644493, 'message': {'message_id': 145, 'from': {'id': 987456897, 'is_bot': False, 'first_name': 'IOBreaker', 'language_code': 'en'}, 'chat': {'id': 987456897, 'first_name': 'IOBreaker', 'type': 'private'}, 'date': 1551697087, 'text': 'please launch a vmware server with those paramaters --os=windows --template=windows2016 --ip=92.0.34.0.7 --hostname=helios --note="it\'s my test machine ".'}}, {'update_id': 246644494, 'message': {'message_id': 146, 'from': {'id': 987456897, 'is_bot': False, 'first_name': 'IOBreaker', 'language_code': 'en'}, 'chat': {'id': 987456897, 'first_name': 'IOBreaker', 'type': 'private'}, 'date': 1551697540, 'text': 'hi'}}, {'update_id': 246644495, 'message': {'message_id': 147, 'from': {'id': 987456897, 'is_bot': False, 'first_name': 'IOBreaker', 'language_code': 'en'}, 'chat': {'id': 987456897, 'first_name': 'IOBreaker', 'type': 'private'}, 'date': 1551731191, 'text': 'hi'}}]}

Where the freeze occurs :

DEBUG opsdroid.connector.websocket: Starting Websocket connector
DEBUG opsdroid.connector.telegram: Loaded telegram connector
DEBUG opsdroid.connector.telegram: Connecting to telegram
DEBUG opsdroid.connector.telegram: {'ok': True, 'result': {'id': 731324986, 'is_bot': True, 'first_name': 'ChamixLocalBot', 'username': 'ChamixLocalBot'}}
DEBUG opsdroid.connector.telegram: Connected to telegram as ChamixLocalBot
INFO opsdroid.core: Opsdroid is now running, press ctrl+c to exit.
INFO opsdroid.web: Started web server on http://127.0.0.1:8080
DEBUG opsdroid.connector.telegram: =======> Testing if "channel" in result["message"]["chat"]["type"]
DEBUG opsdroid.parsers.crontab: Running crontab skills
DEBUG opsdroid.parsers.crontab: Running crontab skills
DEBUG opsdroid.parsers.crontab: Running crontab skills
DEBUG opsdroid.parsers.crontab: Running crontab skills

this is only my debug line 😃 : DEBUG opsdroid.connector.telegram: =======> Testing if “channel” in result[“message”][“chat”][“type”]

Versions

  • Opsdroid version: v0.14.1+19.g6360912.dirty
  • Python version: 3.7.0

Regards

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

I think what should happen is that an Edit event should be raised, and then skills and connectors can implement them in whatever way they want 😁 (see #826 )

(matrix dosen’t have event editing yet, so not currently a problem)

I can see the reasoning behind jacobs input. Personally, I think opsdroid should handle the edited message. Taking in consideration what @iobreaker was trying to do, if you mess up a long code by mistake, it’s easier to just press the up arrow and get the last message, correct the mistake and sent the command back to the bot.

I am going to start a PR to fix this issue - I have also started using telegram more often and quite like it, even though the documentation kind of sucks haha