<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _ws_on_message(self, ws: websocket.WebSocketApp, raw: Union[str, bytes]):
 """Callback for receiving messages from the websocket connection This method receives ALL events from the websocket connection, some of which are used for the initial authentication flow, some of which are used for maintaining the connection, some of which are for notifying this client of user states, etc. Only a few of the events are really worth listening to by "downstream" clients, mostly chat events (``WebSocketEvent.DISPATCH`` with element ``t`` == 'MESSAGE_CREATE'), and those can be accessed by clients using this library via the command registration, which is handled by this method. Args: ws: websocket connection raw: message received from the connection; either string or bytes, the latter is a zlip-compressed string. Either way, the end result of formatting is JSON """

        if isinstance(raw, bytes):
            decoded = zlib.decompress(raw, 15, 10490000).decode('utf-8')
        else:
            decoded = raw
        data = json.loads(decoded)
        if data.get('s') is not None:
            global last_sequence
            last_sequence = str(data['s'])
            self.logger.debug('Set last_sequence to ' + last_sequence)
        event = WebSocketEvent.parse(data['op'])
        self.logger.debug('Received event {} (op #{})'.format(
            event.name,
            data['op']
        ))
        if event == WebSocketEvent.HELLO:
            interval = float(data['d']['heartbeat_interval']) / 1000
            self.logger.debug(f'Starting heartbeat thread at {interval} seconds')
            self._ws_keep_alive = WebSocketKeepAlive(self.logger, ws, interval)
            self._ws_keep_alive.start()
        elif event == WebSocketEvent.DISPATCH:
            self.logger.debug('Got dispatch ' + data['t'])
            if data['t'] == PycordCallback.MESSAGE.value:
                message_content = data['d']['content']
                if message_content.startswith(self.command_prefix) and self._commands:
                    cmd_str = message_content[1:].split(' ')[0].lower()
                    self.logger.debug(f'Got new message, checking for callback for command "{cmd_str}"')
                    for command_obj in self._commands:
                        if command_obj[0].lower() == cmd_str:
                            self.logger.debug(f'Found matching command "{command_obj[0]}", invoking callback')
                            command_obj[1](data)
            for key in self.callbacks:
                if key.value == data['t']:
                    self.callbacks[key](data)