3mora2 / WPP_Whatsapp

WPP_Whatsapp aim of exporting functions from WhatsApp Web to the python, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination
MIT License
57 stars 9 forks source link

In the latest version, the image transmission method "SendImage" fails to dispatch appropriately. Below is the error information. #44

Closed Jeck-Liu-Create closed 2 weeks ago

Jeck-Liu-Create commented 2 weeks ago

Code

from WPP_Whatsapp import Create

import logging

logger = logging.getLogger(name="WPP_Whatsapp")
logger.setLevel(logging.DEBUG)

# start client with your session name
your_session_name = "client"
creator = Create(session=your_session_name, browser="firefox")
client = creator.start()
# Now scan Whatsapp Qrcode in browser

# check state of login
if creator.state != 'CONNECTED':
    raise Exception(creator.state)

message = "hello from wpp"
phone_number = "+33602810693"  # or "+201016708170"

# example
# Simple message
result = client.sendText(phone_number, message)

imgpath = r"C:\Users\12994\Desktop\test\1718068161004.png"
result = client.sendImage(phone_number, imgpath)
print(result)

"""
sendText:
    Sends a text message to given chat
    @category Chat
    @param to chat id: xxxxx@us.c
    @param content text message
    @option dict
    return dict -> {'id': 'true_**********@c.us_*************_out', 'ack': 3, 'sendMsgResult': {}}
"""
client.takeScreenshot()

Log

17-Jun-24 23:26:46 - INFO - client: Initializing...
17-Jun-24 23:26:46 - INFO - client: unregisterServiceWorker
17-Jun-24 23:26:46 - INFO - client: Loading WhatsApp WEB
17-Jun-24 23:26:48 - INFO - client: Page loaded
17-Jun-24 23:26:48 - INFO - client: Injecting wapi.js
17-Jun-24 23:26:48 - INFO - client: Start WPPConfig
17-Jun-24 23:26:48 - INFO - client: WhatsApp WEB loaded
17-Jun-24 23:26:48 - INFO - client: WPPConfig
17-Jun-24 23:26:48 - DEBUG - client: start inject
17-Jun-24 23:26:48 - INFO - client: setInterval__checkStart
17-Jun-24 23:26:48 - DEBUG - client: Registering onStateChange event
17-Jun-24 23:26:48 - INFO - client: http => Waiting page load
17-Jun-24 23:26:48 - INFO - client: injected state: False
17-Jun-24 23:26:48 - INFO - client: inject wppconnect-wa.js
17-Jun-24 23:26:49 - INFO - client: inject wapi.js
17-Jun-24 23:26:49 - INFO - client: wait window.WPP.isReady
17-Jun-24 23:26:49 - INFO - client: wapi.js injected
17-Jun-24 23:26:49 - INFO - client: WhatsApp WEB version: 2.3000.1014266593
17-Jun-24 23:26:49 - INFO - client: WA-JS version: 3.3.2-alpha.0
17-Jun-24 23:26:49 - DEBUG - Page.evaluate: t.webpackRequire is undefined
p@https://github.com/wppconnect-team/wa-js/releases/download/nightly/wppconnect-wa.js:2:310625
get@https://github.com/wppconnect-team/wa-js/releases/download/nightly/wppconnect-wa.js:2:327958
35177/t.isRegistered@https://github.com/wppconnect-team/wa-js/releases/download/nightly/wppconnect-wa.js:2:219790
@debugger eval code line 226 > eval:1:60
evaluate@debugger eval code:233:19
@debugger eval code:1:44

17-Jun-24 23:26:51 - INFO - client: http => Connected
17-Jun-24 23:26:52 - INFO - client: http => Checking is logged...
17-Jun-24 23:26:52 - DEBUG - client: http => authenticated=True
17-Jun-24 23:26:52 - INFO - client: Auto close configured to 60s
17-Jun-24 23:26:52 - INFO - client: Authenticated
17-Jun-24 23:26:52 - DEBUG - client: clearInterval <asyncio.locks.Event object at 0x000001FDAC627E50 [unset]>
17-Jun-24 23:26:52 - INFO - client: http => Checking phone is connected...
17-Jun-24 23:26:52 - DEBUG - client: clearInterval <asyncio.locks.Event object at 0x000001FDAC627E50 [set]>
17-Jun-24 23:26:52 - DEBUG - client: Send Message send_result={'id': 'true_33602810693@c.us_3EB0150D5D4E21047F3B88', 'ack': 1, 'from': '8618232849776@c.us', 'to': '33602810693@c.us', 'sendMsgResult': {}}
Traceback (most recent call last):
  File "D:\my_progarm\watermarking-app\test.py", line 26, in <module>
    result = client.sendImage(phone_number, imgpath)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\my_progarm\watermarking-app\WPP_Whatsapp\api\layers\SenderLayer.py", line 35, in sendImage
    return self.ThreadsafeBrowser.run_threadsafe(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\my_progarm\watermarking-app\WPP_Whatsapp\controllers\browser.py", line 52, in run_threadsafe
    return super().run_threadsafe(func, timeout_=timeout_)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\PlaywrightSafeThread\browser\threadsafe_browser.py", line 302, in run_threadsafe
    result = future.result(timeout=timeout_)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\anaconda3\Lib\concurrent\futures\_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\ProgramData\anaconda3\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "D:\my_progarm\watermarking-app\WPP_Whatsapp\api\layers\SenderLayer.py", line 186, in sendImage_
    return await self.sendImageFromBase64_(to, _base64, filename, caption, quotedMessageId, isViewOnce)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\my_progarm\watermarking-app\WPP_Whatsapp\api\layers\SenderLayer.py", line 200, in sendImageFromBase64_
    result = await self.ThreadsafeBrowser.page_evaluate("""async ({
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\PlaywrightSafeThread\browser\threadsafe_browser.py", line 475, in page_evaluate
    return await self.create_task(page.evaluate(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\PlaywrightSafeThread\browser\threadsafe_browser.py", line 285, in create_task
    return await self.loop.create_task(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\async_api\_generated.py", line 8164, in evaluate
    await self._impl_obj.evaluate(
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_page.py", line 435, in evaluate
    return await self._main_frame.evaluate(expression, arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_frame.py", line 278, in evaluate
    await self._channel.send(
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 59, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\12994\AppData\Roaming\Python\Python311\site-packages\playwright\_impl\_connection.py", line 514, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: Page.evaluate: mentionedList is not defined
@debugger eval code line 226 > eval:17:11
evaluate@debugger eval code:233:19
@debugger eval code:1:44
Jeck-Liu-Create commented 2 weeks ago

Beneath this line at https://github.com/3mora2/WPP_Whatsapp/blob/f2a5993099d970b1a48d2ad7de8d37ed59bb3669/WPP_Whatsapp/api/layers/SenderLayer.py#L206, there is a conspicuous absence of the parameter, mentionedList.

3mora2 commented 2 weeks ago

it fixed now, thank you