PHPackages                             psbhanu/whatsapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. psbhanu/whatsapi

ActiveLibrary[API Development](/categories/api)

psbhanu/whatsapi
================

Wrapper for Whatsapp messenger

1365[1 issues](https://github.com/psbhanu/whatsapi/issues)PHP

Since Nov 22Pushed 9y ago2 watchersCompare

[ Source](https://github.com/psbhanu/whatsapi)[ Packagist](https://packagist.org/packages/psbhanu/whatsapi)[ RSS](/packages/psbhanu-whatsapi/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Whatsapi
========

[](#whatsapi)

Wrapper for [whatsapp/chat-api](https://github.com/mgp25/Chat-API), that allows us send messages through WhatsApp. Thanks guys.

### Installation

[](#installation)

**Non Laravel users**

If you're not a Laravel user you only need to run the composer require command in order to install the needed package.

```
    composer require psbhanu/whatsapi

```

**Laravel users**

Assuming you already have composer installed on your system, install a new [Laravel](http://laravel.com/) project into `whatsapidemo` folder

```
    composer create-project laravel/laravel whatsapidemo --prefer-dist

```

Ensure that you set webserver to use `whatsapidemo/public` as it's webroot. Now, if you visit  (or whatever domain name you are using) you should see a nice Laravel welcome message.

Change into your new `whatsapidemo` folder.

```
    cd whatsapidemo

```

Require the needed package.

```
    composer require psbhanu/whatsapi

```

If you get `[InvalidArgumentException] Could not find package psbhanu/whatsapi at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability` you must add these lines to your composer.json an then re-run previous command.

```
    "minimum-stability": "dev",
    "prefer-stable" : true

```

We tell Laravel that there is a Whatsapi ServiceProvider. At the end of `config/app.php` file, in the providers array, add:

```
    'psbhanu\Whatsapi\WhatsapiServiceProvider'

```

Finally, Into the `config/app.php` file, add to aliases array each of these lines

```
    'Whatsapi' => 'psbhanu\Whatsapi\Facades\Laravel\Whatsapi',
    'WhatsapiTool' => 'psbhanu\Whatsapi\Facades\Laravel\Registration',

```

### Configuration

[](#configuration)

**Non Laravel users**

If you're using another Framework, different from Laravel, you must put manually the config file `Config/config.php` on the right path.

```
    // Include the composer autoload file
    include_once "vendor/autoload.php";

    // Import the necessary classes
    use psbhanu\Whatsapi\Facades\Native\Whatsapi;
    use psbhanu\Whatsapi\Facades\Native\Registration;

    // Or, if you want you can add a class alias
    // class_alias('psbhanu\Whatsapi\Facades\Native\Whatsapi', 'Whatsapi');
    // class_alias('psbhanu\Whatsapi\Facades\Native\Registration', 'Registration');

```

Now, we tell Whatsapi about the config values.

```
    // Of course, you can use the Config class from your favorite Framework.
    $config = __DIR__ . 'config/whatsapi.php';

    Whatsapi::setConfig($config);

```

By default, the native implementation session use the `$_SESSION` global var, you can override this providing a instance that implements the contract `psbhanu\Whatsapi\Sessions\SessionInterface`.

```
    # Codeigniter 3 example

    use CI_Session;
    use psbhanu\Whatsapi\Sessions\SessionInterface;

    class SessionManager implements SessionInterface{

        # The key used in the Session.
        protected $key = 'itnovado_whatsapi';

        # Session object.
        protected $session;

        public function __construct(CI_Session $session)
        {
            $this->session = $session;
        }

        public function getKey()
        {
            return $this->key;
        }

        public function put($value)
        {
            $this->session->set_userdata($this->getKey(), $value);
        }

        public function pull()
        {
            $data = $this->session->userdata($this->getKey());

            $this->session->unset_userdata($this->getKey());

            return $data;
        }
    }

    // Get some resources
    $ci =& get_instance();
    $ci->load->driver('session');

    $sessionManager = new SessionManager($ci->session);

    // Override the default session implementation
    Whatsapi::setSessionManager($sessionManager);

```

**Laravel users**

We need to publish the config file that will allow you to very easily add all your account numbers.

```
    php artisan vendor:publish --provider="psbhanu\Whatsapi\WhatsapiServiceProvider" --tag="config"

```

Now everything has been installed, you just need to add your Whatsapp account details into the config file. There will now be a personal config file created for you in `whatsapidemo/config/whatsapi.php`. Open this file and edit the details with your account info. Once saved, you're good to use the API!

### Usage

[](#usage)

**Note:** You must create the data storage path specified in configuration file. The path must be writable for webserver.

**Request registration code**

When requesting the code, you can do it via SMS or voice call, in both cases you will receive a code like 123-456, that we will use for register the number.

```
    $number = '5219511552222'; # Number with country code
    $type = 'sms'; # This can be either sms or voice

    $response = WhatsapiTool::requestCode($number, $type);

```

Example response:

```
    stdClass Object
    (
        [status] => sent
        [length] => 6
        [method] => sms
        [retry_after] => 1805
    )

```

**Registration**

If you received the code like this 123-456 you should register like this '123456'

```
    $number = '5219511552222'; # Number with country code
    $code = '132456'; # Replace with received code

    $response = WhatsapiTool::registerCode($number, $code);

```

If everything went right, this should be the output:

```
    [status] => ok
    [login] => 34123456789
    [pw] => 0lvOVwZUbvLSxXRk5uYRs3d1E=
    [type] => existing
    [expiration] => 1443256747
    [kind] => free
    [price] => EUR€0.99
    [cost] => 0.89
    [currency] => EUR
    [price_expiration] => 1414897682

```

See the entire registration process on

**Send messages**

```
    // Retrieve user data from database, web service, and so on.
    // Dummy method, fake data.
    $user = new stdClass;
    $user->name = 'Benjamín Martínez Mateos';
    $user->phone = '5219512222222';

    $message = "Hello $user->name and welcome to our site";

    $messages = Whatsapi::send($message, function($send) use ($user)
    {
        $send->to($user->phone);

        // Add an audio file
        $send->audio('http://itnovado.com/example.mp3');

        // Add an image file
        $send->image('http://itnovado.com/example.jpg', 'Cool image');

        // Add a video file
        $send->video('http://itnovado.com/example.mp4', 'Fun video');

        // Add a location (Longitude, Latitude)
        $send->location(-89.164138, 19.412405, 'Itnovado Location');

        // Add a VCard
        $vcard = new psbhanu\Whatsapi\Media\VCard();

        $vcard->set('data', array(
            'first_name' => 'John',
            'last_name' => 'Doe',
            'tel' => '9611111111',
            ));

        $send->vcard('Xaamin', $vcard);

        // Add new text message
        $send->message('Thanks for subscribe');
    });

    foreach($messages as $message)
    {
        ...
    }

```

**Check for new messages**

```
    $messages = $messages = Whatsapi::getNewMessages();

    if($messages)
    {
        foreach($messages as $message)
        {
            ...
        }
    }

```

**Sync contacts**

```
    $result = Whatsapi::syncContacts(['5219512222222', '5219512222223']);

    foreach ($result->existing as $number => $account)
    {
        ...
    }

    foreach ($result->nonExisting as $number)
    {
        ...
    }

```

Example response

```
    SyncResult Object
    (
        [index] => 0
        [syncId] => 130926960960000000
        [existing] => Array
            (
                [+5219512222222] => 5219512222222@s.whatsapp.net
            )

        [nonExisting] => Array
            (
                [0] => 5219512222223
            )

    )

```

**Missing methods**

You can use all power of the [whatsapp/chat-api](https://github.com/mgp25/Chat-API) getting and instance of `Whatsprot` class. Read the whatsapp/chat-api [wiki](https://github.com/mgp25/Chat-API/wiki) for available methods.

```
    $whatsprot = Whatsapi::gateway();

    // Do stuff...

```

You can use on routes, cli... you got the idea.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e442f7fe4a2ff61f57b5b816f07586e4eeb8a4514f1ea7c7ca91a0c3f2af7d85?d=identicon)[psbhanu](/maintainers/psbhanu)

### Embed Badge

![Health badge](/badges/psbhanu-whatsapi/health.svg)

```
[![Health](https://phpackages.com/badges/psbhanu-whatsapi/health.svg)](https://phpackages.com/packages/psbhanu-whatsapi)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
