# Buggy code
async def _get_messages(self):
    """Connect to the Telegram API.

    Uses an aiohttp ClientSession to connect to Telegram API
    and get the latest messages from the chat service.

    The data["offset"] is used to consume every new message, the API
    returns an  int - "update_id" value. In order to get the next
    message this value needs to be increased by 1 the next time
    the API is called. If no new messages exists the API will just
    return an empty {}.

    """
    async with aiohttp.ClientSession() as session:
        data = {}
        if self.latest_update is not None:
            data["offset"] = self.latest_update
        resp = await session.get(self.build_url("getUpdates"), params=data)
        if resp.status != 200:
            _LOGGER.error("Telegram error %s, %s", resp.status, resp.text)
            self.listening = False

        else:
            json = await resp.json()

            await self._parse_message(json)


# Traceback (KeyError)
DEBUG opsdroid.connector.telegram: {'update_id': 539000683, 'channel_post': {'message_id': 15, 'chat': {'id': -1002528219498, 'title': 'vLab', 'type': 'channel'}, 'date': 1550000742, 'text': 'hi'}}
DEBUG opsdroid.connector.telegram: {'update_id': 539026984, 'message': {'message_id': 53, 'from': {'id': 452280388, 'is_bot': False, 'first_name': 'IOBreaker', 'language_code': 'en'}, 'chat': {'id': 452266388, 'first_name': 'IOBreaker', 'type': 'private'}, 'date': 1550000813, 'text': '/start', 'entities': [{'offset': 0, 'length': 6, 'type': 'bot_command'}]}}
DEBUG asyncio: Using selector: EpollSelector
Traceback (most recent call last):
File "/usr/bin/opsdroid", line 11, in <module>
load_entry_point('opsdroid==0.14.1', 'console_scripts', 'opsdroid')()
File "/usr/lib64/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/lib64/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/lib64/python3.6/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib64/python3.6/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/opsdroid/__main__.py", line 197, in main
opsdroid.run()
File "/usr/lib/python3.6/site-packages/opsdroid/core.py", line 135, in run
self.eventloop.run_until_complete(asyncio.gather(*pending))
File "/usr/lib64/python3.6/asyncio/base_events.py", line 473, in run_until_complete
return future.result()
File "/usr/lib/python3.6/site-packages/opsdroid/connector/telegram/__init__.py", line 163, in listen
await self._get_messages()
File "/usr/lib/python3.6/site-packages/opsdroid/connector/telegram/__init__.py", line 143, in _get_messages
await self._parse_message(json)
File "/usr/lib/python3.6/site-packages/opsdroid/connector/telegram/__init__.py", line 99, in _parse_message
user = result["message"]["from"]["username"]
KeyError: 'username'

# Fixed code
async def _get_messages(self):
    """Connect to the Telegram API.

    Uses an aiohttp ClientSession to connect to Telegram API
    and get the latest messages from the chat service.

    The data["offset"] is used to consume every new message, the API
    returns an  int - "update_id" value. In order to get the next
    message this value needs to be increased by 1 the next time
    the API is called. If no new messages exists the API will just
    return an empty {}.

    """
    data = {}
    if self.latest_update is not None:
        data["offset"] = self.latest_update

    await asyncio.sleep(self.update_interval)
    resp = await self.session.get(self.build_url("getUpdates"), params=data)

    if resp.status == 409:
        _LOGGER.info(
            "Can't get updates because previous "
            "webhook is still active. Will try to "
            "delete webhook."
        )
        await self.delete_webhook()

    if resp.status != 200:
        _LOGGER.error("Telegram error %s, %s", resp.status, resp.text)
        self.listening = False
    else:
        json = await resp.json()

        await self._parse_message(json)