Installation
composer require hivelink/php
Add the service provider and facade to config/app.php:
'providers' => [
// ...
HiveLink\HiveLinkServiceProvider::class,
],
'aliases' => [
// ...
'HiveLink' => HiveLink\Facades\HiveLink::class,
],
Configuration Publish the config file:
php artisan vendor:publish --provider="HiveLink\HiveLinkServiceProvider"
Update .env with your API credentials:
HIVE_LINK_API_KEY=your_api_key
HIVE_LINK_API_SECRET=your_api_secret
First Use Case Send a basic SMS:
use HiveLink\Facades\HiveLink;
HiveLink::send([
'to' => '989123456789',
'text' => 'Hello from HiveLink!'
]);
config/hivelink.php (for API settings, retries, logging)HiveLink:: for quick method callsSending SMS Use the facade for simplicity:
HiveLink::send([
'to' => '989123456789',
'text' => 'Your OTP is {code}.',
'variables' => ['code' => '123456']
]);
OTP Management Generate and verify OTPs:
// Generate OTP
$otp = HiveLink::otp()->generate([
'to' => '989123456789',
'length' => 6,
'expire_after' => 300 // 5 minutes
]);
// Verify OTP
$result = HiveLink::otp()->verify($otp['id'], '123456');
Batch Processing Send SMS to multiple recipients:
$recipients = ['989123456789', '989123456780'];
$text = 'Hello!';
HiveLink::batch($recipients, $text);
dispatch(new SendHiveLinkSmsJob($recipient, $message));
config/hivelink.php to debug failed requests.HiveLinkException:
try {
HiveLink::send([...]);
} catch (\HiveLink\Exceptions\HiveLinkException $e) {
Log::error($e->getMessage());
}
$client = new \GuzzleHttp\Client(['timeout' => 10]);
$this->app->bind(\GuzzleHttp\Client::class, fn() => $client);
API Key/Secret Mismatch
.env values match the HiveLink dashboard.HiveLink::config('api_key') to verify.Character Limits
HiveLink::send([
'to' => '989123456789',
'text' => str_repeat('a', 200) // Auto-split
]);
OTP Expiry
expire_after (seconds).Rate Limits
Enable Debug Mode:
HiveLink::setDebug(true); // Logs raw requests/responses
Check Response Codes:
200: Success.400: Invalid parameters (e.g., malformed phone number).401: API key/auth failure.429: Rate limit exceeded.Phone Number Format:
+989123456789).0 or + inconsistencies:
$phone = preg_replace('/[^0-9]/', '', '09123456789'); // => '9123456789'
Custom Responses Override the default response handler:
HiveLink::extend(function ($response) {
return json_decode($response->getBody(), true);
});
Webhook Integration
Use the HiveLink::webhook() method to listen for delivery reports:
HiveLink::webhook()->listen('sms_delivered', function ($data) {
Log::info('SMS delivered to: ' . $data['to']);
});
Testing Mock the client in PHPUnit:
$mock = Mockery::mock(\GuzzleHttp\Client::class);
$this->app->instance(\GuzzleHttp\Client::class, $mock);
How can I help you explore Laravel packages today?