async def callback_processor(self, request): try: data = await request.json() except (UnicodeDecodeError, json.decoder.JSONDecodeError): return web.Response(text="ok") data_type = data["type"] if data_type == "confirmation": return web.Response(text=self.settings.CONF_CODE) obj = data["object"] if "user_id" in obj: obj['user_id'] = int(obj['user_id']) if data_type == 'message_new': data = MessageEventData.from_message_body(obj) msg = Message(self.api, data) await self.process_message(msg) else: evnt = CallbackEvent(self.api, data_type, obj) await self.process_event(evnt) return web.Response(text="ok")
async def process_longpoll_event(self, new_event): if not new_event: return event_id = new_event[0] if event_id != 4: evnt = LongpollEvent(self.api, event_id, new_event) return await self.process_event(evnt) data = MessageEventData() data.msg_id = new_event[1] data.attaches = new_event[6] data.time = int(new_event[4]) try: data.user_id = int(data.attaches['from']) data.chat_id = int(new_event[3]) - 2000000000 data.is_multichat = True del data.attaches['from'] except KeyError: data.user_id = int(new_event[3]) data.is_multichat = False # https://vk.com/dev/using_longpoll_2 flags = parse_msg_flags(new_event[2]) if flags['outbox']: if not self.settings.READ_OUT: return data.is_out = True data.full_text = new_event[5].replace('<br>', '\n') if "fwd" in data.attaches: data.forwarded = MessageEventData.parse_brief_forwarded_messages_from_lp( data.attaches["fwd"]) del data.attaches["fwd"] else: data.forwarded = [] msg = Message(self.api, data) if await self.check_event(data.user_id, data.chat_id, data.attaches): msg.is_event = True await self.process_message(msg)