示例#1
0
    def onMediaMessage(self, messageProtocolEntity):
        if messageProtocolEntity.getMediaType() == "image":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outImage = ImageDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(),
                messageProtocolEntity.fileHash,
                messageProtocolEntity.url,
                messageProtocolEntity.ip,
                messageProtocolEntity.size,
                messageProtocolEntity.fileName,
                messageProtocolEntity.encoding,
                messageProtocolEntity.width,
                messageProtocolEntity.height,
                messageProtocolEntity.getCaption(),
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("Echoing image %s to %s" %
                  (messageProtocolEntity.url,
                   messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(receipt)
            self.toLower(outImage)
示例#2
0
    def onUploadSuccess(self, filePath, jid, url):
        #convenience method to detect file/image attributes for sending, requires existence of 'pillow' library
        print("Upload success")
        entity = OutgoingChatstateProtocolEntity(ChatstateProtocolEntity.STATE_TYPING, jid)
        self.toLower(entity)
	entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, None, jid)
        self.toLower(entity)
示例#3
0
文件: ongair.py 项目: ongair/whatsapp
    def imageSend(self, filePath, url, to, ip=None, caption=None):
        
        # create the entity object to be passed down
        entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, ip, to, caption=caption)
        logger.debug('Sending image %s to %s' %(url, to))

        self.toLower(entity)
示例#4
0
    def imageSend(self, filePath, url, to, ip=None, caption=None):

        # create the entity object to be passed down
        entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
            filePath, url, ip, to, caption=caption)
        logger.debug('Sending image %s to %s' % (url, to))

        self.toLower(entity)
示例#5
0
文件: layer.py 项目: rkramesh/AutoBot
 def onUploadSuccess(self, filePath, jid, url):
     #convenience method to detect file/image attributes for sending, requires existence of 'pillow' library
     logging.info("Upload success")
     entity = OutgoingChatstateProtocolEntity(
         ChatstateProtocolEntity.STATE_TYPING, jid)
     self.toLower(entity)
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
         filePath, url, None, jid)
     self.toLower(entity)
示例#6
0
    def sendImageToSubscribers(self, messageProtocolEntity, category):           
        debug_jids = ["*****@*****.**"]
        subscribers, shortName = getSubscribersForCategory(category=category)['result']
        print 'subscribers parse', subscribers, messageProtocolEntity.getFrom()
        subscribers = [x['username'] for x  in subscribers if x['username']!= messageProtocolEntity.getFrom()] + debug_jids
        print 'subscribers',subscribers


        caption = messageProtocolEntity.getCaption() if messageProtocolEntity.getCaption() else ''

        for sub in subscribers:
            outImage = ImageDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(), messageProtocolEntity.fileHash, messageProtocolEntity.url, messageProtocolEntity.ip,
                messageProtocolEntity.size, messageProtocolEntity.fileName, messageProtocolEntity.encoding, messageProtocolEntity.width, messageProtocolEntity.height,
                'Nova imagem da categoria %s: %s' % (shortName, caption),
                to = str(sub), preview = messageProtocolEntity.getPreview())

            print 'enviando imagem para', sub, outImage.getId()
            self.toLower(outImage)
示例#7
0
    def send_file(self, file_path, url, to, ip=None):
        filename, extension = os.path.splitext(file_path)
        entity = None

        if extension in EXT_IMAGE:
            entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(file_path, url, ip, to)
        elif extension in EXT_VIDEO:
            entity = DownloadableMediaMessageProtocolEntity.fromFilePath(file_path, url, "video", ip, to)
        elif extension in EXT_AUDIO:
            entity = DownloadableMediaMessageProtocolEntity.fromFilePath(file_path, url, "audio", ip, to)
        if entity:
            self.toLower(entity)
示例#8
0
    def send_file(self, file_path, url, to, ip=None):
        filename, extension = os.path.splitext(file_path)
        entity = None

        if extension in EXT_IMAGE:
            entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(file_path, url, ip, to)
        elif extension in EXT_VIDEO:
            entity = DownloadableMediaMessageProtocolEntity.fromFilePath(file_path, url, "video", ip, to)
        elif extension in EXT_AUDIO:
            entity = DownloadableMediaMessageProtocolEntity.fromFilePath(file_path, url, "audio", ip, to)
        if entity:
            self.toLower(entity)
示例#9
0
 def sendMediaForReal(x):
     result, url = x
     print("Sending for real now")
     ip = result.getIp()
     if mediaType == RequestUploadIqProtocolEntity.MEDIA_TYPE_IMAGE:
         entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
             path, url, ip, jid, caption=caption)
     elif mediaType == RequestUploadIqProtocolEntity.MEDIA_TYPE_AUDIO:
         entity = AudioDownloadableMediaMessageProtocolEntity.fromFilePath(
             path, url, ip, jid)
     elif mediaType == RequestUploadIqProtocolEntity.MEDIA_TYPE_VIDEO:
         entity = VideoDownloadableMediaMessageProtocolEntity.fromFilePath(
             path, url, ip, jid, caption=caption)
     if not entity:
         raise ValueError()
     self.toLower(entity)
示例#10
0
    def onMediaMessage(self, messageProtocolEntity):
        if messageProtocolEntity.getMediaType() == "image":
            
            receipt = OutgoingReceiptProtocolEntity(messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outImage = ImageDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(), messageProtocolEntity.fileHash, messageProtocolEntity.url, messageProtocolEntity.ip,
                messageProtocolEntity.size, messageProtocolEntity.fileName, messageProtocolEntity.encoding, messageProtocolEntity.width, messageProtocolEntity.height,
                messageProtocolEntity.getCaption(),
                to = messageProtocolEntity.getFrom(), preview = messageProtocolEntity.getPreview())

            print("Echoing image %s to %s" % (messageProtocolEntity.url, messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(receipt)
            self.toLower(outImage)

        elif messageProtocolEntity.getMediaType() == "location":

            receipt = OutgoingReceiptProtocolEntity(messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outLocation = LocationMediaMessageProtocolEntity(messageProtocolEntity.getLatitude(),
                messageProtocolEntity.getLongitude(), messageProtocolEntity.getLocationName(),
                messageProtocolEntity.getLocationURL(), messageProtocolEntity.encoding,
                to = messageProtocolEntity.getFrom(), preview=messageProtocolEntity.getPreview())

            print("Echoing location (%s, %s) to %s" % (messageProtocolEntity.getLatitude(), messageProtocolEntity.getLongitude(), messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(outLocation)
            self.toLower(receipt)
        elif messageProtocolEntity.getMediaType() == "vcard":
            receipt = OutgoingReceiptProtocolEntity(messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
            outVcard = VCardMediaMessageProtocolEntity(messageProtocolEntity.getName(),messageProtocolEntity.getCardData(),to = messageProtocolEntity.getFrom())
            print("Echoing vcard (%s, %s) to %s" % (messageProtocolEntity.getName(), messageProtocolEntity.getCardData(), messageProtocolEntity.getFrom(False)))
            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(outVcard)
            self.toLower(receipt)
示例#11
0
    def image_send(self, number, imageLabel):
        if self.connected:
            username = self.getStack().getProp(
                YowAuthenticationProtocolLayer.PROP_CREDENTIALS)[0]

            cnx = mysql.connector.connect(user='******',
                                          password='',
                                          database='zapserver')
            cursor = cnx.cursor()

            cursor.execute(
                "select mimeType, fileHash, url, ip, size, fileName, encoding, width, height, preview "
                "from Image where label = %s and jidServidor = %s LIMIT 1",
                [imageLabel, username])

            for (row0, row1, row2, row3, row4, row5, row6, row7, row8,
                 row9) in cursor:
                outImage = ImageDownloadableMediaMessageProtocolEntity(
                    str(row0),
                    str(row1),
                    str(row2),
                    str(row3),
                    int(row4),
                    str(row5),
                    str(row6),
                    int(row7),
                    int(row8),
                    "",
                    to=number,
                    preview=str(row9))

                self.toLower(outImage)

                print("Send ImageLabel to %s" % number)

            cursor.close()
示例#12
0
    def onMedia(self, mediaProtocolEntity):
        if mediaProtocolEntity.getMediaType() == "image":
            receipt = OutgoingReceiptProtocolEntity(
                mediaProtocolEntity.getId(), mediaProtocolEntity.getFrom())

            self.toLower(receipt)

            outImage = ImageDownloadableMediaMessageProtocolEntity(
                mediaProtocolEntity.getMimeType(),
                mediaProtocolEntity.fileHash,
                mediaProtocolEntity.url,
                mediaProtocolEntity.ip,
                mediaProtocolEntity.size,
                mediaProtocolEntity.fileName,
                mediaProtocolEntity.encoding,
                mediaProtocolEntity.width,
                mediaProtocolEntity.height,
                #mediaProtocolEntity.getCaption(),
                "Only text messages ok!!",
                to=mediaProtocolEntity.getFrom(),
                preview=mediaProtocolEntity.getPreview())

            #print("Echoing Image from %s" % mediaProtocolEntity.getFrom(False))
            #print("MimeType: %s" % mediaProtocolEntity.getMimeType())
            #print("FileHash: %s" % mediaProtocolEntity.fileHash)
            #print("url: %s" % mediaProtocolEntity.url)
            #print("ip: %s" % mediaProtocolEntity.ip)
            #print("size: %s" % mediaProtocolEntity.size)
            #print("FileName: %s" % mediaProtocolEntity.fileName)
            #print("encoding: %s" % mediaProtocolEntity.encoding)
            #print("width: %s" % mediaProtocolEntity.width)
            #print("height: %s" % mediaProtocolEntity.height)
            #print("Caption: %s" % str(mediaProtocolEntity.getCaption()))
            #print("Preview: %s" % mediaProtocolEntity.getPreview().encode("UTF-8"))

            #registrar mensagem recebida no BD
            username = self.getStack().getProp(
                YowAuthenticationProtocolLayer.PROP_CREDENTIALS)[0]
            jid = mediaProtocolEntity.getFrom()

            cnx = mysql.connector.connect(user='******',
                                          password='',
                                          database='zapserver')

            cursor = cnx.cursor()
            cursor.execute(
                "insert into Image(jidServer, label, mimeType, fileHash, fileName, url, "
                " ip, size, encoding, width, height, preview) "
                "values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s, %s)", [
                    username,
                    str(mediaProtocolEntity.getCaption()),
                    mediaProtocolEntity.getMimeType(),
                    mediaProtocolEntity.fileHash, mediaProtocolEntity.fileName,
                    mediaProtocolEntity.url, mediaProtocolEntity.ip,
                    mediaProtocolEntity.size, mediaProtocolEntity.encoding,
                    mediaProtocolEntity.width, mediaProtocolEntity.height,
                    mediaProtocolEntity.getPreview().encode("UTF-8")
                ])

            cnx.commit()

            cursor.close()
            cnx.close()

            f = open(username + ".log", 'a')
            f.write(
                jid.split('@')[0] + ": Image " +
                str(mediaProtocolEntity.getCaption()) + " (" +
                str(datetime.datetime.now()) + ")\n")
            f.close()

            self.toLower(outImage)
 def send_uploaded_media(self, fpath, jid, url, ip = None):
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
             fpath, url, ip, jid)
     if not args.dry:
         self.stack.execDetached(self.stack.send(entity))
示例#14
0
文件: layer.py 项目: rkramesh/AutoBot
 def onUploadError(self, filePath, jid, url):
     logging.info("Upload file failed!")
     logging.info(
         ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
             filePath, url, None, jid))
 def send_uploaded_media(self, fpath, jid, url, ip=None):
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
         fpath, url, ip, jid)
     if not args.dry:
         self.stack.execDetached(self.stack.send(entity))
示例#16
0
    def onMediaMessage(self, messageProtocolEntity):
        global lastSentId
        if messageProtocolEntity.getMediaType() == "image":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outImage = ImageDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(),
                messageProtocolEntity.fileHash,
                messageProtocolEntity.url,
                messageProtocolEntity.ip,
                messageProtocolEntity.size,
                messageProtocolEntity.fileName,
                messageProtocolEntity.encoding,
                messageProtocolEntity.width,
                messageProtocolEntity.height,
                messageProtocolEntity.getCaption(),
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("Echoing image %s to %s" %
                  (messageProtocolEntity.url,
                   messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(receipt)
            self.toLower(outImage)

        elif messageProtocolEntity.getMediaType() == "location":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outLocation = LocationMediaMessageProtocolEntity(
                messageProtocolEntity.getLatitude(),
                messageProtocolEntity.getLongitude(),
                messageProtocolEntity.getLocationName(),
                messageProtocolEntity.getLocationURL(),
                messageProtocolEntity.encoding,
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("Echoing location (%s, %s) to %s" %
                  (messageProtocolEntity.getLatitude(),
                   messageProtocolEntity.getLongitude(),
                   messageProtocolEntity.getFrom(False)))

            #send receipt otherwise we keep receiving the same message over and over
            self.toLower(outLocation)
            self.toLower(receipt)

        elif messageProtocolEntity.getMediaType() == "vcard":
            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
            self.toLower(receipt)
            x = messageProtocolEntity.getCardData()
            received_vcard_number = x.split('TEL:')[1].split("\n")[0]

            #inserting in DB
            linkerObject = linker()
            whatsapp_id = messageProtocolEntity.getFrom(False)
            message_sender = linkerObject.returnEkoId(whatsapp_id, 0)
            message_body = received_vcard_number
            message_source = linkerObject.returnMessageSource()
            message_type = linkerObject.returnMessageType(2)
            message_status = linkerObject.returnMessageStatus()
            message_destination = message_source
            dbUpdateObject = dbUpdate()
            dbUpdateObject.insertReceiveMessage(message_sender, message_body,
                                                message_source, message_type,
                                                message_status)

            print("Receiving %s from %s" %
                  (message_body, messageProtocolEntity.getFrom(False)))

            self.toLower(receipt)

            time.sleep(2)
            #to pick only unprocessed message

            replyToBeSent = dbUpdateObject.selectResponseMessage(
                message_destination, lastSentId)
            self.replyBack(messageProtocolEntity, replyToBeSent)

        elif messageProtocolEntity.getMediaType() == "audio":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
            self.toLower(receipt)
            outAudio = AudioDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(),
                messageProtocolEntity.fileHash,
                messageProtocolEntity.url,
                messageProtocolEntity.ip,
                messageProtocolEntity.size,
                messageProtocolEntity.fileName,
                messageProtocolEntity.abitrate,
                messageProtocolEntity.acodec,
                messageProtocolEntity.asampfreq,
                messageProtocolEntity.duration,
                messageProtocolEntity.encoding,
                messageProtocolEntity.origin,
                messageProtocolEntity.seconds,
                to=messageProtocolEntity.getFrom())

            path = str(messageProtocolEntity.url)
            commands.getoutput('wget ' + path)
            fname = path.split('/')[-1]
            commands.getoutput('ffmpeg -i ' + fname + ' ' +
                               fname.split('.')[0] + '.wav')
            r = sr.Recognizer()
            with sr.WavFile(
                    fname.split('.')[0] +
                    '.wav') as source:  # use "test.wav" as the audio source
                audio = r.record(source)  # extract audio data from the file
            try:
                print("Receiving sound. Transcription: " + r.recognize(audio)
                      )  # recognize speech using Google Speech Recognition
            except LookupError:  # speech is unintelligible
                print("Could not understand audio")
                return
                #inserting in DB
                whatsapp_id = messageProtocolEntity.getFrom(False)
                message_sender = linker.returnEkoId(whatsapp_id, 0)
                message_body = r.recognize(audio)
                message_source = linker.returnmessageSource()
                message_type = linker.returnmessageType(2)
                message_status = linker.returnmessagestatus()
                message_destination = message_source
                dbUpdateObject = dbUpdate()
                dbUpdateObject.insertReceiveMessage(message_sender,
                                                    message_body,
                                                    message_source,
                                                    message_type,
                                                    message_status)
                print(
                    "Receiving %s from %s" %
                    (r.recognize(audio), messageProtocolEntity.getFrom(False)))

                self.toLower(receipt)

                time.sleep(2)
                #to pick only unprocessed message

                replyToBeSent = dbUpdateObject.selectResponseMessage(
                    message_destination, self.lastSentId)
                self.replyBack(messageProtocolEntity, replyToBeSent)
示例#17
0
 def doSendImage(self, filePath, url, to, ip = "127.0.0.1", caption = None):
     logger.info('filepath:%s url:%s to:%s ip:%s caption:%s ' % (filePath, url, to, ip, caption))
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, ip, to, caption = caption)
     self.toLower(entity)
示例#18
0
 def doSendImage(self,filePath,url,to,ip=None):
   entity=ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath,url,ip,to)
   self.toLower(entity)
示例#19
0
 def doSendImage(self, filePath, url, to, ip="127.0.0.1", caption=None):
     logger.info('filepath:%s url:%s to:%s ip:%s caption:%s ' %
                 (filePath, url, to, ip, caption))
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
         filePath, url, ip, to, caption=caption)
     self.toLower(entity)
示例#20
0
 def doSendImage(self, filePath, url, to, ip=None):
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
         filePath, url, ip, to)
     self.toLower(entity)
示例#21
0
	def onUploadSuccess(self, filePath, receiver_jid, url):
		#convenience method to detect file/image attributes for sending, requires existence of 'pillow' library
		entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, None, receiver_jid)
		self.toLower(entity)
示例#22
0
 def onUploadError(self, filePath, jid, url):
     print("Upload file failed!")
     print(ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, None, jid))
示例#23
0
 def send_uploaded_media(self, fpath, jid, url, ip=None):
     entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(
         fpath, url, ip, jid)
     if not args.dry:
         self._yowsup.toLower(entity)
示例#24
0
    def onMediaMessage(self, messageProtocolEntity):
        if messageProtocolEntity.getMediaType() == "image":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outImage = ImageDownloadableMediaMessageProtocolEntity(
                messageProtocolEntity.getMimeType(),
                messageProtocolEntity.fileHash,
                messageProtocolEntity.url,
                messageProtocolEntity.ip,
                messageProtocolEntity.size,
                messageProtocolEntity.fileName,
                messageProtocolEntity.encoding,
                messageProtocolEntity.width,
                messageProtocolEntity.height,
                messageProtocolEntity.getCaption(),
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("image %s [%s]:%s" %
                  (messageProtocolEntity.getFrom(False),
                   datetime.datetime.fromtimestamp(
                       messageProtocolEntity.getTimestamp()).strftime(
                           '%d-%m-%Y %H:%M'), messageProtocolEntity.url))

        elif messageProtocolEntity.getMediaType() == "location":

            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())

            outLocation = LocationMediaMessageProtocolEntity(
                messageProtocolEntity.getLatitude(),
                messageProtocolEntity.getLongitude(),
                messageProtocolEntity.getLocationName(),
                messageProtocolEntity.getLocationURL(),
                messageProtocolEntity.encoding,
                to=messageProtocolEntity.getFrom(),
                preview=messageProtocolEntity.getPreview())

            print("location %s [%s]:(%s, %s)" %
                  (messageProtocolEntity.getFrom(False),
                   datetime.datetime.fromtimestamp(
                       messageProtocolEntity.getTimestamp()).strftime(
                           '%d-%m-%Y %H:%M'),
                   messageProtocolEntity.getLatitude(),
                   messageProtocolEntity.getLongitude()))

        elif messageProtocolEntity.getMediaType() == "vcard":
            receipt = OutgoingReceiptProtocolEntity(
                messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
            outVcard = VCardMediaMessageProtocolEntity(
                messageProtocolEntity.getName(),
                messageProtocolEntity.getCardData(),
                to=messageProtocolEntity.getFrom())
            print("vcard %s [%s]:(%s, %s)" %
                  (messageProtocolEntity.getFrom(False),
                   datetime.datetime.fromtimestamp(
                       messageProtocolEntity.getTimestamp()).strftime(
                           '%d-%m-%Y %H:%M'), messageProtocolEntity.getName(),
                   messageProtocolEntity.getCardData()))

        outgoingMessageProtocolEntity = OutgoingReceiptProtocolEntity(
            messageProtocolEntity.getId(), messageProtocolEntity.getFrom())
        self.toLower(receipt)
        print("Sent delivered receipt Message %s" %
              messageProtocolEntity.getId())