I'm trying to understand how to use the Yowsup library for WhatsApp. I can send message and I can receive it, but I'm interested to get the phone number to start a new chat. In other words, will develop a computer app that can interact with WhatsApp users, for now I can do the following:
python yowsup-cli -c config.example --requestcode sms
and python yowsup-cli -c config.example --register xxx-xxx
python yowsup-cli -c config.example -s 39xxxxxxxxxx "!"
python yowsup-cli -c config.example -i 39xxxxxxxxxx
python yowsup-cli -c config.example -l
Now when an user send me a message how I can interact with him/her? I guess I should get the phone number form the command python yowsup-cli -c config.example -l
and begin a new interactive conversation with this command: python yowsup-cli -c config.example -i 39xxxxxxxxxx
in which the 39xxxxxxxxxx is the number of the user I get with the previous command.
I hope you can help me
I don't think you want to be using yowsup-cli for development purposes. I think it's intended to be a simple demo client with very limited functionality.
If you look at the yowsup-cli source code you will see it actually imports the included examples to provide the command line message functionality.
What you see inside this code is that your python yowsup-cli -c config.example -l
actually calls
wa = WhatsappListenerClient(args['keepalive'], args['autoack'])
wa.login(login, password)
This example listener client on the other hand has a callback function registered to the message_received
signal.
self.signalsInterface.registerListener("message_received", self.onMessageReceived)
Now if you take a closer look at this function
def onMessageReceived(self, messageId, jid, messageContent, timestamp, wantsReceipt, pushName, isBroadCast):
formattedDate = datetime.datetime.fromtimestamp(timestamp).strftime('%d-%m-%Y %H:%M')
print("%s [%s]:%s"%(jid, formattedDate, messageContent))
if wantsReceipt and self.sendReceipts:
self.methodsInterface.call("message_ack", (jid, messageId))
You can se that the jid
and therefore the phone number which you say you need is on the parameter list of this signal. If you wish to interact with a user after he has sent you a message my guess would be you should store the jid or phone number in your own subscriber to this signal.
In short - don't use the the yowsup-cli per se for development. Use it as a starting point to build your own app. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With