Whatsapp aka. yowsup helper functions

Hey there,
WhatsApp messaging from OH is is already possible via yowsup-cli. I do use it for status updates, etc.
Some built-in helper functions would be awsome. E.g. ability to send images or receive Whatsapp messages and react on them.
Having some helper functions like
sendNotification(“your my.openHAB user email here”, “your text here”)
or
sendMail(String to, String subject, String message, List attachmentUrlList)
would be really great.
I found some documentation about such functionaliry for FHEM (german link) where you can send a message to FHEM via Whatsapp and the system replies. E.g: Q: Whats the temperature? A: 23 degrees celsius

Anyone aware of such functionality in OH already? Or was such idea discussed earlier already? Any link/reference would be great.
Thanks much

2 Likes

I can’t help you out very much but did not know what sending notifications via WhatsApp was possible, I’ll def look into that!

Yes please id be keen for this. Im running telegram just for notifications…it would be awsome to drop it and just use whatsapp… especially if you could send images.

I digged a bit deeper into it and seems that Whatsapp is a bit “unstable”, since yowsup-cli is not a supported connection method. My registered land-line number got banned after a few days.

In fact I’m testing Telegram action right now, which gives quite good and stable results till now. Indeed having only one chat app would be great. And sending messages to Openhab which will give replies, would be good as well.

XMPP (Gtalk) works fine.

I’ve been using pushbullet, which sends images very nicely from the command line. I also experimented with whatsapp, but got banned.

Hi, what’s the status of a WhatsApp integration. Does yowsup still worked. I read about the problem to get banned, however there are some rules to avoid this. Does any kind of number work or do you need a mobile number (I don’t want to take the risk getting banned with my mobile number :slight_smile:

I’m interested too.
Would be a pleasure to have this functionality!

@Nico111 After fiddling around I got yowsup 2.5.7 up and running (see below), BUT after the first message it seems that my number got banned. After getting back to the yowsup Wiki I found this note:

If you use the yowsup-cli command for registration of a new number, you run the risk of being black-listed by WhatsApp after sending your first message. To avoid this, register using an actual mobile device with WhatsApp installed, send a few messages, and then to be safe wait for 12-24 hours before removing your WhatsApp installation and registering the same number using the yowsup-cli as above. See issue 2482 for reference.

for my number it’s to late, but maybe someone else could verify that trick.


Pre-requisite: You need a mobile number, which is not yet registered with WhatsApp, e.g. a prepaid SIM. This is only required once, the SIM is not relevant anymore, but shouldn’t be used in a smartphone with WhatsApp at any time.

1. Install required packages:
Preperation on Linux

sudo apt-get update
sudo apt-get install libncurses5-dev

Preperation on Mac (needs Homwbrew)

brew install wget --with-libressl
brew install ncurses

Install Python modules:

pip install --upgrade pip 
pip install argparse
pip install python-dateutil
pip install --upgrade readline
pip install protobuf
pip install pycrypto
pip install python-axolotl-curve25519
pip install --upgrade pillow

go to the directory where you want to download and build yowsup

wget https://github.com/tgalal/yowsup/archive/master.zip
unzip master.zip
cd yowsup-master/

don’t run setup.py yet!

2. Updating WhatsApp version

You need to update the WhatsApp version and a key, otherwise you get error “old_version”!

You find suitable settings under https://coderus.openrepos.net/whitesoft/whatsapp_scratch

{"a": "HVpGIJI3MRi3wZmsvjJDqw==", "b": "PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk", "c":"1478194306452L", "d":"**2.18.355**", "e":"2.16.12", "f":"2.11.634", "g":"PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk", "h":"1478194472015L", "i":"PdA2DJyKoUrwLw1Bg6EIhzh502dF9noR9uFCllGk", "j":"1478194472015L"}

Use parameter a and d and update the file yowsup/env/env_android.py

nano yowsup/env/env_android.py
and change the lines
_MD5_CLASSES = "<hash>"
_VERSION = "<version>"

for example:

_MD5_CLASSES = "HVpGIJI3MRi3wZmsvjJDqw=="
_VERSION = "2.18.355"

Now build and install yowsup

Linux:
python ./setup.py install 

MacOS:
python2 ./setup.py install 

3. WhatsApp registration
You need to lookup Mobile Country Code (MCC), the Mobile Network Code (MNC) and the normal Country Code (CC) you want to use:
Open https://en.wikipedia.org/wiki/Mobile_country_code and look for MCC and MNC. Those identify the mobile network you are using, e.g. MCC=262 for Germany and MNC=1 for Telekom, MNC=2 for VodafoneDE etc.

Run the WhatsApp registration:

yowsup-cli registration -d -E android -m <MCC> -n <MNC> -p <phone number> -C <country code> -r sms

Example: Germany (MCC=262, Country Code=49) and T-Mobile (MNC=1), phone number 491711234567
yowsup-cli registration -d -E android -m 262 -n 1 -p 491711234567 -C 49 -r sms

Make sure to prefix your phone number also with the country code, in this case 49xxxx. Do not include the 0 for the phone number, e.g. 01711234567 becomes 491711234567.

As a result you receive a SMS on your mobile phone. You need the 6 digit registration code in format XXX-XXX sent by WhatsApp. SMS text will be something like:

Your WhatsApp code: XXX-XXX
...

Registration will be completed with the following command:

yowsup-cli registration -d -E android -p <CC><phone number without 0> -C <CC> -R <Registration Code>

for example: yowsup-cli registration -d -E android -p 491711234567 -C 49 -R 123-456

Now you should receive a result like this one:

status: ok
kind: free
pw: <password>
price: $0.99
price_expiration: 1543012826
currency: USD
cost: 0.99
expiration: 4444444444.0
login: <phone number>

Generate some keys with the following command:

./yowsup-cli demos -l "491711234567:XXXXXX0uB6IMp9spB9FqedKFak=" -y

This opens the yowsup command line interface.

Do a Quick Login by entering "/L<return>"

This should result in a response like:

INFO:yowsup.layers.axolotl.layer_control:Axolotl layer is generating keys
Auth: Logged in!
general: Disconnected: Requested

4. Sending messages
Finally you are able to send messages.

yowsup-cli demos -l "<originating number>:<password from previous step>" -s <destination number> "<message>"

example: 
yowsup-cli demos -l "491711234567: XXXXXX0uB6IMp9spB9FqedKFak =" -s 491727654321 "Welcome to openHAB"

You should receive the message in WhatsApp on the target phone :wink:

3 Likes

Thanks - that’s really helpful. Have you been able to avoid being banned, though?

I spend another 10€ for a 2nd number, currently in “regular use mode”, will try tomorrow or Tuesday again a yowsup - let’s see :slight_smile:

If that’s work out I’m thinking on building a binding.

https://rafavg77.wordpress.com/2015/09/21/playing-with-yowsup-cli-2-0-receive-messages-and-do-stuff/ shows how easy it is to modify the echo client. This means that you would be able to build some kind of Bot, which receives commands and passes them to a OH item triggering a rule etc.

Let’s wait and see…:sunglasses:

1 Like

That’s great. I gave up on yowsup, having set up a couple of accounts and immediately gotten banned. However I didn’t do what you suggest, and spend a few days in “regular use” mode.

Mission accomplished. After 2 days of “regular use” I was able to register and play some message ping pong. That’s what I did

  • insert a new SIM
  • install WhatsApp
  • Start conversations with several numbers in your address book - do some ping pong
  • did that for 1,5d
  • deinstalled Whatsapp (you still need the SIM for the registration SMS)
  • register with yowsup and the registration SMS (see above)
  • SIM removed from phone
  • use different phone to send 2 messages to this number from 2 different contacts
  • start sending messages with yousup - you should them incoming messages on the console
  • did some ping pong with 2 contacts

I don’t know if that’s really required, but that’s what I did. I suppose it’s important to show some regular use and let some time went by before switchting to yowsup.

Let’s see if it still works tomorrow :slight_smile:

stll up :slight_smile:

Echo Client is also working

yowsup-cli demos -l "49170XXXXXXX:XXXXXXXXLQkjHw2/faNBL0XXXX=" -e

will echo any message sent.


An image send to the number is received, the client receives an URL in the format

https://mmg-fna.whatsapp.net/d/f/Ajug-qaFkGZ9FEv-pDTFtQlFbFjt-hUuvTXXXXXXXXXX.enc

It seems that the file is encrypted by itself. I found this link https://www.quora.com/How-can-I-decrypt-an-encrypted-WhatsApp-file, but didn’t looked into details.

1 Like

Thanks for looking into this and being everyone’s guinea pig!

still working, so how to proceed?

if it’s still working for you after a week then I’ll try too!

It’s still running, so I started working on a first version of a binding.

I update the install doc above to include macOS (my dev environment) and already get it running (make sure you run with python2 not with python command to execute setup.py).

Lets see…

2 Likes

still running! :slight_smile:

I encountered the following problem when moving to the dev system:

WARNING:yowsup.layers.axolotl.layer_receive:InvalidMessage or InvalidKeyIdException for xxxxxxxxxx, going to send a retry

also described here

I found the following solution:

There is a little annoying solution, that i am using since 2 month and it always works.

1. login with the yowsup cli (... -y).
2. /L
3. /disconnect

repeat step 2 and 3 repeatedly until it resolves. it will auto generate the key.
maybe you have to try 50 to 100 times to solve it keep patience , it will work.
Try deleting the .yowsup folder, and then try again.

What helped me was just sending messages in both directions, also using the echo client (-e).

Important Note:

  • Be aware not to fix the same phone number (MSISDN) on multiple servers. You need one number per server to avoid those issues!
  • This could also happen when you start more than once instance on the same system (I suppose that caused the problem on my dev system)
1 Like

@dan12345 First messages send and received :slight_smile:

If you are interested I could provide an alpha1 tomorrow. I’ll add some documentation and want to discuss some design aspects.

PS: I looked into support for media files, but this is not yet in the focus. You get an url to an encrypted file, so the plan might be to download the file, decrypt it and then provide the URL to the local file to an item, which can then be processed in a widget etc. to get displayed to the user.
The community knows: https://github.com/tgalal/yowsup/issues/1449

2 Likes