Webwhatsapp-wrapper: TypeError: chat.sendMessage is not a function

Created on 27 Nov 2019  路  6Comments  路  Source: mukulhase/WebWhatsapp-Wrapper

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).

Most helpful comment

See issue #754 or this commit

this solution works for me ;)

All 6 comments

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

See issue #754 or this commit

this solution works for me ;)

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('[email protected]')

contact=driver.get_contact_from_id('[email protected]')
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.client_url)
if not os.path.exists('chat_{id}'.format(id=message.chat_id['_serialized'])):
os.makedirs('chat_{id}'.format(id=message.chat_id['_serialized']))
message.save_media('chat_{id}'.format(id=message.chat_id['_serialized']),True)

if __name__ == '__main__':
run()

@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('[email protected]','Estoy harto loco')
Hope work for you too.

Thanks @marcelofuhr it worked for me!

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhndm picture mhndm  路  3Comments

NolanWang picture NolanWang  路  5Comments

dafner picture dafner  路  6Comments

juancrescente picture juancrescente  路  4Comments

ItachiL18 picture ItachiL18  路  6Comments