Installation
composer require htuzel/addchat-laravel
Publish the config file:
php artisan vendor:publish --provider="Htuzel\Addchat\AddchatServiceProvider" --tag="config"
Configuration
Edit config/addchat.php and set your Turacoon API credentials:
'api_key' => env('ADDCONFIG_API_KEY'),
'widget_id' => env('ADDCONFIG_WIDGET_ID'),
First Use Case Add the widget to your Blade template:
@addchat
Or programmatically in a controller:
use Htuzel\Addchat\Facades\Addchat;
Addchat::render();
Dynamic Widget Rendering Conditionally render the widget based on user roles or other logic:
if (auth()->check() && auth()->user()->isPremium()) {
Addchat::render();
}
Customizing Widget Behavior Use the facade to pass custom settings:
Addchat::render([
'theme' => 'dark',
'position' => 'bottom-right'
]);
Integration with Events Listen to chat events (e.g., new messages) via Turacoon’s webhooks and update your Laravel app accordingly:
Route::post('/turacoon-webhook', function (Request $request) {
// Process webhook data
});
Localization
Override default widget labels by extending the package’s language files in resources/lang.
ADDCONFIG_API_KEY and ADDCONFIG_WIDGET_ID in .env.$data = Cache::remember('turacoon_chat_data', now()->addHours(1), function () {
return Http::get('https://api.turacoon.com/...')->json();
});
Missing Config
Forgetting to publish the config file will result in Undefined config errors. Always run:
php artisan vendor:publish --tag="config"
CORS Issues
If Turacoon’s API or webhooks fail silently, check your Laravel CORS settings in config/cors.php to ensure Turacoon’s domain is whitelisted.
Widget Not Loading
widget_id in the config matches Turacoon’s dashboard.Rate Limiting Turacoon’s API may throttle requests. Implement exponential backoff in your webhook handlers:
use Symfony\Component\HttpClient\Retry\RetryStrategy;
$client = Http::withOptions([
'retry' => RetryStrategy::fromCalls(3, 100)
]);
Log Webhook Payloads Add a middleware to log incoming Turacoon webhook data for debugging:
public function handle(Request $request, Closure $next) {
if ($request->is('turacoon-webhook')) {
\Log::info('Turacoon Webhook', $request->all());
}
return $next($request);
}
Check JavaScript Console If the widget fails to load, inspect the browser console for errors like missing API keys or invalid widget IDs.
Custom Events Extend the package by listening to Turacoon’s webhooks and triggering Laravel events:
event(new ChatMessageReceived($webhookData));
Override Views Publish and modify the widget’s Blade views:
php artisan vendor:publish --tag="views"
API Wrapper Create a service class to wrap Turacoon’s API calls for better maintainability:
class TuracoonService {
public function getChatStatus() {
return Http::get('https://api.turacoon.com/...')->json();
}
}
How can I help you explore Laravel packages today?