Open EdisonHundLucas opened 4 years ago
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('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()
@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.
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.
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).