Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creator.client.onMessage(new_message) is not working properly #45

Closed
Eviltr0N opened this issue Jun 30, 2024 · 4 comments
Closed

creator.client.onMessage(new_message) is not working properly #45

Eviltr0N opened this issue Jun 30, 2024 · 4 comments

Comments

@Eviltr0N
Copy link

Hi, by using examples/receive_message.py i have created a simple code that receives messages from specific chat and replies to it. Its working when the message is simple message and it doesn't work when the incoming message is tagged to other message or simply a reply. In the attached screenshot Hii, Msg - 1, Msg - 2 and Msg - 4 Normal msg seems to be captured by creator.client.onMessage(new_message) but when i tagged another msg in the chat, in case of Msg -3 (tagged reply), Msg - 5 and Msg - 6 it doesn't print in the terminal.

Here is code

import logging


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


your_session_name = "test"
creator = Create(session=your_session_name)


client = creator.start()


if creator.state != 'CONNECTED':
    raise Exception(creator.state)

ph_number = "XXXXXXXXXX"
msg_count = 0

def new_message(message):
    global client, msg_count
    # Add your Code here
    if message and not message.get("isGroupMsg"):
        chat_id = message.get("from")
        message_id = message.get("id")
        if chat_id==f'{ph_number}@c.us':
            print(msg_count, message.get("body"))
            client.reply(chat_id, f'Reply - {msg_count}', message_id)
            msg_count+=1



creator.client.onMessage(new_message)
creator.loop.run_forever()

Output:

30-Jun-24 12:11:29 - INFO - test: Initializing...
30-Jun-24 12:11:29 - DEBUG - test: Registering onStateChange event
30-Jun-24 12:11:29 - INFO - test: unregisterServiceWorker
30-Jun-24 12:11:29 - INFO - test: Session Unpaired
30-Jun-24 12:11:29 - INFO - test: Loading WhatsApp WEB
30-Jun-24 12:11:30 - INFO - test: Page loaded
30-Jun-24 12:11:30 - INFO - test: Injecting wapi.js
30-Jun-24 12:11:30 - INFO - test: Start WPPConfig
30-Jun-24 12:11:30 - INFO - test: WhatsApp WEB loaded
30-Jun-24 12:11:30 - INFO - test: WPPConfig
30-Jun-24 12:11:30 - DEBUG - test: start inject
30-Jun-24 12:11:30 - INFO - test: injected state: False
30-Jun-24 12:11:30 - INFO - test: setInterval__checkStart
30-Jun-24 12:11:30 - INFO - test: http => Waiting page load
30-Jun-24 12:11:30 - INFO - test: inject wppconnect-wa.js
30-Jun-24 12:11:31 - INFO - test: inject wapi.js
30-Jun-24 12:11:31 - INFO - test: wait window.WPP.isReady
30-Jun-24 12:11:31 - INFO - test: wapi.js injected
30-Jun-24 12:11:31 - INFO - test: WhatsApp WEB version: 2.3000.1014582763
30-Jun-24 12:11:31 - INFO - test: WA-JS version: 3.4.2-alpha.0
30-Jun-24 12:11:31 - INFO - test: Wait First selector (INTRO_IMG, INTRO_QRCODE)
30-Jun-24 12:11:33 - INFO - test: __checkQrCode need_scan=False
30-Jun-24 12:11:34 - INFO - test: http => Checking is logged...
30-Jun-24 12:11:34 - DEBUG - test: http => authenticated=True
30-Jun-24 12:11:34 - INFO - test: Auto close configured to 60s
30-Jun-24 12:11:34 - INFO - test: Authenticated
30-Jun-24 12:11:34 - DEBUG - test: clearInterval <asyncio.locks.Event object at 0x7829fc094ad0 [unset]>
30-Jun-24 12:11:34 - INFO - test: http => Checking phone is connected...
30-Jun-24 12:11:35 - INFO - test: http => Connected
30-Jun-24 12:11:35 - DEBUG - test: clearInterval <asyncio.locks.Event object at 0x7829fc094ad0 [set]>
30-Jun-24 12:11:35 - DEBUG - test: Registering onMessage event
30-Jun-24 12:11:36 - INFO - test: needAuthentication=False
30-Jun-24 12:11:36 - INFO - test: http => Connected
30-Jun-24 12:11:36 - DEBUG - test: Exposing onMessage function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onAnyMessage function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onAck function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onNotificationMessage function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onParticipantsChanged function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onStateChange function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onStreamChange function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onIncomingCall function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onInterfaceChange function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onPresenceChanged function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onLiveLocation function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onAddedToGroup function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onRevokedMessage function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onReactionMessage function
30-Jun-24 12:11:36 - DEBUG - test: Exposing onPollResponse function
30-Jun-24 12:11:36 - DEBUG - test: Emitting onStateChange event (1 registered)
30-Jun-24 12:11:36 - INFO - Ready ....
30-Jun-24 12:12:26 - DEBUG - test: Emitting onMessage event (1 registered)
0 Hii
30-Jun-24 12:12:36 - DEBUG - test: Emitting onMessage event (1 registered)
1 Msg - 1
30-Jun-24 12:12:42 - DEBUG - test: Emitting onMessage event (1 registered)
2 Msg - 2
30-Jun-24 12:13:28 - DEBUG - test: Emitting onMessage event (1 registered)
3 Msg - 4 Normal msg



^CTraceback (most recent call last):
  File "/home/electron/Desktop//langc/test.py", line 36, in <module>
    creator.loop.run_forever()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 608, in run_forever
    self._run_once()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1898, in _run_once
    event_list = self._selector.select(timeout)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt

ss

@3mora2
Copy link
Owner

3mora2 commented Jun 30, 2024

Try onAnyMessage

@Eviltr0N
Copy link
Author

Try onAnyMessage

Already tried... Having same issue with onAnyMessage too

@3mora2
Copy link
Owner

3mora2 commented Jun 30, 2024

error from wa-js
image

Fix for urgency:
add

creator.client.ThreadsafeBrowser.page_evaluate_sync("""
 // Resolvenndo bug 'TypeError: i.Wid.isStatusV3 is not a function'
    if(!WPP.whatsapp.Wid.isStatusV3) {
      WPP.whatsapp.Wid.isStatusV3 = () => false
    }
""")

or uncomment this part from receive_message.py

@Eviltr0N
Copy link
Author

Eviltr0N commented Jul 1, 2024

or uncomment this part from receive_message.py

Thanks... It worked.

@Eviltr0N Eviltr0N closed this as completed Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants