Installation
composer require dekalee/autopilot-bundle
Add the bundle to config/bundles.php:
return [
// ...
Dekalee\AutopilotBundle\DekaleeAutopilotBundle::class => ['all' => true],
];
Configuration
Add to .env:
DEKALEE_AUTOPILOT_APIKEY=your_api_key_here
Configure in config/packages/dekalee_autopilot.yaml (or config.yml):
dekalee_autopilot:
api_key: '%env(DEKALEE_AUTOPILOT_APIKEY)%'
First Use Case
Inject the AutopilotManager service into a controller or service:
use Autopilot\AutopilotManager;
public function __construct(private AutopilotManager $autopilot) {}
public function triggerAutopilot()
{
$response = $this->autopilot->trigger('event_name', ['key' => 'value']);
return response()->json($response);
}
Event Triggering
Use the AutopilotManager to dispatch events to AutopilotHQ:
$this->autopilot->trigger('user_signup', ['user_id' => 123]);
Event Listening (Webhooks) Configure a route to handle incoming webhook events:
Route::post('/autopilot/webhook', [AutopilotWebhookController::class, 'handle']);
Implement validation and logic in the controller:
public function handle(Request $request)
{
$payload = $request->json()->all();
$this->validate($payload, ['event' => 'required', 'data' => 'required']);
// Process webhook logic (e.g., update user status)
return response()->json(['status' => 'success']);
}
Debugging & Monitoring Leverage the debug toolbar integration to inspect API calls:
Service Integration Wrap Autopilot calls in a dedicated service for reusability:
class AutopilotService {
public function __construct(private AutopilotManager $autopilot) {}
public function sendUserEmail($userId, $template)
{
return $this->autopilot->trigger('send_email', [
'user_id' => $userId,
'template' => $template,
]);
}
}
API Key Security
.env.Route::post('/autopilot/webhook')
->middleware('signed') // Use Laravel's signed requests
->controller([AutopilotWebhookController::class, 'handle']);
Webhook Validation
$this->validate($request, [
'event' => 'required|string',
'data' => 'required|array',
'signature' => 'required|string', // If using signed payloads
]);
Rate Limiting
use Symfony\Component\HttpClient\RetryableHttpClient;
$client = new RetryableHttpClient(
new HttpClient(),
[
'max_retries' => 3,
'delay_ms' => 100,
]
);
Debugbar Dependency
laravel-debugbar. Install it if missing:
composer require barryvdh/laravel-debugbar --dev
Environment-Specific Config
Override the Autopilot config per environment (e.g., config/packages/dekalee_autopilot_testing.yaml):
dekalee_autopilot:
api_key: '%env(DEKALEE_AUTOPILOT_TEST_APIKEY)%'
debug: true # Enable extra logging in testing
Event Naming Convention
Use consistent event names (e.g., user.{action} like user.created, user.paid) for easier tracking in AutopilotHQ.
Testing
Mock the AutopilotManager in tests:
$this->mock(AutopilotManager::class)->shouldReceive('trigger')
->once()
->with('user_signup', ['user_id' => 123])
->andReturn(['success' => true]);
Extension Points
AutopilotManager to log or transform payloads:
$this->autopilot->getClient()->getEmitter()->addSubscriber(
new CustomAutopilotSubscriber()
);
public function subscribe(Container $container, callable $next)
{
$next($container);
$this->subscribeToAutopilotEvents($container);
}
protected function subscribeToAutopilotEvents(Container $container)
{
$container->get('events')->listen(
'autopilot.triggered',
[YourListener::class, 'handle']
);
}
How can I help you explore Laravel packages today?