diff --git a/WPP_Whatsapp/api/layers/HostLayer.py b/WPP_Whatsapp/api/layers/HostLayer.py index 8640a71..1dc5770 100644 --- a/WPP_Whatsapp/api/layers/HostLayer.py +++ b/WPP_Whatsapp/api/layers/HostLayer.py @@ -585,8 +585,11 @@ def asciiQr(code): return asciiQr(code=code) async def scrapeImg(self): - await self.ThreadsafeBrowser.page_wait_for_function("()=>document.querySelector('canvas')?.closest", - page=self.page) + try: + await self.ThreadsafeBrowser.page_wait_for_function("()=>document.querySelector('canvas')?.closest", + page=self.page) + except: + pass click = await self.ThreadsafeBrowser.page_evaluate("""() => { const selectorImg = document.querySelector('canvas'); const selectorUrl = selectorImg.closest('[data-ref]'); diff --git a/WPP_Whatsapp/api/layers/SenderLayer.py b/WPP_Whatsapp/api/layers/SenderLayer.py index bacc058..ce1e48b 100644 --- a/WPP_Whatsapp/api/layers/SenderLayer.py +++ b/WPP_Whatsapp/api/layers/SenderLayer.py @@ -180,12 +180,21 @@ async def sendMessageOptions_(self, chat, content, options=None): async def sendImage_(self, to, filePath, filename="", caption="", quotedMessageId=None, isViewOnce=None): to = self.valid_chatId(to) - if filePath and os.path.exists(filePath): - _base64 = self.convert_to_base64(filePath) - filename = os.path.basename(filePath) if not filename else filename - return await self.sendImageFromBase64_(to, _base64, filename, caption, quotedMessageId, isViewOnce) - else: - raise Exception("Path Not Found") + _base64 = await downloadFileToBase64(filePath, [ + 'image/gif', + 'image/png', + 'image/jpg', + 'image/jpeg', + 'image/webp', + ]) + if not _base64: + if filePath and os.path.exists(filePath): + _base64 = self.fileToBase64(filePath) + else: + raise Exception("Path Not Found") + + filename = os.path.basename(filePath) if not filename else filename + return await self.sendImageFromBase64_(to, _base64, filename, caption, quotedMessageId, isViewOnce) async def sendImageFromBase64_(self, to, _base64, filename, caption, quotedMessageId, isViewOnce, mentionedList=None): @@ -204,6 +213,7 @@ async def sendImageFromBase64_(self, to, _base64, filename, caption, quotedMessa caption, quotedMessageId, isViewOnce, + mentionedList, }) => { const result = await WPP.chat.sendFileMessage(to, base64, { type: 'image', @@ -263,8 +273,10 @@ async def sendFile_(self, to, pathOrBase64, nameOrOptions, caption): if pathOrBase64.startswith('data:'): _base64 = pathOrBase64 else: - if pathOrBase64 and os.path.exists(pathOrBase64): - _base64 = self.convert_to_base64(pathOrBase64) + _base64 = await downloadFileToBase64(pathOrBase64) + if not _base64: + if pathOrBase64 and os.path.exists(pathOrBase64): + _base64 = self.fileToBase64(pathOrBase64) if not options.get("filename"): options["filename"] = os.path.basename(pathOrBase64) diff --git a/examples/send_file.py b/examples/send_file.py index 5ffcb41..d1da229 100644 --- a/examples/send_file.py +++ b/examples/send_file.py @@ -11,7 +11,8 @@ raise Exception(creator.state) message = "hello from wpp" -filePath="path/to/file" +filePath="https://images.unsplash.com/photo-1466442929976-97f336a657be" +# filePath=r"C:\Users\ammar\Downloads\12.jpg" phone_number = "201016708170" # or "+201016708170" # example diff --git a/examples/send_text_message.py b/examples/send_text_message.py index 6c66216..da2ceed 100644 --- a/examples/send_text_message.py +++ b/examples/send_text_message.py @@ -32,4 +32,3 @@ @option dict return dict -> {'id': 'true_**********@c.us_*************_out', 'ack': 3, 'sendMsgResult': {}} """ -client.takeScreenshot() \ No newline at end of file diff --git a/setup.py b/setup.py index f1b159f..9866d04 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ "the creation of any interaction, such as customer service, media sending, intelligence recognition " "based on phrases artificial and many other things, use your imagination") -version = "0.3.0" +version = "0.3.5" setup( name="WPP_Whatsapp",