waaltcom/whatools-php

There is no license information available for the latest version (dev-master) of this package.

PHP lib for integrating Whatools into your app easily.

dev-master 2015-09-22 20:03 UTC

This package is not auto-updated.

Last update: 2025-09-27 23:15:53 UTC


README

PHP lib for integrating Whatools into your app easily

Notice

This lib works only with v3 API. Please make sure your Whatools line is configured to use such API version.

API reference

Setting up

The only thing you need is including this library and then create an API object by passing your Whatools API key as a parameter to the class constructor.

include("whatools.inc.php");
$w = new Whatools("Put here your API key");

Remember that you can get the API key for your Whatools line by logging into Whatools and then going to Advanced settings > REST API.

Logging in and out

Logging in and out is the analog process in v3 API to subscribing and unsubscribing in older API versions. Nevertheless, in v3, when you log out you are effectively closing the connection between WhatsApp servers and your account, so you can be sure that you never miss a single message.

$w->login();
echo "Logged in as +", $w->whatsappInfo->cc, $w->whatsappInfo->pn, "\n";
$w->logout();

Setting your nickname

$w->nicknamePost("John Doe");

Getting your nickname

$nickname = $w->nicknameGet("John Doe");

Setting your status message

$w->statusPost("To be, or not to be, that is the question.");

Getting your status message

$status = $w->statusGet();

Setting your avatar

$w->avatarPost("Route for an image file");

Getting and storing someone's avatar

$avatar = $w->avatarGet("Phone number in international format");
file_put_contents("avatar.jpg", $avatar);

Sending a message

$w->messagePost("Phone number in international format", "Body of the message");

Sending a picture

$w->picturePost("Phone number in international format", "Route for an image file", "Optional caption");

Retrieving and printing messages received and sent since last logout

$messages = $w->messageGet();
foreach ($messages as $message)
{
  if ($msg->mine)
    echo "> ", $msg->to;
  else
    echo "< ", $msg->from;
  echo "\n\t\"", $msg->body, "\"";
  echo "\n\t@", $msg->stamp;
  echo "\n\tACK: ", $msg->ack, "\n";
}