erfanhemmati/kavenegar-php
PHP client for the Kavenegar RESTful SMS API. Install via Composer, set your API key, then send SMS to one or multiple recipients using KavenegarApi::Send. Includes basic exception handling and response details (messageid, status, cost).
sendLater via bus:queue) for async processing, reducing latency in high-traffic scenarios..env or AWS Secrets Manager). No built-in encryption, so manual handling is needed.ApiException, HttpException) align with Laravel’s exception handling but lack structured logging or retry logic (e.g., exponential backoff for transient failures).spatie/laravel-queue-retries?cost field in responses) for billing? If so, a custom observer or job is needed.KavenegarApiMock).$this->app->singleton(KavenegarApi::class, fn($app) =>
new KavenegarApi(config('services.kavenegar.api_key'))
);
KavenegarApi::Send() in a job (e.g., SendSmsJob) to decouple from HTTP requests:
class SendSmsJob implements ShouldQueue {
public function handle() {
$api = app(KavenegarApi::class);
$api->Send($this->sender, $this->receptors, $this->message);
}
}
SmsSent) after successful API calls for downstream processing (e.g., analytics)..env (KAVENEGAR_API_KEY).KavenegarApi (e.g., app/Services/SmsService.php).class SmsService {
public function __construct(private KavenegarApi $api) {}
public function sendOtp(string $phone, string $otp): void {
$this->api->Send("10004346", [$phone], "Your OTP: $otp");
}
}
SendSmsJob).sms_logs) for auditing.migrations/create_sms_logs_table.php)..env:
KAVENEGAR_API_KEY=your_api_key_here
KAVENEGAR_SENDER=10004346
composer.json and run composer install.SmsService) to abstract API calls.^09\d{9}$ for Iran).KavenegarApi in unit tests (e.g., using Mockery).composer why-not kavenegar/php to check for updates.catch (\Kavenegar\Exceptions\ApiException $e) {
Log::error("Kavenegar API failed", [
'message' => $e->errorMessage(),
'receptors' => $receptors,
'sender' => $sender,
]);
throw $e;
}
maxAttempts: 100 in SendSmsJob).spatie/laravel-circuitbreaker) to avoid cascading failures.array_chunk($phones, 50); // Process in batches of 50
cost field in responses to avoid unexpected charges. Alert on anomalies (e.g., Laravel Monitor).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| API Key invalid/expired | All SMS fail | Automated key validation on app startup. |
| Kavenegar API downtime | SMS delivery halted | Queue retries + fallback to another provider. |
| Rate limit exceeded | Partial SMS failures | Exponential backoff + batch splitting. |
| Malformed phone numbers | Invalid requests charged | Validate phone numbers before API calls. |
| No internet connectivity |
How can I help you explore Laravel packages today?