Download the PHP package maina-david/whatsapp-sdk without Composer
On this page you can find all versions of the php package maina-david/whatsapp-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maina-david/whatsapp-sdk
More information about maina-david/whatsapp-sdk
Files in maina-david/whatsapp-sdk
Package whatsapp-sdk
Short Description Integrate Facebook Graph API to WhatsApp
License MIT
Homepage https://github.com/maina-david/whatsapp-sdk-php
Informations about the package whatsapp-sdk
WhatsApp PHP SDK
This SDK provides convenient access to the WhatsApp API for applications written in PHP.
Documentation
Take a look at the WhatsApp Business Management API docs here.
Install
You can install the PHP SDK via composer or by downloading the source
Via Composer
The recommended way to install the SDK is with Composer.
Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:
You should publish the config/whatsapp.php config file with:
Set up in the config/whatsapp.php: Phone Number ID, permanent access token and Graph API version you want to use(Default is V15.0) obtained from the Developer's Dashboard.
Usage
You will need to set up a phone number and a permanent access token in Facebook Developer's Portal.
Learn how to create a permanent token
Instantiating the WhatsApp Class
The WhatsApp
class can be instantiated with or without parameters. If no parameters are provided, it will attempt to retrieve the values from the whatsapp configuration file. Alternatively, you can pass the necessary parameters directly when instantiating the class.
In the above example, the WhatsApp
class is instantiated using the $phoneNumberId
and $accessToken
parameters. You can provide these parameters directly or let the class retrieve them from the configuration file if they are not specified.
Remember to replace +123456789
with the actual recipient's phone number and 'Hello, world!'
with the desired message content.
Make sure to adjust the namespace and class name (WhatsApp
) based on your project's structure. Additionally, modify the code inside the sendMessage()
method to match your specific use case.
TextMessage
-
sendTextMessage(array $options)
: Sends a text messagemessage
: Message content.REQUIRED
to
: phone number.REQUIRED
-
sendReplyToTextMessage(array $options)
: Reply to a messagemessage_id
: whatsapp message ID of previous message.REQUIRED
message
: Message content.REQUIRED
to
: phone number.REQUIRED
-
sendMediaMessageByURL(array $options)
: Send a media message with urltype
: media type. Only 'image', 'document', 'audio', 'sticker', 'video'REQUIRED
url
: URL of the media to be sent.REQUIRED
to
: phone number.REQUIRED
caption
: Describes the specified image or video. Do not use it with audio, sticker, or document media.OPTIONAL
filename
: Describes the filename for the specific document. Use only with document media.OPTIONAL
-
sendMediaMessageByID(array $options)
: Send a media message with media IDtype
: media type. Only 'image', 'document', 'audio', 'sticker', 'video'REQUIRED
media_id
: Media ID from WhatsApp.REQUIRED
to
: phone number.REQUIRED
caption
: Describes the specified image or video. Do not use it with audio, sticker, or document media.OPTIONAL
filename
: Describes the filename for the specific document. Use only with document media.OPTIONAL
-
sendReplyToMediaMessageByURL(array $options)
: Send a reply to a media message by URLmessage_id
: whatsapp message ID of previous message.REQUIRED
url
: URL of the media to be sent.REQUIRED
to
: phone number.REQUIRED
-
sendReplyToMediaMessageByID(array $options)
: Send a reply to a media message by IDmessage_id
: whatsapp message ID of previous message.REQUIRED
media_id
: Media ID from WhatsApp.REQUIRED
to
: phone number.REQUIRED
-
sendLocationMessage(array $options)
: Send a location message to a recipientto
: phone number.REQUIRED
latitude
: The longitude of the location.REQUIRED
longitude
: The latitude of the location.REQUIRED
name
: The name of the location.OPTIONAL
address
: The address of the location. This field is only displayed if name is present..OPTIONAL
-
sendReplyToLocationMessage(array $options)
: Send a location message to a recipientmessage_id
: whatsapp message ID of previous message.REQUIRED
to
: phone number.REQUIRED
latitude
: The longitude of the location.REQUIRED
longitude
: The latitude of the location.REQUIRED
name
: The name of the location.OPTIONAL
address
: The address of the location. This field is only displayed if name is present..OPTIONAL
-
markMessageAsRead(array $options)
: Mark a message as readmessage_id
: whatsapp message ID of previous message.REQUIRED
Testing the SDK
The SDK uses PHPUnit as the test runner.
To run available tests, from the root of the project run:
Issues
If you find a bug, please file an issue on the issue tracker on GitHub.