Download the PHP package balfour/whatsapp-client without Composer
On this page you can find all versions of the php package balfour/whatsapp-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download balfour/whatsapp-client
More information about balfour/whatsapp-client
Files in balfour/whatsapp-client
Package whatsapp-client
Short Description A library for handling WhatsApp communication via the chat-api.com API
License MIT
Informations about the package whatsapp-client
whatsapp-client
A library for handling WhatsApp communication via the unofficial chat-api.com WhatsApp API.
This library is in early release and is pending unit tests.
Legal Notice
This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial API written for educational purposes only and should be used at your own risk.
Table of Contents
- Installation
- Usage
- Creating a Client
- Sending a Message
- Sending a File
- Retrieving Messages
- Rebooting the VM
- Building a Bot
- Actions
- SendMessageAction
- SendFileAction
- SendMenuAction
- EscapeMenuAction
- SendAndActivateMenuAction
- Custom
- Triggers
- StringTrigger
- StartsWithTrigger
- RegexTrigger
- Menus
- Single Menu
- Nested Menus
- Middleware
- Full Example
- Emulator
- Actions
Installation
Usage
For further documentation on chat-api, please see https://chat-api.com/en/swagger.html
Creating a Client
Sending a Message
Sending a File
Retrieving Messages
Rebooting the VM
Building a Bot
A full usage example connecting triggers, actions & middleware is available below.
Actions
An action is a response which is executed when a trigger or menu option is matched.
The packages comes bundled with the following actions:
SendMessageAction
This action responds with a message.
SendFileAction
This action responds with a file (or image) attached.
SendMenuAction
see menus
EscapeMenuAction
see menus
SendAndActivateMenuAction
see menus
Custom
You can build your own actions by creatin a custom class which implements the ActionInterface
.
Here is an example action which repeats the inbound message.
Triggers
A trigger is an inbound keyword or phrase which executes an action.
The following triggers are supported:
StringTrigger
The inbound message must be an exact match.
StartsWithTrigger
The inbound message must start with the specified string.
RegexTrigger
The inbound message must match the given regex pattern.
Menus
Single Menu
This is an example of a single menu.
The menu must be activated using a trigger. (see full example at end)
Nested Menus
This is a more complicated example with multiple nested menus.
In order to keep state of which menu the user is currently in, we must use an implemntation of
a MenuStateStoreInterface
. For testing purposes, this package comes bundled with a
InMemoryMenuStateStore
; however in the real world, you'll likely want to use a store which
persists across multiple php processes, such as a redis cache.
Middleware
The bot uses middleware to match the inbound message to a trigger or a menu option. These are
called ProcessTrigger
and ProcessMenuOption
respectively.
You can also write your own middleware by creating a class which implements the MiddlewareInterface
.
Full Example
This example is copied from the emulate.php
script and can be run locally using
php emulate.php
.
Emulator
The package includes an emulator script which allows you to test your menu options and triggers without sending real world messages.
You can run the emulator using php emulate.php