PHP code example of glueful / conversa

1. Go to this page and download the library: Download glueful/conversa library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glueful / conversa example snippets


use Glueful\Notifications\Services\ChannelManager;

$sms = container()->get(ChannelManager::class)->getChannel('sms');
$sms->send($user, ['body' => 'Your appointment is tomorrow at 9am']);

use Glueful\Notifications\Contracts\Notifiable;

class User implements Notifiable
{
    public function routeNotificationFor(string $channel)
    {
        return match ($channel) {
            'sms', 'whatsapp' => $this->phone, // E.164, e.g. +15551234567
            default => null,
        };
    }
    // getNotifiableId(), shouldReceiveNotification(), getNotificationPreferences() …
}

use Glueful\Extensions\Conversa\ConversaService;

$conversa = app($context, ConversaService::class);

// Free-text SMS / WhatsApp
$conversa->send('whatsapp', '+15551234567', ['body' => 'Welcome to Acme!']);

// WhatsApp template (resolved to a provider template via `templates` config)
$conversa->send('whatsapp', '+15551234567', [
    'template' => ['name' => 'order_shipped', 'variables' => ['1Z999']],
]);

// Idempotent send — a repeat key returns the original message without sending again
$result = $conversa->send('sms', '+15551234567', ['body' => 'Your order has shipped'], [
    'idempotency_key' => 'order-4711-shipped',
]);
// $result->ok, $result->providerMessageId, $result->error