Exemple #1
0
    def broadcast(self, job):
        """ This method reads the message and targets arguments in the job
            and sends a broadcast
        """

        targets = [ normalizeJid(number) for number in job.targets.split(',') ]
        outgoingMessage = BroadcastTextMessage(targets, job.args.encode('utf8'))
        job.whatsapp_message_id = outgoingMessage.getId()
        self.toLower(outgoingMessage)

        job.runs += 1 
        job.sent = True
Exemple #2
0
    def broadcast(self, job):
        """ This method reads the message and targets arguments in the job
            and sends a broadcast
        """

        targets = [normalizeJid(number) for number in job.targets.split(',')]
        outgoingMessage = BroadcastTextMessage(targets,
                                               job.args.encode('utf8'))
        job.whatsapp_message_id = outgoingMessage.getId()
        self.toLower(outgoingMessage)

        job.runs += 1
        job.sent = True
Exemple #3
0
    def sendImage(self, job):
        """ Send an image to a contact.

        """

        # create db session
        _session = self.session()

        # get the message
        message = _session.query(Message).get(job.message_id)
        caption = message.text

        logger.debug('Retrieved the message with caption %s of type %s' %
                     (caption, message.message_type))

        asset = _session.query(Asset).get(message.asset_id)
        if asset is not None:
            url = asset.url

            logger.debug('About to download %s' % url)

            if url.startswith("//"):
                url = "https:%s" % url

            # download the file
            path = download(url)
            logger.debug('File downloaded to %s' % path)

            if path is not None:
                # get whatsapp username from targets
                target = normalizeJid(job.targets)

                # create the upload request entity
                entity = RequestUploadIqProtocolEntity(
                    RequestUploadIqProtocolEntity.MEDIA_TYPE_IMAGE,
                    filePath=path)

                # the success callback
                successFn = lambda successEntity, originalEntity: self.onRequestUploadSuccess(
                    target, path, successEntity, originalEntity, caption)

                # The on error callback
                errorFn = lambda errorEntity, originalEntity: self.onRequestUploadError(
                    target, path, errorEntity, originalEntity)

                logger.debug('About to call send the image send iq')
                self._sendIq(entity, successFn, errorFn)

            job.runs += 1
            job.sent = True
Exemple #4
0
    def sendImage(self, job):
        """ Send an image to a contact.

        """

        # create db session
        _session = self.session()

        # get the message
        message = _session.query(Message).get(job.message_id)
        caption = message.text

        logger.debug('Retrieved the message with caption %s of type %s' %(caption, message.message_type))

        asset = _session.query(Asset).get(message.asset_id)
        if asset is not None:
            url = asset.url
            
            logger.debug('About to download %s' %url) 

            if url.startswith("//"):
                url = "https:%s" %url

            # download the file
            path = download(url)
            logger.debug('File downloaded to %s' %path)

            if path is not None:
                # get whatsapp username from targets
                target = normalizeJid(job.targets)

                # create the upload request entity
                entity = RequestUploadIqProtocolEntity(RequestUploadIqProtocolEntity.MEDIA_TYPE_IMAGE, filePath=path)

                # the success callback
                successFn = lambda successEntity, originalEntity: self.onRequestUploadSuccess(target, path, successEntity, originalEntity, caption)

                # The on error callback 
                errorFn = lambda errorEntity, originalEntity: self.onRequestUploadError(target, path, errorEntity, originalEntity)        

                logger.debug('About to call send the image send iq')
                self._sendIq(entity, successFn, errorFn)

            job.runs += 1
            job.sent = True
Exemple #5
0
    def leaveGroup(self, job):
        entity = LeaveGroupsIqProtocolEntity([normalizeJid(job.args)])
        self.toLower(entity)

        job.sent = True
        job.runs += 1
Exemple #6
0
    def leaveGroup(self, job):        
        entity = LeaveGroupsIqProtocolEntity([ normalizeJid(job.args) ])
        self.toLower(entity)

        job.sent = True
        job.runs += 1