This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

Overview

What It Does

This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first 1,000 conversations each month are free from WhatsApp Cloud API. A conversation.

Getting Started

Please create and configure your Facebook WhatsApp application following the "Get Stared" section of the official guide.

Minimum requirements – To run the SDK, your system will require PHP >= 7.4 with a recent version of CURL >=7.19.4 compiled with OpenSSL and zlib.

Installation

compose require netflie/whatsapp-cloud-api

Quick Examples

Send a text message



// Require the Composer autoloader.
require 'vendor/autoload.php';

use Netflie\WhatsAppCloudApi\WhatsAppCloudApi;

// Instantiate the WhatsAppCloudApi super class.
$whatsapp_cloud_api = new WhatsAppCloudApi([
    'from_phone_number_id' => 'your-configured-from-phone-number-id',
    'access_token' => 'your-facebook-whatsapp-application-token',
]);

$whatsapp_cloud_api->sendTextMessage('34676104574', 'Hey there! I\'m using WhatsApp Cloud API. Visit https://www.netflie.es');

Send a document

You can send documents in two ways: by uploading a file to the WhatsApp Cloud servers (where you will receive an identifier) or from a link to a document published on internet.



use Netflie\WhatsAppCloudApi\Message\Media\LinkID;
use Netflie\WhatsAppCloudApi\Message\Media\MediaObjectID;

$document_id = '341476474779872';
$document_name = 'whatsapp-cloud-api-from-id.pdf';
$document_caption = 'WhastApp API Cloud Guide';

// With the Media Object ID of some document upload on the WhatsApp Cloud servers
$media_id = new MediaObjectID($document_id);
$whatsapp_cloud_api->sendDocument('34676104574', $media_id, $document_name, $document_caption);

// Or
$document_link = 'https://netflie.es/wp-content/uploads/2022/05/image.png';
$link_id = new LinkID($document_link);
$whatsapp_cloud_api->sendDocument('34676104574', $link_id, $document_name, $document_caption);

Send a template message



$whatsapp_cloud_api->sendTemplate('34676104574', 'hello_world', 'en_US'); // Language is optional

You also can build templates with parameters:



$component_header = [];

$component_body = [
    [
        'type' => 'text',
        'text' => '*Mr Jones*',
    ],
];

$component_buttons = [
    [
        'type' => 'button',
        'sub_type' => 'quick_reply',
        'index' => 0,
        'parameters' => [
            [
                'type' => 'text',
                'text' => 'Yes',
            ]
        ]
    ],
    [
        'type' => 'button',
        'sub_type' => 'quick_reply',
        'index' => 1,
        'parameters' => [
            [
                'type' => 'text',
                'text' => 'No',
            ]
        ]
    ]
];

$components = new Component($component_header, $component_body, $component_buttons);
$whatsapp_cloud_api->sendTemplate('34676104574', 'sample_issue_resolution', 'en_US', $components); // Language is optional

Send an audio message



$audio_link = 'https://netflie.es/wp-content/uploads/2022/05/file_example_OOG_1MG.ogg';
$link_id = new LinkID($audio_link);
$whatsapp_cloud_api->sendAudio('34676104574', $link_id);

Send an image message



$link_id = new LinkID('http(s)://image-url');
$whatsapp_cloud_api->sendImage('', $link_id);

//or

$media_id = new MediaObjectID('');
$whatsapp_cloud_api->sendImage('', $media_id);

Send a video message



$link_id = new LinkID('http(s)://video-url');
$whatsapp_cloud_api->sendVideo('', $link_id, '');

//or

$media_id = new MediaObjectID('');
$whatsapp_cloud_api->sendVideo('', $media_id, '');

Send a sticker message

Stickers sample: https://github.com/WhatsApp/stickers



$link_id = new LinkID('http(s)://sticker-url');
$whatsapp_cloud_api->sendSticker('', $link_id);

//or

$media_id = new MediaObjectID('');
$whatsapp_cloud_api->sendSticker('', $media_id);

Send a location message



$whatsapp_cloud_api->sendLocation('', $longitude, $latitude, $name, $address);

Send a contact message



$name = new ContactName('Adams', 'Smith');
$phone = new Phone('34676204577', PhoneType::CELL());

$whatsapp_cloud_api->sendContact('', $name, $phone);

Features

  • Send Text Messages
  • Send Documents
  • Send Templates with parameters
  • Send Audios
  • Send Images
  • Send Videos
  • Send Stickers
  • Send Locations
  • Send Contacts

Getting Help

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer unit-test

You also can run tests making real calls to the WhastApp Clou API. Please put your testing credentials on WhatsAppCloudApiTestConfiguration file.

composer integration-test

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information. Please see License file for more information.

Disclaimer

This package is not officially maintained by Facebook. WhatsApp and Facebook trademarks and logos are the property of Meta Platforms, Inc.

Comments
  • Send message not working

    Send message not working

    Hello, i tried to use the class and send message but nothing happen and im not receiving any message. i installed using composer and then include the class then i have this code

    $whatsapp_cloud_api = new WhatsAppCloudApi([ 'from_phone_number_id' => 'xx', 'access_token' => 'xx', ]);

    $whatsapp_cloud_api->sendTextMessage('xx', 'Hey there! I'm using WhatsApp Cloud API. Visit https://www.netflie.es');

    am i wrong? btw i used the temporary token

    opened by kevinnyotosusanto 9
  • Support for WhatsApp Interactive Lists

    Support for WhatsApp Interactive Lists

    Implemented support for WhatsApp Interactive Lists. ~~TODO: Unit and integration tests.~~

    https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages#interactive-messages https://documenter.getpostman.com/view/13382743/UVC5FTHT#be4781ec-b59f-4aaa-8bf9-458ff4f29650

    opened by robertripoll 7
  • Facing issue with  Undefined variable: whatsapp_cloud_api

    Facing issue with Undefined variable: whatsapp_cloud_api

    Notice: Undefined variable: whatsapp_cloud_api in E:\xampp_7.4.6\xampp\htdocs\whatsapp_api\wa_cloud_api\index.php on line 14

    Fatal error: Uncaught Error: Call to a member function sendDocument() on null in E:\xampp_7.4.6\xampp\htdocs\whatsapp_api\wa_cloud_api\index.php:14 Stack trace: #0 {main} thrown in E:\xampp_7.4.6\xampp\htdocs\whatsapp_api\wa_cloud_api\index.php on line 14

    opened by maddymathan 5
  • Fatal error: Uncaught Error: Class

    Fatal error: Uncaught Error: Class "Component"

    Fatal error: Uncaught Error: Class "Component" not found in C:\xampp\htdocs\wpnew\b\whatsapp-cloud-api\test.php:49 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wpnew\b\whatsapp-cloud-api\test.php on line 49

    opened by bihariraj 3
  • No puedo enviar a números telefónicos dinámicos

    No puedo enviar a números telefónicos dinámicos

    Estoy intentando que el código lo envíe al número de teléfono que el usuario ingrese. Este número se almacena en una variable.

    image

    En el error si me lee el valor ingresado, pero no me lo toma como válido

    image

    No se me ocurre otra forma de como hacer que el código funcione. (La última línea está repetida porque lo tengo que enviar a varios usuarios, si funciona, pero no con la variable)

    opened by Cesar-jpg 2
  • No puedo enviar mensaje

    No puedo enviar mensaje

    Estoy intentando usar el SDK, ya confirmé y si se envían los mensajes por la consola de Facebook, pero por mi web me aparecen distintos errores

    Este es el código incrustado como está en la documentación image

    y este es el error image

    Si modifico para que encuentre el archivo: image

    Entonces me aparece lo siguiente: image

    Ya intente varias cosas, ya instale todo por composer y aun así no lo encuentra, descargue los archivos y los ingresé a la carpeta de mi proyecto y noté que no está la carpeta "vendor" y "autoload.php"

    Cambie el nombre de la carpeta que decia whatsapp-app-cloud-api-main a WhatsAppCloudApi y me dice que no encuentra la clase image

    opened by Cesar-jpg 2
  • Feat: Support for Whatsapp ID on Send Contact API

    Feat: Support for Whatsapp ID on Send Contact API

    "phones": [
        {
            "phone": "<whatsapp-number>",
            "type": "CELL",
            "wa_id": "<whatsapp-number>"
        }
    ]
    

    The code bellow should include the wa_id like above. If not present, the Contact is not recognized as whatsapp number and it displays the button "Invite to Whatsapp".

    https://github.com/netflie/whatsapp-cloud-api/blob/258aa652fd155b60310728480cdf89d1998e6b49/src/Request/RequestContactMessage.php#L36

    Willing to help sending PR later, But I'm not well versed in tests.

    enhancement 
    opened by vicenterusso 2
  • Como validar conexión

    Como validar conexión

    Hola.

    Cuando realizamos la conexión con: $whatsapp_cloud_api = new WhatsAppCloudApi([ 'from_phone_number_id' => 'your-configured-from-phone-number-id', 'access_token' => 'your-facebook-whatsapp-application-token', ]);

    ¿Como podemos verificar que la conexión fue exitosa?

    opened by daniel89fg 1
  • How to install this package in Laravel?

    How to install this package in Laravel?

    When I run the composer command, I get those errors:

    Info from https://repo.packagist.org: #StandWithUkraine
    Using version ^1.3 for netflie/whatsapp-cloud-api
    ./composer.json has been updated
    Running composer update netflie/whatsapp-cloud-api
    Loading composer repositories with package information
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Root composer.json requires netflie/whatsapp-cloud-api ^1.3 -> satisfiable by netflie/whatsapp-cloud-api[1.3.0].
        - netflie/whatsapp-cloud-api 1.3.0 requires guzzlehttp/guzzle ^7.0 -> found guzzlehttp/guzzle[dev-master, 7.0.0-beta.1, ..., 7.5.x-dev (alias of dev-master)] but it conflicts with your root composer.json require (^6.3).
    
    Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
    You can also try re-running composer require with an explicit version constraint, e.g. "composer require netflie/whatsapp-cloud-api:*" to figure out if any version is installable, or "composer require netflie/whatsapp-cloud-api:^2.1" if you know which you need.
    
    Installation failed, reverting ./composer.json and ./composer.lock to their original content.
    
    opened by tmcdiscord 1
  • Subir archivos a Whatsapp Cloud

    Subir archivos a Whatsapp Cloud

    Hola.

    La librería es capaz de enviar archivos median link o mediante el id que proporciona whatsapp cloud, pero... ¿tenéis algun ejemplo de como enviar el archivo para alojarlo en whatsapp cloud y recibir el id?.

    Gracias.

    opened by daniel89fg 1
  • Can I make other users participate in the conversation?

    Can I make other users participate in the conversation?

    I'm a backend devleoper, and after I have used my phone number as a Whatsapp Cloud API, I cannot seem to access it through my phone whatsapp application.

    So I was wondering if I can use this PHP API to grant access to my client to see his customers interactions with the conversation? And also reply to them?

    Thanks

    opened by tmcdiscord 1
Releases(1.4.0)
  • 1.4.0(Dec 23, 2022)

    1.4.0 - 2022-12-23

    What's Changed

    • Support Interactive Lists by @robertripoll in https://github.com/netflie/whatsapp-cloud-api/pull/58
    • Execute workflow for PHP 7.4, 8.0 & 8.1 versions
    Source code(tar.gz)
    Source code(zip)
  • 1.3.1(Nov 18, 2022)

    Changelog

    1.3.1 - 2022-11-18

    What's Changed

    • Configured PHPStan github action
    • Fix some minor bugs reported by PHPStan analysis
    • Fix Response namespace in ResponseException class
    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Sep 30, 2022)

  • 1.2.0(Jun 2, 2022)

  • 1.1.0(May 29, 2022)

    What's Changed

    • Support for WhatsApp Contact Messages
    • Support for WhatsApp Location Messages
    • Support for WhatsApp Sticker media object
    • Support for WhatsApp Video media object
    • Support for WhatsApp Image media object
    • Support for WhatsApp Audio media object
    • Support for WhatsApp Templates with paramters
    • Support for WhatsApp Document media object
    • Define Integration and Unit PHPUnit testsuites
    • Ignore .php-cs-fixer.dist.php file

    Full Changelog: https://github.com/netflie/whatsapp-cloud-api/compare/1.0.1...1.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
NETFLIE
Software Engineer working in https://netflie.es
NETFLIE
PHP SDK for the Sellix Developers API (developers.sellix.io)

PHP SDK for the Sellix Developers API (developers.sellix.io). Quickly get started and create products, payments and more using PHP.

Sellix 7 Nov 23, 2022
Best resources restful api for developers (with JSON:API standar specification design)

List API Best resources restful api for developers (with JSON:API standar specification design). API Resource Endpoint Name Resource Description Al Qu

Noval 2 Jan 18, 2022
Best resources restful api for developers

Best resources restful api for developers (with JSON:API standar specification design).

Noval 2 Jan 18, 2022
The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructure and leverage the power of 1Password Secrets Automation

1Password Connect PHP SDK The 1Password Connect PHP SDK provides your PHP applications access to the 1Password Connect API hosted on your infrastructu

Michelangelo van Dam 12 Dec 26, 2022
A complete Notion SDK for PHP developers.

notion-sdk-php A complete Notion SDK for PHP developers. Installation composer require mariosimao/notion-php Getting started A Notion token will be n

Mario Simão 77 Nov 29, 2022
The SDK written in PHP for Close partner developers.

Close SDK for PHP The Close SDK for PHP makes it easy for developers to communicate with The Close App in their PHP code. Get started really fast by i

Close Dev Team 3 Jun 23, 2022
A list of all the Belgian stations and their properties used within the iRail project

All stations in Belgium We try to maintain a list of all the stations in Belgium using CSV so everyone can help to maintain it on github. Furthermore,

null 33 Nov 16, 2022
Alibaba Cloud SDK for PHP

English | 简体中文 Alibaba Cloud SDK for PHP Alibaba Cloud SDK for PHP is a development kit that supports quick access to products, dependency on Alibaba

Alibaba Cloud 493 Dec 16, 2022
Qiniu Resource (Cloud) Storage SDK for PHP

Qiniu Cloud SDK for PHP 安装 推荐使用 composer 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 qiniu/php-sdk 。 $ composer require qiniu/php-sdk 直接下载安装,SD

Qiniu Cloud 804 Dec 19, 2022
API documentation API SCB EASY APP

SCB-API-EASY V3.0 API documentation SIAM COMMERCIAL BANK PUBLIC COMPANY LTD. API SCB Easy V3 endpoint = https://fasteasy.scbeasy.link 1.0. Get balance

SCB API Esay team 2 Sep 28, 2021
Laravel package to easily update business KPI monitors for your software or service

Laravel package to easily update business KPI monitors for your software or service. Monitors can be exposed to your user community via mobile app or embedded into your own application.

Heinz Seldte 2 Dec 12, 2022
Facebook SDK for PHP (v6) - allows you to access the Facebook Platform from your PHP app

Facebook SDK for PHP (v6) This repository contains the open source PHP SDK that allows you to access the Facebook Platform from your PHP app. Installa

null 0 Aug 10, 2022
This project was built to connect WHMCS with GridPane.com's API service so we can create sites within WHMCS.

GridPane Server Module for WHMCS This project was built to connect WHMCS with GridPane.com's API service so we can create sites within WHMCS. Discliam

null 10 Sep 2, 2021
A REST API that should power the Agile Monkeys CRM Service

This is a simple REST API that purposes to power the Agile Monkeys CRM service

Dickens odera 3 Jul 31, 2021
Appwrite configuration for Cloud Function runtimes settings 🌩

Appwrite Runtimes Appwrite repository for Cloud Function runtimes that contains the configurations and tests for all of the Appwrite runtime environme

Appwrite 39 Nov 22, 2022
A PHP replacement layer for the C intl extension that also provides access to the localization data of the ICU library.

A PHP replacement layer for the C intl extension that also provides access to the localization data of the ICU library.

Symfony 2.5k Dec 29, 2022
A Symfony bundle that provides #StandWithUkraine banner and has some built-in features to block access to your resource for Russian-speaking users.

StandWithUkraineBundle На русском? Смотри README.ru.md This bundle provides a built-in StandWithUkraine banner for your Symfony application and has so

Victor Bocharsky 10 Nov 12, 2022
A PHP library for the CoinMarketCap API designed to be easy to use.

Help wanted: I don't have enough time to keep updating this library, if you can, don't be shy. Pull requests are welcome. PHP CoinMarketCap API This p

Shahrad Elahi 12 Sep 23, 2022
The NKN open API is a blockchain-to-database parser with an easy to use interface written in PHP

The NKN open API is a blockchain-to-database parser with an easy to use interface written in PHP. We're using Laravel as our framework to provide a clean and maintainable code.

Rule110 - The NKN open source community 7 Jun 26, 2022