How it works in detail

Updated at

22.12.2017

The project currently consists of five different parts:

  1. Any Android running WhatsApp(R) which could be installed on an old smartphone or in a virtual machine
  2. Custom Android App which collects the notifications
  3. Custom PHP script which receives the notifications
  4. MySQL database to save the messages for further processing
  5. Cronjob which handles the periodically sent emails

Step 1: Install Android and WhatsApp(R)

You can install Android in a virtual machine using VirtualBox or QEMU or use an old smartphone instead. You can use any android version (>4.0) which works best for you. The only important thing is that WhatsApp(R) is working on the device and you have already assigned your account within WhatsApp(R).

Screenshot

Step 2: Create a MySQL database

To store the messages we will need a MySQL database. You can setup the database by importing the file mysql_database_whatscrap.sql which can be found inside the download package.
Note your host, name, username and password as we will need those credentials later and don't forget to grant your database user access to the new database.

Step 3: Set up the custom PHP scripts and install dependencies

Copy the custom PHP scripts (which can also be found inside the download package) onto your webspace and change the variables at the top till they fit your needs. Don't forget to insert your database credentials like mentioned above.

Files in detail:

  • inc/email.php
    • Replace YOURHOSTNAME, YOURUSERNAME, YOURPASSWORD with the credentials for your SMTP
  • inc/init.inc.php
    • nothing to change
  • inc/new_ez_sql_core.php
    • nothing to change
  • inc/new_ez_sql_mysqli.php
    • nothing to change
  • post_whatscrap_message.php
    • Enter your mysql credentials and change your secret API token
  • whatscrap_job.php
    • Enter your mysql credentials and also your mailaddress in the two variables "from" and "to"

Also note the url which points to the script "post_whatscrap_message.php" and your secret API token. We will need it for the next step.

For sending mails we rely on a php Mailer which needs to be installed through those two commands:

pear install Mail

pear install Mail_mime

If you don't want / can't use this library you need to implement your own sendmail command.

Step 4: Set up our custom Android app

Now you install our custom Android app on this virtual machine or your old smartphone. To make it easier for you just open the following url in the browser of your android device to get the file directly onto the machine
whatscrap_v0_1.apk

Screenshot


After installing just start the app and give it the necessary permission to read the notifications.
Therefore open the app "WhatsCrap" and click the three buttons in the upper right corner.

Screenshot

Now choose "Notification Settings" in the menu

Screenshot

and make sure the switch is set to "on"

Screenshot

Now we set the url and secret API token

Screenshot

Here you enter your url

Screenshot

and your secret API token you noted before

Screenshot

Now it's time to test the API connection

Screenshot

If everything is fine you get the following success message. Otherwise the occurred error will be displayed.

Screenshot

Now the app is working in the background waiting for notifications to post to your database.

You can open the app "WhatsCrap" at any time to check if your message notifications from WhatsApp(R) appear here and everything is working fine.

Screenshot

Step 5: Install a cronjob

Now the only missing part is a cronjob which every 15 minutes checks the database for new messages

*/15 * * * * cd /path/to/your/webspace/folder/where/the/files/are/located; php whatscrap_job.php