def onImageReceived(self, messageid, jid, preview, url, size, wantsReceipt,
                        isBroadcast):
        '''Function called when an image is received.

        Args:
          messageid (str): a handle to the message.
          jid (str): the sender WhatsApp account (number + domain).
          url (str): the url which the image is stored in.
          wantsReceipt (bool): tells if sender expects reception notification.

        Not needed:
          preview, size, isBroadcast.
        '''

        self.log(
            self.tr('<font color=orange>+{0}</font> sent an image.').format(
                self.phone[:self.phone.index('@')]))
        downloader = MediaDownloader(
            successClbk=lambda path: self.splashImage.emit(path),
            errorClbk=lambda: self.log('<font color=red>' + self.tr(
                'Reception failed.') + '</font>'))
        downloader.download(url)
        if jid == self.phone:
            if wantsReceipt:
                self.methodsInterface.call('message_ack', (jid, messageid))
示例#2
0
	def __init__(self,jid,message_id,url,mediaType_id,mediaId,account,resize=False):
		
		WADebug.attach(self);
		path = self.getSavePath(mediaType_id);
		
		filename = url.split('/')[-1]
		
		if path is None:
			raise Exception("Unknown media type")
		
		if not os.path.exists(path):
			os.makedirs(path)
		
		
		self.uploadHandler = MediaUploader(jid, account, self.onUploadSuccess, self.onError, self.onProgressUpdated)
		self.downloadHandler = MediaDownloader(self.onDownloadSuccess, self.onError, self.onProgressUpdated)

		self.url = url
		self._path = path+"/"+filename

		ext = os.path.splitext(filename)[1]

		self.downloadPath = Utilities.getUniqueFilename(path + "/" + self.getFilenamePrefix(mediaType_id) + ext)

		self.resize = resize
		self.mediaId = mediaId
		self.message_id = message_id
		self.jid = jid

		super(WAMediaHandler,self).__init__();
def onImageReceived(messageId, jid, preview, url, size, wantsReceipt, isBroadcast):
        print("Image received: Id:%s Jid:%s Url:%s size:%s" %(messageId, jid, url, size))
        print preview
        downloader = MediaDownloader(onDlsuccess, onDlerror, onDlprogress)
        downloader.download(url)
        global bot
        if wantsReceipt and bot.sendReceipts:
            bot.methodsInterface.call("message_ack", (jid, messageId))

        timeout = 10
        t = 0;
        while t < timeout:
            time.sleep(0.5)
            t+=1