mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.04k stars 795 forks source link

TypeError: chat.sendMessage is not a function #761

Open EdisonHundLucas opened 4 years ago

EdisonHundLucas commented 4 years ago

webwhatsapi/wapi_js_wrapper.py", line 134, in call raise JsException("Error in function {0} ({1}). Command: {2}".format(self.function_name, e.msg, command)) JsException: Error in function sendMessage (TypeError: chat.sendMessage is not a function).

gushome7 commented 4 years ago

I have same problem. repository cloned today. Same error but in line 140 of wrapper.

marcelooorts commented 4 years ago

See issue #754 or this commit

this solution works for me ;)

gushome7 commented 4 years ago

Thanks @marcelofuhr. If I change wapi.js with @emilianot commit, after login nothing happens. No error, but nothing work. My source code:

from future import unicode_literals import os, sys, time, json from webwhatsapi import WhatsAPIDriver from webwhatsapi.objects.message import Message, MediaMessage

def run(): profiledir=os.path.join(".","firefox_cache") if not os.path.exists(profiledir): os.makedirs(profiledir) driver = WhatsAPIDriver(client='firefox', headless=False, loadstyles=True,profile=profiledir) print("Waiting for QR") driver.wait_for_login() driver.save_firefox_profile() time.sleep(30)

print("Bot started")
print("Ready to send")
driver.chat_send_seen('5491158793853@c.us')

contact=driver.get_contact_from_id('5491158793853@c.us')
chat=contact.get_chat();
chat.send_message('Hola Loco!')

driver.subscribe_new_messages(NewMessageObserver())
print("Waiting for new messages...")

""" Locks the main thread while the subscription in running """
while True:
    time.sleep(60)

class NewMessageObserver: def on_message_received(self, new_messages): for message in new_messages: print('message...',message) message.chat.send_message('ok maestro') message.chat.send_seen() if message.type == 'chat': print("New message '{}' received from number {}".format(message.content, message.sender.id)) elif message.type == 'image' or message.type == 'video' or message.type == 'document' or message.type == 'audio' or message.type == 'ptt': print('-- Media') print('filename', message.filename) print('size', message.size) print('mime', message.mime) print('sender', message.sender) msg_caption='' if hasattr(message, 'caption'): msg_caption = message.caption print('caption', message.caption) print('client_url', message.clienturl) if not os.path.exists('chat{id}'.format(id=message.chat_id['serialized'])): os.makedirs('chat{id}'.format(id=message.chat_id['_serialized'])) message.savemedia('chat{id}'.format(id=message.chat_id['_serialized']),True)

if name == 'main': run()

gushome7 commented 4 years ago

@EdisonHundLucas I was able to successfully run the solution proposed by @marcelofuhr. After a lot of tries, adding a time.sleep(20) after driver.save_firefox_profile() I can send messages using driver.send_message_to_id('5491158793853@c.us','Estoy harto loco') Hope work for you too.

marcelomaia commented 4 years ago

Thanks @marcelofuhr it worked for me!

tguimmaraess commented 4 years ago

I'm having problems as trying to execute a javascript code on console to send messages to a chat. It used to work now it won't work anymore. It says:

VM4302:21 Uncaught TypeError: chat.sendMessage is not a function

Does anybody know how to solve it? It's a simple script that runs directly on console. It seems like WhatsApp doesn't have sendMessage function anymore? I can use other functions but not sendMessage.