Esempio n. 1
0
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(SetPictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            elif node.getChild("delete"):
                self.toUpper(DeletePictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] == "features":
            # Not implemented
            pass
        elif node["type"] in [ "contacts", "subject", "w:gp2" ]:
            # Implemented in respectively the protocol_contacts and protocol_groups layer
            pass
        elif node["type"] == "contacts":
            pass
        elif node["type"] == "mediaretry":
            # Not implemented
            pass
        elif node["type"] == "web":
            # Not implemented
            pass
        else:
            self.raiseErrorForNode(node)

        ack = OutgoingAckProtocolEntity(node["id"], "notification", node["type"], node["from"])
        self.toLower(ack.toProtocolTreeNode())
Esempio n. 2
0
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(
                    SetPictureNotificationProtocolEntity.fromProtocolTreeNode(
                        node))
            elif node.getChild("delete"):
                self.toUpper(
                    DeletePictureNotificationProtocolEntity.
                    fromProtocolTreeNode(node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(
                StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] in ["contacts", "subject", "w:gp2"]:
            # Implemented in respectively the protocol_contacts and protocol_groups layer
            pass
        else:
            logger.warning("Unsupported notification type: %s " % node["type"])
            logger.debug("Unsupported notification node: %s" % node)

        ack = OutgoingAckProtocolEntity(node["id"],
                                        "notification",
                                        node["type"],
                                        node["from"],
                                        participant=node["participant"])
        self.toLower(ack.toProtocolTreeNode())
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(
                    SetPictureNotificationProtocolEntity.fromProtocolTreeNode(
                        node))
            elif node.getChild("delete"):
                self.toUpper(
                    DeletePictureNotificationProtocolEntity.
                    fromProtocolTreeNode(node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(
                StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] == "features":
            # Not implemented
            pass
        elif node["type"] in ["contacts", "subject", "w:gp2"]:
            # Implemented in respectively the protocol_contacts and protocol_groups layer
            pass
        elif node["type"] == "contacts":
            pass
        elif node["type"] == "web":
            # Not implemented
            pass
        #else:
        #pass
        # self.raiseErrorForNode(node)

        ack = OutgoingAckProtocolEntity(node["id"], "notification",
                                        node["type"], node["from"])
        self.toLower(ack.toProtocolTreeNode())
Esempio n. 4
0
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(SetPictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            elif node.getChild("delete"):
                self.toUpper(DeletePictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] == "features":
            # Not implemented
            pass
        elif node["type"] in ["contacts", "subject", "w:gp2"]:
            # Implemented in respectively the protocol_contacts and protocol_groups layer
            pass
        elif node["type"] in ["features", "contacts", "web", "location"]:
            # implement individually at some point
            # but keep this pass block so system doesn't crash on these types
            pass
        else:
            self.raiseErrorForNode(node)

        ack = OutgoingAckProtocolEntity(node["id"], "notification", node["type"], node["from"])
        self.toLower(ack.toProtocolTreeNode())
Esempio n. 5
0
 def onEncryptNotification(self, protocolTreeNode):
     entity = EncryptNotification.fromProtocolTreeNode(protocolTreeNode)
     ack = OutgoingAckProtocolEntity(protocolTreeNode["id"], "notification",
                                     protocolTreeNode["type"])
     self.toLower(ack.toProtocolTreeNode())
     self.sendKeys(fresh=False,
                   countPreKeys=self.__class__._COUNT_PREKEYS -
                   entity.getCount())
Esempio n. 6
0
 def onEncryptNotification(self, protocolTreeNode):
     entity = EncryptNotification.fromProtocolTreeNode(protocolTreeNode)
     ack = OutgoingAckProtocolEntity(protocolTreeNode["id"], "notification", protocolTreeNode["type"], protocolTreeNode["from"])
     self.toLower(ack.toProtocolTreeNode())
     self.flush_keys(
         self.manager.generate_signed_prekey(),
         self.manager.level_prekeys(force=True)
     )
Esempio n. 7
0
 def recvCall(self, node):
     entity = CallProtocolEntity.fromProtocolTreeNode(node)
     if entity.getType() == "offer":
         receipt = OutgoingReceiptProtocolEntity(node["id"], node["from"], callId = entity.getCallId())
         self.toLower(receipt.toProtocolTreeNode())
     else:
         ack = OutgoingAckProtocolEntity(node["id"], "call", None, node["from"])
         self.toLower(ack.toProtocolTreeNode())
     self.toUpper(entity)
Esempio n. 8
0
 def onIdentityChangeEncryptNotification(self, protocoltreenode):
     entity = IdentityChangeEncryptNotification.fromProtocolTreeNode(
         protocoltreenode)
     ack = OutgoingAckProtocolEntity(protocoltreenode["id"], "notification",
                                     protocoltreenode["type"],
                                     protocoltreenode["from"])
     self.toLower(ack.toProtocolTreeNode())
     self.getKeysFor([entity.getFrom(True)],
                     resultClbk=lambda _, __: None,
                     reason="identity")
Esempio n. 9
0
 def recvCall(self, node):
     entity = CallProtocolEntity.fromProtocolTreeNode(node)
     if entity.getType() == "offer":
         receipt = OutgoingReceiptProtocolEntity(node["id"],
                                                 node["from"],
                                                 callId=entity.getCallId())
         self.toLower(receipt.toProtocolTreeNode())
     else:
         ack = OutgoingAckProtocolEntity(node["id"], "call", None,
                                         node["from"])
         self.toLower(ack.toProtocolTreeNode())
     self.toUpper(entity)
Esempio n. 10
0
File: layer.py Progetto: be31/yowsup
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(PictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] == "features":
            pass
        else:
            self.raiseErrorForNode(node)

        ack = OutgoingAckProtocolEntity(node["id"], "notification", node["type"])
        self.toLower(ack.toProtocolTreeNode())
Esempio n. 11
0
 def onReceipt(self, entity):
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt",
                                     entity.getType(), entity.getFrom())
     if args.debug:
         print "<= WhatsApp: receipt %s" % (entity)
     if not args.dry:
         self.toLower(ack)
Esempio n. 12
0
	def on_receipt(self, entity):
		logger.debug('Mensaje ACK')
		ack = OutgoingAckProtocolEntity(
			entity.getId(),
			'receipt',
			entity.getType(),
			entity.getFrom()
		)
		self.toLower(ack)
Esempio n. 13
0
    def on_receipt(self, entity):
        """Received a "receipt" for a message."""
        logger.debug('ACK message')

        # Acknowledge
        ack = OutgoingAckProtocolEntity(entity.getId(), 'receipt',
                                        entity.getType(), entity.getFrom())

        self.toLower(ack)
Esempio n. 14
0
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(
                    PictureNotificationProtocolEntity.fromProtocolTreeNode(
                        node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(
                StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] == "features":
            pass
        else:
            self.raiseErrorForNode(node)

        ack = OutgoingAckProtocolEntity(node["id"], "notification",
                                        node["type"])
        self.toLower(ack.toProtocolTreeNode())
Esempio n. 15
0
    def recvNotification(self, node):
        if node["type"] == "picture":
            if node.getChild("set"):
                self.toUpper(SetPictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            elif node.getChild("delete"):
                self.toUpper(DeletePictureNotificationProtocolEntity.fromProtocolTreeNode(node))
            else:
                self.raiseErrorForNode(node)
        elif node["type"] == "status":
            self.toUpper(StatusNotificationProtocolEntity.fromProtocolTreeNode(node))
        elif node["type"] in ["contacts", "subject", "w:gp2"]:
            # Implemented in respectively the protocol_contacts and protocol_groups layer
            pass
        else:
            logger.warn("Unsupported notification type: %s " % node["type"])
            logger.debug("Unsupported notification node: %s" % node)

        ack = OutgoingAckProtocolEntity(node["id"], "notification", node["type"], node["from"], participant=node["participant"])
        self.toLower(ack.toProtocolTreeNode())
Esempio n. 16
0
    def onReceipt(self, entity):
        """
            When a receipt is received from WhatsApp. First it is acknowledged then
            depening on the type of receipt the right delivery status is made.
        """

        # Acknowledge the receipt
        ack = OutgoingAckProtocolEntity(entity.getId(), "receipt",
                                        entity.getType(), entity.getFrom())
        self.toLower(ack)

        id = entity.getId()
        receipt_type = entity.getType()

        _session = self.session()
        job = _session.query(Job).filter_by(account_id=self.account.id,
                                            whatsapp_message_id=id).scalar()
        if job is not None:
            if job.method == 'sendMessage':
                # In the event that this is from a text message
                message = _session.query(Message).get(job.message_id)
                if message is not None:
                    # TODO: Make this uniform. Post the received to the API instead of updating the DB
                    message.received = True
                    message.receipt_timestamp = datetime.now()
                    _session.commit()

                    if receipt_type == 'read':
                        data = {
                            'receipt': {
                                'type': 'read',
                                'message_id': message.id
                            }
                        }
                        post_to_server('receipt', self.phone_number, data)
            elif job.method == 'broadcast_Text':
                contact = entity.getParticipant()
                data = {
                    'receipt': {
                        'message_id': id,
                        'phone_number': strip_jid(contact)
                    }
                }

                post_to_server('broadcast_receipt', self.phone_number, data)
Esempio n. 17
0
 def onReceipt(self, entity):
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt",
                                     entity.getType(), entity.getFrom())
     print("Receipt: %s" % ack)
     self.toLower(ack)
Esempio n. 18
0
 def onReceipt(self, entity):
     print "aaaaa", entity.getId()
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", "delivery")
     self.toLower(ack)
Esempio n. 19
0
 def onReceipt(self, entity):
     """ Acknowledge the receipt """
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", entity.getType(), entity.getFrom())
     self.toLower(ack)
Esempio n. 20
0
 def onEncryptNotification(self, protocolTreeNode):
     entity = EncryptNotification.fromProtocolTreeNode(protocolTreeNode)
     ack = OutgoingAckProtocolEntity(protocolTreeNode["id"], "notification", protocolTreeNode["type"], protocolTreeNode["from"])
     self.toLower(ack.toProtocolTreeNode())
     self.sendKeys(fresh=False, countPreKeys = self.__class__._COUNT_PREKEYS - entity.getCount())
Esempio n. 21
0
 def onReceipt(self, entity):
     # ack
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt",
                                     entity.getType(), entity.getFrom())
     self.toLower(ack)
Esempio n. 22
0
 def onReceipt(self, entity):
     self.toLower(
         OutgoingAckProtocolEntity(entity.getId(), 'receipt',
                                   entity.getType(), entity.getFrom()))
Esempio n. 23
0
 def onReceipt(self, entity):
     """Called when received an ACK."""
     ack = OutgoingAckProtocolEntity(entity.getId(), 'receipt',
                                     entity.getType(), entity.getFrom())
     self.toLower(ack)
Esempio n. 24
0
  def onAck(self, entity):
    name = entity.getClass()

    if name == "receipt":
      ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", "receipt", entity._from)
      self.toLower(ack)
Esempio n. 25
0
 def onReceipt(self, entity):
     print "Id-->", entity.getId(), "Type-->", entity.getType(
     ), "From-->", entity.getFrom()
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt",
                                     entity.getType(), entity.getFrom())
     self.toLower(ack)
Esempio n. 26
0
 def onReceipt(self, entity):
     logger.info("Received Receipt: ID {}".format(entity._id))
     logger.info("Sending ACK")
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt",
                                     entity.getType(), entity.getFrom())
     self.toLower(ack)
Esempio n. 27
0
 def ack(self):
     return OutgoingAckProtocolEntity(self.getId(),
                                      "receipt",
                                      self.getType(),
                                      self.getFrom(),
                                      participant=self.participant)
Esempio n. 28
0
 def onReceipt(self, entity):
     ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", "delivery",
                                     entity.getFrom())
     self.toLower(ack)
Esempio n. 29
0
 def onReceipt(self, entity):
      ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", entity.getType(), entity.getFrom())