Whatsapp aka. yowsup helper functions

Great I can test this . Enabling what’s app on new mobile #.

awesome. I just got a new SIM and will start using whatsapp on the phone for a couple of days, before getting going with yowsup.

This is fantastic. I’m looking forward to test it!
Will we be able to send messages within the rules DLS?

A “postUpdate” to the outbound message channel should work

perfect

yes, bind the channels to items and then postUpdate on the item as @hmerk mentioned.

I olan to support

  • sendung text messages
  • receiving text messages
  • receiving medial urls (audio/video/puctures). In this case the item will receive the url of the unencrypted media file, which could then use to disllay the media content etc.

There will be 2 types of channels

  • messageIn/Out: using the syntax number:message and
  • mediaIn (Out may be added at a later stage), which uses json to provide the additional properties
  • I’ll use channel groups to seperate them
    This means also that the channel names will change, so you need to deleteand re-add the thing, but this is easy going.

@hmerk What’s about frequent item updates on multiple messages? Does OH handles kind of queuing, so the updates get delivered to a rule one by one or do I need to implement some time of queueing (messages gets queued until the channel is read or a timer expired)

Are there other features you like to see?

Please be aware: It’s a alpha1, so don’t expect that there are no bugs etc. Please provide TRACE log if you encounter problems.

sending image files would be awesome - at the moment I use pushbullet for that (but not the binding, as the pushbullet binding doesn’t support images)

Thanks for a brilliant tutorial - works perfectly. One minor suggestion - for consistency, where you show how to generate keys, you could write it as:

./yowsup-cli demos -l "<CC><phone number without 0>:<password from previous step>" -y

Which would stop idiots like me from simply copying your phone number and then being surprised it doesn’t work.

Dan

Thanks for the hint. Everything is welcome to make handling for the community easier. I changed the post above - I think that’s what you mean?

I’m going to publish the repository on GitHub soon and create a README including the information from this thread. This will provides access to the lastest build, but also give you the opportunity to contribute to the project and the documentation. This will also include grouping of channels so that the channel names will be the same in upcoming releases.

I look into the media files topic:

  • this release of yowsup supports image/video/audio
  • sending media files should be easy, because yowsup seems to also handle the encryption
  • receiving media files is a little more tricky, because you only get the URL to the encrypted file, so decryption runs locally and it’s not auto-performed by yowsup. I found just a few lines to build it in, but this requires a PR to yowsup or a manual update to one of the .py files. The problem with yowsup in general is that it seems that the initiator is no longer maintaining the project. However the stuff I need so far is working without problems. There are several forks, but I need to check, which one would be the best fit and actively maintained. So receiving media files will take some time. Sending is more important, one use case would be to send a picture from your web cam on alarm events etc.
  • In addition receiving media files of type VCARD don’t provide the .vcf itself (only the meta data) -> ok, because I don’t see a use case here.
  • Receiving media files of type documents could/do crash yowsup -> I also don’t see a use case, but sending an image to openHAB could cause yowsup to terminate. I’ll add some kind of auto-recovery, which detects is situation (process no longer running and a Trace Back log on the console), which restarts yowsup automatically -> should do the work around.

PS: My account is still working, since 2 weeks

thanks

my attempts to get yowsup working with images have been a dismal failure - basically my python skills are way insufficient and there are no clear tutorials I can find…

you are probably going to be more successful!

What do you mean? The tutorial above should be all you need. You just need to understand that Python is not a script language like it looks from a first point of view. So every change you make to the .py files requires an "./setup.py install/ in the yowsup-master directory. You could also check if there is a directory

/root/.yowsup and
/root/.yowsup/<number>

Those should be filled after the installation/key have been generated. I’ll add a check to the binding that verifies that at least the directories exist.

but beside that you don’t need any Python knowledge.

What’s your problem?
fyi: The Binding sits on top of yowsup-cli (in fact I “only” control the cli from the binding and bring the things together), which means if you basic yowsup setup is not working the binding will not work, I thought to directly integrate the Python code into the binding (Java), but this is way more complex (using e.g, Jython) and for the moment I don’t see significant benefits. My Python knowledge is the same as yours = 0,001%, but I got it running and could support you (learnings could be reflected in the documentation).

If you could run the cli (-y) from command , login (/L), send a message (/send “”) and receive a message (from you mobile) everything should be fine. Configure the right path to yowsup-cli (default should be /usr/local/bin/yowsup-cli, check with ls if it’s really there, otherwise the thing should stay offline and you see an error message in the log/PaperUI) in the thing properties and start using it :slight_smile:

I should have explained - my problem is that your tutorial works fine, and sending text messages works fine. But sending images using /send from the yowsup command line gives a “request upload for file test.jpg for 123456@s.whatsapp.net failed” error. The various solutions for this online seems to all involve python expertise way beyond mine…

Maybe the problem is that the media file has to be encrypted before it will be sent out. When you try to send a image to yowsup you could that a url is received with a file having the extension .enc, which means it’s encrypted and needs to be decrypted. That’s what I mentioned above. And I could imagine that that same thing has to be done when sending media.

Are you ready to install the binding.

ok, I found a fork, which adds media support and is also more up-to-date:

This fork switches to Python 3, version 2 is no longer supported.
you need more modules installed - otherwise it will even not start

For Mac - not yet tested with Raspberry:

You need to install the modules listed above for Python 3

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

Mac only

brew install freetype imagemagick exiftool ffmpeg pkg-config
brew install libmagic
cd /usr/local/lib/
ln -s ../Cellar/libmagic/5.35/lib/libmagic.dylib libmagic.dylib

plus the additional modules for media support

pip3 install preview-generator
pip3 install xvfbwrapper
pip3 install urllib3
pip3 install idna
pip3 install chardet
pip3 install certifi
pip3 install cryptography

Download and install preview_generator

Download https://files.pythonhosted.org/packages/ce/17/9eeb6bc3a7cc1dc8ba7db35a2038c61bef49336ec21057258801e9aef2a5/preview_generator-0.9.tar.gz

unzip preview_generator-0.9.tar.gz
phyton3 ./setup.py install


Installing the new yowsup fork
Now download the new fork - clone this one to a new working dir

git clone https://github.com/AragurDEV/yowsup.git

Now run yowsup-cli with -y

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

If you get a message “ModuleNotFoundError: No module named ‘Crypto’:” then run the following:

pip3 uninstall crypto
pip3 uninstall pycrypto
pip3 install pycrypto

If you get an error that MagicWand is not found:

I seems that MagicWand doesn't support imagemagick 7 yet as mentioned in other answers.
There's a new brew formula for Imagemagick 6 which can be used to install the older version in the meanwhile:

brew install imagemagick@6
Create a symlink to this newly installed dylib file as mentioned in other answer to get things working.
ln -s /usr/local/Cellar/imagemagick@6/<your specific 6 version>/lib/libMagickWand-6.Q16.dylib /usr/local/lib/libMagickWand.dylib

In my case:
ln -s /usr/local/Cellar/imagemagick@6/6.9.10-14/lib/libMagickWand-6.Q16.dylib /usr/local/lib/libMagickWand.dylib

New you could send a image on the yowsup-cli:

/image send <number> <image file>

If you see the error “ERROR:yowsup.layers.protocol_media.mediauploader:Error occured at transfer object of type ‘int’ has no len()” run

pip3 uninstall pyOpenSSL

see https://github.com/danielcardeenas/whatsapp-framework/issues/133

I’m still working on sending videos.

thanks - this is the step that foxed me before… when running the forked yowsup I get a ImportError: No module named preview_generator.manager error.

Am certainly ready to install the binding and test it.

did you run

pip3 install preview_generator

It’s important to get the fork running so we are working on the same build.

Thanks for your patience!

I now have the fork running, and it sends text messages fine. But when I tried to send an image I got this error:

[connected]:ERROR:yowsup.layers.protocol_media.mediauploader:Error occured at transfer object of type 'int' has no len()
[etc]

But thanks to a commentator on this thread: https://github.com/danielcardeenas/whatsapp-framework/issues/133 I found the solution - uninstall pyopenSSL (pip3 uninstall pyOpenSSL).

Now I have text and images working perfectly. So good to take it from here!

here we are: alpha1 is on GitHub:

I tried to conclude the above installation instructions to the README.md, but didn’t verified if this works on a clean system. The current status is macOS only, Raspberry will follow, but I have no Windows to create the install steps - maybe someone else could help (clone the repository, edit doc and create a PR).

The jar can be found here:
https://github.com/markus7017/org.openhab.binding.whatsapp/blob/alpha1/target/org.openhab.binding.whatsapp-2.4.0-SNAPSHOT.jar
copy to your <oh-dir&Guten Tag,;/addons folder.

Please make sure that your yowsup installation is up and running (you could send/receive text messages).

Configuration is pretty simple:

  • Open PaperUI and change to Configuration-&Guten Tag,;Things
  • Press the ‘+’ button
  • Select the WhatsApp Binding -> WhatsApp Hub
  • Enter the originating number registered with yowsup-cli
  • and the password created by the registration
  • check the path to yowsup-cli

The thing should come up immediately and change to status ONLINE.

Link the messageOut and messageIn channel to an items, e.g. waSend and waReceived.

You could send a message from a rule, e.g. postCommand(waSend, “<number>:<message>”

An inbound message is posted to the messageIn channel in the same format.

@dan12345 could you send and/or receive video, audio, document, vcard, location using you yowsup installationen?

So far my results:
Text in: ok
Text out: ok

Image in: message received, but url points to encrypted filed
Image out: ok

Video in: Message is received, but attachment is encrypted
Video out: nothing happens

Audio in: Message is received, but attachment is encrypted
Audio out: not yet tested

Document in: nothing happens
.txt: “[Media Type: document]” is received, but no additional information (e.g. url)

Docoument out:

  • pdf: “Exception: Unable to get page count. Is poppler installed and in PATH?”
    popler installed with “brew install poppler” -> ok

Localtion out: ok
Location in: Message MediaType: location, but no other information

VCard out: ok
VCard in: “[Media Type: document]”, but no other information

Working media formats is a pre-requisite for integration into the binding.

apologies for the delay responding - been away.

Sending text, images and location works fine.

Sending video and audio: nothing happens

Sending document: stream of errors when sending a simple text file

Couldn’t work out how to send vcard

And - I’m probably being very slow - but I can’t see how to receive anything using the yowsup CLI. What am I missing?

Dan