class Message(WhatsappObject): def __init__(self, js_obj, driver=None): """ Constructor :param js_obj: Raw JS message obj :type js_obj: dict """ super(Message, self).__init__(js_obj, driver) self.id = js_obj["id"] self.sender = Contact(js_obj["sender"], driver) if js_obj["sender"] else False self.timestamp = datetime.fromtimestamp(js_obj["timestamp"]) self.chat_id = js_obj['chatId'] if js_obj["content"]: self.content = js_obj["content"] self.safe_content = safe_str(self.content[0:25]) + '...' def __repr__(self): return "<Message - from {sender} at {timestamp}: {content}>".format( sender=safe_str(self.sender.get_safe_name()), timestamp=self.timestamp, content=self.safe_content)
def __init__(self, js_obj, driver=None): """ Constructor :param js_obj: Raw JS message obj :type js_obj: dict """ super(Message, self).__init__(js_obj, driver) self.id = js_obj["id"] self.sender = Contact(js_obj["sender"], driver) if js_obj["sender"] else False self.timestamp = datetime.fromtimestamp(js_obj["timestamp"]) self.chat_id = js_obj['chatId'] if js_obj["content"]: self.content = js_obj["content"] self.safe_content = safe_str(self.content[0:25]) + '...'
def __init__(self, js_obj, driver=None): """ Constructor :param js_obj: Raw JS message obj :type js_obj: dict """ super(Message, self).__init__(js_obj, driver) self.id = js_obj["id"] self.wsp_mid = js_obj.get('wsp_mid', None) self.sender = False self.timestamp = datetime.fromtimestamp(js_obj["timestamp"]) self.chat_id = js_obj['chatId'] if js_obj["sender"]: self.sender = Contact(js_obj["sender"], driver) try: status = MessageStatus(js_obj.get('ack', 0)) except ValueError as e: logger.error(str(e), exc_info=True) status = MessageStatus.ERROR self.lecture_status = status self.text = "" if js_obj["text"]: self.text = js_obj["text"] if js_obj["content"]: self.content = js_obj["content"] self.safe_content = safe_str(self.content[0:25]) + '...' else: logger.info("NON TEXT MESSAGE TYPE") logger.info(json.dumps(js_obj)) self.content = 'NOT SUPPORTED CONTENT' self.safe_content = 'NOT SUPPORTED CONTENT' self.quotedMessage = None if js_obj.get('quotedMsgObj', None): self.quotedMessage = js_obj['quotedMsgObj']
class Message(WhatsappObject): sender = Union[Contact, bool] def __init__(self, js_obj, driver=None): """ Constructor :param js_obj: Raw JS message obj :type js_obj: dict """ super(Message, self).__init__(js_obj, driver) self.id = js_obj["id"] self.type = js_obj["type"] self.sender = Contact( js_obj["sender"], driver) if 'sender' in js_obj and js_obj["sender"] else False self.timestamp = datetime.fromtimestamp(js_obj["timestamp"]) self.timestmp = js_obj["timestamp"] self.chat_id = js_obj['chatId'] if js_obj["content"]: self.content = js_obj["content"] self.safe_content = safe_str(self.content[0:25]) + '...' elif self.type == 'revoked': self.content = '' self.safe_content = '...' def __repr__(self): return "<Message - {type} from {sender} at {timestamp}: {content}>".format( type=self.type, sender=safe_str(self.sender.get_safe_name()) if isinstance( self.sender, Contact) else self.sender, timestamp=self.timestamp, content=self.safe_content)