ahmedsalah / kenda-communication-plugin
kenda-communication-plugin
Fund package maintenance!
kenda
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/contracts: ^10.0||^11.0
- spatie/crypto: ^2.1
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- spatie/laravel-ray: ^1.35
This package is auto-updated.
Last update: 2025-05-12 06:26:59 UTC
README
Overview
The Kenda Communication Plugin is a Laravel package designed to facilitate communication between your Laravel application and WhatsApp services. It provides a structured way to register devices, websites, and functions, ensuring secure and seamless integration with remote servers.
Installation
You can install the package via Composer:
composer require ahmedsalah/kenda-communication-plugin
Configuration
Publish the configuration file using the following command:
php artisan vendor:publish --tag="kenda-communication-plugin-config"
This will create a configuration file containing:
return [ 'api_key' => env('KENDA_COMMUNICATION_PLUGIN_API_KEY', 'kn-...'), 'from_phone' => env('KENDA_COMMUNICATION_PLUGIN_FROM_PHONE', '254712345678'), 'public_key_path' => env('KENDA_COMMUNICATION_PLUGIN_PUBLIC_KEY_PATH', 'public_key_server.kendaKey'), 'enable_user_resolving' => env('KENDA_COMMUNICATION_PLUGIN_ENABLE_USER_RESOLVING', true), 'enable_guest_user' => env('KENDA_COMMUNICATION_PLUGIN_ENABLE_GUEST_USER', true), 'user_model' => env('KENDA_COMMUNICATION_PLUGIN_USER_MODEL', 'App\Models\User'), 'user_phone_number_column' => env('KENDA_COMMUNICATION_PLUGIN_USER_PHONE_NUMBER_COLUMN', 'phone_number'), 'functions' => [ 'example_function' => 'App\KendaCommunicationPlugin\Functions\ExampleFunction', ], ];
Usage
1. Register a New Device
To begin, you must register a WhatsApp number (Device) with the server.
2. Register Your Website
Once the device is registered, register your website on the server. This allows your website to communicate with the API and receive user requests.
3. Register Your Functions
Functions must be registered on the server to allow your Laravel application to execute them remotely.
4. Map Local Functions to Remote Server Functions
Each registered function must be mapped to a local function in your Laravel application.
Generate a function file:
php artisan kenda:generate-function
Then, map the function in the config file:
return [ 'functions' => [ 'createUser' => 'App\KendaCommunicationPlugin\Functions\CreateUser', 'writeArticle' => 'App\KendaCommunicationPlugin\Functions\WriteArticle', ], ];
Additional Features
Sending WhatsApp Messages
You can send WhatsApp messages directly to users using the following function:
KendaCommunicationPlugin::sendWhatsappMessage(string $targetPhone, string $message);
This feature is useful for notifications and reminders. However, avoid excessive messaging to prevent getting blocked by WhatsApp.
Testing
Run the test suite using:
composer test
Changelog
Refer to the CHANGELOG for a record of recent changes.
Credits
License
This package is open-source under the MIT License. See LICENSE for details.