# Buggy code
async def websocket_handler(self, request):
    """Handle for aiohttp handling websocket connections."""
    socket = request.match_info.get("socket")
    available = [item for item in self.available_connections if item["id"] == socket]
    if len(available) != 1:
        return aiohttp.web.Response(
            text=json.dumps("Please request a socket first"), status=400
        )
    if (
        datetime.now() - available[0]["date"]
    ).total_seconds() > self.connection_timeout:
        self.available_connections.remove(available[0])
        return aiohttp.web.Response(
            text=json.dumps("Socket request timed out"), status=408
        )
    self.available_connections.remove(available[0])
    _LOGGER.debug("User connected to %s", socket)

    websocket = aiohttp.web.WebSocketResponse()
    await websocket.prepare(request)

    self.active_connections[socket] = websocket

    async for msg in websocket:
        if msg.type == aiohttp.WSMsgType.TEXT:
            message = Message(None, socket, self, msg.data)
            await self.opsdroid.parse(message)
        elif msg.type == aiohttp.WSMsgType.ERROR:
            _LOGGER.error(
                "Websocket connection closed with exception %s", websocket.exception()
            )

    _LOGGER.info("websocket connection closed")
    self.active_connections.pop(socket, None)

    return websocket


# Traceback (AttributeError)
DEBUG opsdroid.connector.websocket: Starting Websocket connector
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
INFO aiohttp.access: 127.0.0.1 [07/Mar/2019:14:35:22 +0000] "POST /connector/websocket HTTP/1.1" 200 220 "-" "-"
DEBUG opsdroid.connector.websocket: User connected to 3d406d62-40e6-11e9-bd4a-4865ee166460
ERROR aiohttp.server: Error handling request
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/usr/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/home/hicham/Developments/Bots/opsdroid/opsdroid-master/opsdroid/connector/websocket/__init__.py", line 89, in websocket_handler
await self.opsdroid.parse(message)
File "/home/hicham/Developments/Bots/opsdroid/opsdroid-master/opsdroid/core.py", line 435, in parse
if message is not None and message.text.strip() != "":
AttributeError: 'NoneType' object has no attribute 'strip'
ERROR aiohttp.server: Unhandled exception

# Fixed code
async def websocket_handler(self, request):
    """Handle for aiohttp handling websocket connections."""
    socket = request.match_info.get("socket")
    available = [item for item in self.available_connections if item["id"] == socket]
    if len(available) != 1:
        return aiohttp.web.Response(
            text=json.dumps("Please request a socket first"), status=400
        )
    if (
        datetime.now() - available[0]["date"]
    ).total_seconds() > self.connection_timeout:
        self.available_connections.remove(available[0])
        return aiohttp.web.Response(
            text=json.dumps("Socket request timed out"), status=408
        )
    self.available_connections.remove(available[0])
    _LOGGER.debug("User connected to %s", socket)

    websocket = aiohttp.web.WebSocketResponse()
    await websocket.prepare(request)

    self.active_connections[socket] = websocket
    async for msg in websocket:
        if msg.type == aiohttp.WSMsgType.TEXT:
            message = Message(msg.data, None, None, self)
            await self.opsdroid.parse(message)
        elif msg.type == aiohttp.WSMsgType.ERROR:
            _LOGGER.error(
                "Websocket connection closed with exception %s", websocket.exception()
            )

    _LOGGER.info("websocket connection closed")
    self.active_connections.pop(socket, None)

    return websocket