Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yowsup WhatsApp get phone number

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:

  1. I got the access to WhatsApp server by using this command: python yowsup-cli -c config.example --requestcode sms and python yowsup-cli -c config.example --register xxx-xxx
  2. I send message by using this command: python yowsup-cli -c config.example -s 39xxxxxxxxxx "!"
  3. I can have an interactive conversation by using this command: python yowsup-cli -c config.example -i 39xxxxxxxxxx
  4. Get all message I received by using this command: 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

like image 635
lucgian841 Avatar asked Apr 03 '14 10:04

lucgian841


1 Answers

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!

like image 56
jhnwsk Avatar answered Oct 07 '22 23:10

jhnwsk