Repository: opsdroid/opsdroid

Issue:
telegram connector does not handle emoji message
Hi,

When opsdroid receive an emoji message from telegram  "_perhaps this issue impact other platforms_"  it does not succeed to parse the incoming message (no text field found) and enter a loop process indicating **ERROR opsdroid.connector.telegram: Unable to parse the message**

```
DEBUG opsdroid.connector.telegram: {'update_id': 628993004, 'message': {'message_id': 3495, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1557067146, 'sticker': {'width': 512, 'height': 512, 'emoji': '🎩', 'set_name': 'MrZoid', 'thumb': {'file_id': 'AAQCABOs8zIOAARKlxOC0H7RiTc2AAIC', 'file_size': 6640, 'width': 128, 'height': 128}, 'file_id': 'CAADAgADBgEAAiUDUg-fFZcSxHZ6mAI', 'file_size': 45888}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
```

## Steps to Reproduce
1- configure configuration.yaml to use telegram connector
2- start opsdroid last version
3- send an emoji
4- check opsdroid logs/debug messages


## Expected Functionality

Opsdroid should handle emoji messages


## Experienced Functionality

Logs :

```
INFO opsdroid.logging: ========================================
INFO opsdroid.logging: Started opsdroid v0.15.4+33.g0c7e0c0
DEBUG asyncio: Using selector: KqueueSelector
DEBUG opsdroid.loader: Loaded loader
DEBUG opsdroid.loader: Loading modules from config...
DEBUG opsdroid.loader: Loaded skill: opsdroid-modules.skill.hello
DEBUG opsdroid.loader: Loading connector modules...
DEBUG opsdroid.loader: Loaded connector: opsdroid.connector.websocket
DEBUG opsdroid.loader: Loaded connector: opsdroid.connector.telegram


DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
DEBUG opsdroid.connector.telegram: {'update_id': 993865146, 'message': {'message_id': 686, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563032184, 'sticker': {'width': 512, 'height': 512, 'emoji': '😎', 'set_name': 'GreatMindsColor', 'thumb': {'file_id': 'AAQCABMv9jcPAARtFJS24s8gbBsoAAIC', 'file_size': 6098, 'width': 128, 'height': 128}, 'file_id': 'CAADAgAD4AgAAgi3GQKT5DnrvOwaLAI', 'file_size': 40318}}}
ERROR opsdroid.connector.telegram: Unable to parse the message.
...
...
...

```



## Versions
- **Opsdroid version: opsdroid v0.15.4+33.g0c7e0c0**
- **Python version: 3.7.2**

## Configuration File

Any configuration file with telegram connector activated




Discussion:
Thanks for raising this. That’s an expected reaction to an emoji since the connector uses the text found in ‘message’ or ‘chat’ response of the api call to parse the text. 

Telegram sets an emoji with the param ‘emoji’ and we haven’t handled this cases so it won’t be able to parse that message since no ‘message’ or ‘chat’ was found in the response.

Do you think we should handle emojis? Not sure if it could be too beneficial imo
Hi @FabioRosado, By handling the emoji i mean avoiding the error loop caused by the emoji message (and by the not updated **last_update** variable)


I did a quick fix that update the next message and display a log when an emoji is detected

```
DEBUG opsdroid.connector.telegram: {'update_id': 993865152, 'message': {'message_id': 695, 'from': {'id': 452282388, 'is_bot': False, 'first_name': 'Chami', 'language_code': 'en'}, 'chat': {'id': 452282388, 'first_name': 'Chami', 'type': 'private'}, 'date': 1563034116, 'sticker': {'width': 512, 'height': 512, 'emoji': '😚', 'set_name': 'ThisCat', 'thumb': {'file_id': 'AAQCABN6xoUqAATJoPUbqEseUvAmAAIC', 'file_size': 8888, 'width': 128, 'height': 128}, 'file_id': 'CAADAgADowADztjoC0gThbizU6HxAg', 'file_size': 60402}}}
DEBUG opsdroid.connector.telegram: Ignoring emoji message
```
As you can see, the log message is now a DEBUG message instead of an ERROR one.
The log indicate clearly that opsdroid is just ignoring the emoji message (for a happy debugging :-) )

What do you think ?

Resolving patch:
diff --git a/opsdroid/connector/telegram/__init__.py b/opsdroid/connector/telegram/__init__.py
--- a/opsdroid/connector/telegram/__init__.py
+++ b/opsdroid/connector/telegram/__init__.py
@@ -173,6 +173,15 @@ async def _parse_message(self, response):
                     )
                     await self.send(message)
                 self.latest_update = result["update_id"] + 1
+            elif (
+                "message" in result
+                and "sticker" in result["message"]
+                and "emoji" in result["message"]["sticker"]
+            ):
+                self.latest_update = result["update_id"] + 1
+                _LOGGER.debug(
+                    "Emoji message parsing not supported " "- Ignoring message"
+                )
             else:
                 _LOGGER.error("Unable to parse the message.")
 


Test patch:
diff --git a/tests/test_connector_telegram.py b/tests/test_connector_telegram.py
--- a/tests/test_connector_telegram.py
+++ b/tests/test_connector_telegram.py
@@ -286,6 +286,52 @@ async def test_parse_message_unauthorized(self):
             self.assertTrue(mocked_respond.called)
             self.assertTrue(mocked_respond.called_with(message_text))
 
+    async def test_parse_message_emoji(self):
+        response = {
+            "result": [
+                {
+                    "update_id": 427647860,
+                    "message": {
+                        "message_id": 12,
+                        "from": {
+                            "id": 649671308,
+                            "is_bot": False,
+                            "first_name": "A",
+                            "last_name": "User",
+                            "username": "user",
+                            "language_code": "en-GB",
+                        },
+                        "chat": {
+                            "id": 649671308,
+                            "first_name": "A",
+                            "last_name": "User",
+                            "username": "user",
+                            "type": "private",
+                        },
+                        "date": 1538756863,
+                        "sticker": {
+                            "width": 512,
+                            "height": 512,
+                            "emoji": "😔",
+                            "set_name": "YourALF",
+                            "thumb": {
+                                "file_id": "AAQCABODB_MOAARYC8yRaPPoIIZBAAIC",
+                                "file_size": 8582,
+                                "width": 128,
+                                "height": 128,
+                            },
+                            "file_id": "CAADAgAD3QMAAsSraAu37DAtdiNpAgI",
+                            "file_size": 64720,
+                        },
+                    },
+                }
+            ]
+        }
+
+        with amock.patch("opsdroid.core.OpsDroid.parse"):
+            await self.connector._parse_message(response)
+            self.assertLogs("_LOGGER", "debug")
+
     async def test_get_messages(self):
         listen_response = amock.Mock()
         listen_response.status = 200