Installation
composer require baks-dev/avito-support
Ensure your project meets the PHP 8.4+ requirement and has baks-dev/core (≥7.4) installed.
Service Provider & Facade
Register the package in config/app.php under providers:
BaksDev\AvitoSupport\AvitoSupportServiceProvider::class,
Publish the config (if needed):
php artisan vendor:publish --provider="BaksDev\AvitoSupport\AvitoSupportServiceProvider" --tag="config"
Access via facade:
use BaksDev\AvitoSupport\Facades\AvitoSupport;
First Use Case: Sending a Support Message
AvitoSupport::sendMessage([
'user_id' => 123,
'message' => 'Test message from Laravel',
'priority' => 'high',
]);
config/avito-support.php: Configuration (API endpoints, defaults).src/AvitoSupport.php: Core class methods.src/Facades/AvitoSupport.php: Facade for cleaner syntax.Message Handling
AvitoSupport::sendMessage($data); // $data = ['user_id', 'message', 'priority', ...]
Supports optional fields like attachments, metadata, and callback_url.AvitoSupport::sendBatch([$message1, $message2]);
Webhook Integration
Route::post('/avito/support/webhook', [AvitoSupportController::class, 'handleWebhook']);
AvitoSupport::validateWebhook($request);
Event Listeners
AvitoSupportSent events:
public function handle(AvitoSupportSent $event) {
// Log, notify, or process the sent message
}
Configuration Overrides
config/avito-support.php:
'api_endpoint' => env('AVITO_API_URL', 'https://api.avito.example/support'),
'default_priority' => 'medium',
AvitoSupport::dispatchMessage($data)->onQueue('avito');
AvitoSupport::extend(function ($support) {
$support->macro('customMethod', function () { ... });
});
avito-support test group:
php artisan test --group=avito-support
API Rate Limits
AvitoSupport::getRateLimit() to avoid hitting API thresholds.AvitoSupport::retry($data, 3, 1000); // Retry 3 times with 1s delay
Webhook Validation
if (!AvitoSupport::validateWebhook($request)) {
abort(403, 'Invalid webhook signature');
}
AVITO_WEBHOOK_SECRET in .env.Deprecated Methods
release/v7.4.6.md for breaking changes (e.g., renamed methods like send() → sendMessage()).Core Dependency
baks-dev/core (≥7.4) is installed. Conflicts may arise with older versions.Enable Logging:
AvitoSupport::setLogLevel(\Monolog\Logger::DEBUG);
Logs appear in storage/logs/avito-support.log.
Mock API Calls in Tests:
AvitoSupport::shouldReceive('sendMessage')->andReturn(true);
Custom Transport Override the HTTP client:
AvitoSupport::setHttpClient(new CustomHttpClient());
Message Transformers Extend message formatting:
AvitoSupport::extendMessageTransformer(function ($message) {
$message['custom_field'] = 'value';
return $message;
});
Event Customization
Bind custom listeners to AvitoSupportSent:
event(new AvitoSupportSent($data));
Environment Variables:
Prefix Avito-related configs with AVITO_ (e.g., AVITO_API_KEY).
Example .env:
AVITO_API_URL=https://api.avito.example/support
AVITO_WEBHOOK_SECRET=your_secret_here
Fallback Behavior: Disable API calls entirely for testing:
AvitoSupport::setApiEnabled(false);
How can I help you explore Laravel packages today?