Exemplo n.º 1
0
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 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]) + '...'
        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()),
            timestamp=self.timestamp,
            content=self.safe_content)
Exemplo n.º 2
0
    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 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]) + '...'
        elif self.type == 'revoked':
            self.content = ''
            self.safe_content = '...'