Saturday 9 January 2016

Setting Up WhatsApp on Your Computer

Unfortunately I lost my phone yesterday, obviously I am unable to read and send messages to my friends. I don’t want to miss the conversations, so I googled, find this awesome library Yowsup (https://github.com/tgalal/yowsup), which enables you build application which use WhatsApp service. I did this setup on MAC os, I guess it is almost similar for all other platforms.

Prerequisite
a.   Requires python2.6+, or python3.0 +
b.   Required python packages: python-dateutil. Following command used to install dateutil.
pip install python-dateutil
c.    Required python packages for end-to-end encryption: protobuf, pycrypto, python-axolotl-curve25519
pip install protobuf
pip install pycrypto
pip install python-axolotl-curve25519

d.   Required python packages for yowsup-cli: argparse, readline (or pyreadline for windows), pillow (for sending images)
pip install argparse
pip install readline
pip install pillow

Step 1: Download the zip file from following location.


Step 2: Unzip the file, you can see following files.
$ ls
LICENSE  README.md setup.py yowsup  yowsup-cli

Run following command to install Yowsup.
python setup.py install

Yowsup-cli

Yowsup-cli is a command line interface, that allows you using whatsapp services directly.
$ ./yowsup-cli
Available commands:
===================
demos, version, registration

You can get help for the commands by using –help option.

$ ./yowsup-cli registration --help
usage: registration [-h] [-v] [-d] [--help-config] [-c CONFIG] [-m MCC]
                    [-n MNC] [-p PHONE] [-C CC] [-r (sms|voice) | -R code]

WhatsApp Registration options

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Print version info and exit
  -d, --debug           Show debug messages
  --help-config         Prints a config file sample

Configuration options:
  Config file is optional. Other configuration arguments have higher
  priority if given, and will override those specified in the config file

  -c CONFIG, --config CONFIG
                        Path to config file. If this is not set then you must
                        set at least --phone and --cc arguments
  -m MCC, --mcc MCC     Mobile Country Code. Check your mcc here:
                        https://en.wikipedia.org/wiki/Mobile_country_code
  -n MNC, --mnc MNC     Mobile Network Code. Check your mnc from
                        https://en.wikipedia.org/wiki/Mobile_country_code
  -p PHONE, --phone PHONE
                        Your full phone number including the country code you
                        defined in 'cc', without preceeding '+' or '00'
  -C CC, --cc CC        Country code. See http://www.ipipi.com/help/telephone-
                        country-codes.htm. This is now required

Modes:
  -r (sms|voice), --requestcode (sms|voice)
                        Request the digit registration code from Whatsapp.
  -R code, --register code
                        Register account on Whatsapp using the code you
                        previously received


Register your mobile with whatsapp
WhatsApp registration involves 2 steps. First you need to request a registration code. And then you resume the registration with code you got.

Step 1: Use following command to request code.
yowsup-cli registration --requestcode sms --phone 49XXXXXXXX --cc 49 --mcc 123 --mnc 456

cc stands for country code, you will get it from following location.

mcc stands for mobile country code, you can get it from following location.

mnc stands for mobile network code, you will get it from following location.
When I requested for code, unfortunately I got below error.
Error, phone number does not start with the specified country code

Then I tried prefixing the mobile number with country code, it works absolutely fine and got following kind of output.


INFO:yowsup.common.http.warequest:{"status":"sent","length":6,"method":"sms","retry_after":1805}

status: sent
retry_after: 1805
length: 6
method: sms


Step 2: Use following command to register your mobile number.
yowsup-cli registration --register 123456 --phone 49XXXXXXXX --cc 49

Once you type above command, you will get following kind of message.
status: ok
kind: free
pw: 1bwj1aasakanj12gakajlajsdkahk
price: ₹ 55
price_expiration: 14552212360
currency: INR
cost: 55.00
expiration: 1460647515

pw field specifies your password.

Step 3: We need to configure mobile number, country code and password provided in step 2 in a configuration file. Following command gives you the configuration file format.


yowsup-cli demos --help-config
$ ./yowsup-cli demos --help-config

############# Yowsup Configuration Sample ###########
#
# ====================
# The file contains info about your WhatsApp account. This is used during registration and login.
# You can define or override all fields in the command line args as well.
#
# Country code. See http://www.ipipi.com/help/telephone-country-codes.htm. This is now required.
cc=49
#
# Your full phone number including the country code you defined in 'cc', without preceding '+' or '00'
phone=491234567890
#
# You obtain this password when you register using Yowsup.
password=NDkxNTIyNTI1NjAyMkBzLndoYXRzYXBwLm5ldA==
#######################################################


Step 4: Suppose, if your configurations are stored in config.txt, then use following command.
yowsup-cli demos -c config.txt -s 1234567890 "my message"

1234567890 is the  phone number (Add your country code) that you want to send message.

Note
a. If you got any error related to libjpeg, go through following post.

References





No comments:

Post a Comment