ahmedsalah/kenda-communication-plugin

kenda-communication-plugin

0.4 2025-02-25 17:43 UTC

This package is auto-updated.

Last update: 2025-05-12 06:26:59 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.