1. Go to this page and download the library: Download vntrungld/laravel-crisp 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/ */
vntrungld / laravel-crisp example snippets
use LaravelCrisp;
// Get the Crisp client instance
$client = LaravelCrisp::client();
// Example: Send a message
$client->websiteConversations->sendMessageInConversation(
'website_id',
'session_id',
[
'type' => 'text',
'content' => 'Hello from Laravel!'
]
);
use Vntrungld\LaravelCrisp\LaravelCrisp;
class YourController extends Controller
{
public function __construct(protected LaravelCrisp $crisp)
{
}
public function sendMessage()
{
$client = $this->crisp->client();
// Use the client...
}
}
use Illuminate\Support\Facades\Event;
use Vntrungld\LaravelCrisp\Events\WebhookReceived;
Event::listen(WebhookReceived::class, function (WebhookReceived $event) {
$payload = $event->payload;
// Handle the webhook payload
logger('Crisp webhook received', $payload);
// Example: Handle message sent event
if ($payload['event'] === 'message:send') {
// Process the message...
}
});
php artisan make:listener HandleCrispWebhook
namespace App\Listeners;
use Vntrungld\LaravelCrisp\Events\WebhookReceived;
class HandleCrispWebhook
{
public function handle(WebhookReceived $event): void
{
$payload = $event->payload;
match($payload['event']) {
'message:send' => $this->handleMessageSent($payload),
'message:received' => $this->handleMessageReceived($payload),
// ... other event types
default => null,
};
}
protected function handleMessageSent(array $payload): void
{
// Your logic here
}
protected function handleMessageReceived(array $payload): void
{
// Your logic here
}
}
use Vntrungld\LaravelCrisp\Events\WebhookReceived;
use App\Listeners\HandleCrispWebhook;
protected $listen = [
WebhookReceived::class => [
HandleCrispWebhook::class,
],
];