Esempio n. 1
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. 2
0
 def onGetSyncResult(self, resultSyncIqProtocolEntity,
                     originalIqProtocolEntity):
     logger.info("Result from sync %s" % resultSyncIqProtocolEntity)
     post_to_server(
         'contacts/sync', self.phone_number, {
             'registered': resultSyncIqProtocolEntity.outNumbers.keys(),
             'unregistered': resultSyncIqProtocolEntity.invalidNumbers
         })
Esempio n. 3
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. 4
0
 def onGetSyncResult(self, resultSyncIqProtocolEntity, originalIqProtocolEntity):
     logger.info("Result from sync %s" %resultSyncIqProtocolEntity)
     post_to_server('contacts/sync', self.phone_number, {'registered': resultSyncIqProtocolEntity.outNumbers.keys(),
                                                         'unregistered': resultSyncIqProtocolEntity.invalidNumbers})