def callback_message(self, message): logger.debug('Receive message from client: {}'.format(message[0])) logger.debug('Full message body: {}'.format(message)) msg_obj = Message(message) session_id = Session.generate_session_id(msg_obj['id'], msg_obj['user']) self.sessions[session_id] = self.sessions.get(session_id) or Session( msg_obj['id'], msg_obj['user']) current_session = self.sessions[session_id] logger.debug('Global Sessions: {}'.format(self.sessions)) logger.debug('Current session: {}'.format(current_session._data)) msg_obj.session = current_session if msg_obj.session['is_wait']: # BUG actually, needs a lock here if user type fast enough msg_obj.session.queue.put(msg_obj['content']) return if super(TomBot, self).callback_message(msg_obj): # Act only in the backend tells us that this message is OK to broadcast for plugin in get_all_active_plugin_objects(): #noinspection PyBroadException try: logger.debug('Callback %s' % plugin) plugin.callback_message(msg_obj) except Exception as _: logger.exception("Crash in a callback_message handler")
def callback_message(self, message): logger.debug('Receive message from client: {}'.format(message[0])) logger.debug('Full message body: {}'.format(message)) msg_obj = Message(message) session_id = Session.generate_session_id(msg_obj['id'], msg_obj['user']) self.sessions[session_id] = self.sessions.get(session_id) or Session(msg_obj['id'], msg_obj['user']) current_session = self.sessions[session_id] logger.debug('Global Sessions: {}'.format(self.sessions)) logger.debug('Current session: {}'.format(current_session._data)) msg_obj.session = current_session if msg_obj.session['is_wait']: # BUG actually, needs a lock here if user type fast enough msg_obj.session.queue.put(msg_obj['content']) return if super(TomBot, self).callback_message(msg_obj): # Act only in the backend tells us that this message is OK to broadcast for plugin in get_all_active_plugin_objects(): #noinspection PyBroadException try: logger.debug('Callback %s' % plugin) plugin.callback_message(msg_obj) except Exception as _: logger.exception("Crash in a callback_message handler")
def post(self, *args, **kwargs): msg = json_decode(self.request.body) content = config.main_name + ' ' + msg['command'] + ' ' + msg['args'] msg['content'] = content identity = msg.get('identity') or 'WEBAPI' msg_body = [identity, json.dumps(msg)] msg_obj = Message(msg_body) msg_obj.id = msg['id'] or 'NotProvided' msg_obj.id = msg['user'] or 'NotProvided' proxy.send(msg)