ziming / laravel-crisp
Wrapper Library for Crisp Chat Rest Api
Fund package maintenance!
ziming
Requires
- php: ^8.4
- crispchat/php-crisp-api: ^1.7
- illuminate/contracts: ^10.0||^11.0||^12.0
- php-http/guzzle7-adapter: ^1.1
- spatie/laravel-data: ^4.17
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^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||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.35
README
A laravel Crisp library for Crisp Chat REST API. Still in progress.
Support me
You can donate to my github sponsor.
Installation
You can install the package via composer:
composer require ziming/laravel-crisp
You can publish the config file with:
php artisan vendor:publish --tag="crisp-config"
This is the contents of the published config file:
return [ 'website_id' => env('CRISP_WEBSITE_ID'), 'tier' => env('CRISP_TIER', 'plugin'), 'access_key_id' => env('CRISP_ACCESS_KEY_ID'), 'secret_access_key' => env('CRISP_SECRET_ACCESS_KEY'), ];
Usage
So what are the differences between the Crisp's official PHP SDK and this package?
The 1st main difference is that you don't have to set the tier & api credentials every time after instantiating
You also do not have to pass in the website_id
every time.
I hope through the examples below, you can see how much more convenient this brings for those of us who only have a single Crisp workspace.
// Official PHP Crisp SDK use Crisp\CrispClient; $officialCrisp = new CrispClient(); $officialCrisp->setTier('plugin'); $officialCrisp->authenticate( config('crisp.access_key_id'), config('crisp.secret_access_key') ); $officialCrisp->websitePeople->findByEmail(config('crisp.website_id'), 'abc@example.com'); // This Package $laravelCrisp = new Ziming\LaravelCrisp(); $laravelCrisp->websitePeople->findByEmail('abc@example.com'); // If you prefer the laravel facade approach you can just do this \Ziming\LaravelCrisp\Facades\LaravelCrisp::websitePeople() ->findByEmail('abc@example.com'); // If for some reason you want to use a different website_id, // the official Crisp client is always available too $laravelCrisp->officialClient->websitePeople->findByEmail( config('crisp.website_id'), 'abc@example.com' );
The second main difference is extra methods that I think are useful but are not in Crisp official SDK when I 1st added them.
// Gives you the Crisp Profile Link in Crisp \Ziming\LaravelCrisp\Resources\WebsitePeople::getProfileLink('people-id'); // Gives you the conversation link in Crisp \Ziming\LaravelCrisp\Resources\WebsiteConversations::getConversationLink('session-id'); // Get the first people id that matches the search text if 1 or more results are returned $laravelCrisp = new Ziming\LaravelCrisp(); $laravelCrisp->websitePeople->getFirstPeopleIdBySearchText('abc@example.com'); // Get you the last message of a conversation $laravelCrisp->websiteConversations->getOneLastMessage('session-id'); // Gives you a nice DTO object for a crisp conversation. Which give really nice hints to your IDEs $crispConversation = $laravelCrisp->websiteConversations->getOneCrispConversation('session-id'); // Because it is a DTO object, you can access all the various properties // of the object with IDE hints! $crispConversation->is_verified;
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.