feridev / avanak
A modern, well-tested, PSR-compliant PHP SDK for Avanak SMS API.
Requires
- php: ^8.1 || ^8.2 || ^8.3
- ext-json: *
- guzzlehttp/guzzle: ^7.9
- psr/log: ^3.0
- vlucas/phpdotenv: ^5.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.6
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2025-06-06 11:04:03 UTC
README
This package provides an interface to connect with the Avanak API and supports features like voice call sending, OTP delivery, text-to-speech (TTS) generation, managing voice messages, and reporting.
๐ฆ Package Structure
Avanak/
โโโ Contracts/
โ โโโ AvanakClientInterface.php # Main interface for interacting with the Avanak API
โ โโโ HttpClientInterface.php # Abstraction layer for the HTTP client (e.g., Guzzle)
โ
โโโ Http/
โ โโโ AvanakClient.php # Implementation of AvanakClientInterface
โ
โโโ Services/
โ โโโ AccountService.php # Fetch account status
โ โโโ AudioService.php # Manage audio files (upload, delete, download, details)
โ โโโ OtpService.php # Send OTP
โ โโโ TtsService.php # Send TTS call, generate TTS, quick send message
โ
โโโ Support/
โ โโโ GuzzleHttpClient.php # Guzzle-based implementation of HttpClientInterface
๐งฐ Installation
If installing locally:
composer require feridev/avanak
Or, add to your composer.json
:
"repositories": [ { "type": "path", "url": "./packages/avanak" } ], "require": { "feridev/avanak": "*" }
โ๏ธ Environment Setup
In your .env
file, add the Avanak API token:
AVANAK_API_TOKEN=your_avanak_token
๐งฑ Usage
1. Define the client:
use Avanak\Support\GuzzleHttpClient; use Avanak\Http\AvanakClient; $httpClient = new GuzzleHttpClient(env('AVANAK_API_TOKEN')); $client = new AvanakClient($httpClient, 'https://api.avanak.ir');
2. Use the services:
Get account status:
use Avanak\Services\AccountService; $service = new AccountService($client); $status = $service->getAccountStatus();
Send OTP:
use Avanak\Services\OtpService; $service = new OtpService($client); $response = $service->sendOtp('your_password', 5, '09123456789');
Generate TTS:
use Avanak\Services\TtsService; $service = new TtsService($client); $response = $service->generateTTS('your_password', 'Sample text', 'Message Title');
Quick send with TTS:
$response = $service->quickSendWithTTS('your_password', 'Sample text', 'Title', '09123456789');
Send voice call using existing message ID:
$response = $service->quickSend('your_password', 1234, '09123456789');
Get quick send details:
$response = $service->getQuickSend('your_password', 4567);
Upload audio file:
use Avanak\Services\AudioService; $audioService = new AudioService($client); $base64Audio = base64_encode(file_get_contents('file.mp3')); $response = $audioService->uploadAudio($base64Audio, 'your_password', 'Message Title', true);
Download audio message:
$response = $audioService->downloadAudioMessage('message_id');
Get message details:
$response = $audioService->getMessageDetails('message_id');
Delete audio message:
$response = $audioService->deleteAudioMessage('message_id');
Get all messages:
$response = $audioService->getMessages();
Get quick send statistics:
$response = $audioService->getQuickSendStatistics('2024-01-01T00:00:00', '2024-12-31T23:59:59');
๐งช Testing
Automated tests have not been added yet. It is recommended to use Postman or curl for manual request validation.
๐ Security
Ensure all sensitive data such as API tokens are stored in the .env
file and never committed to version control.
๐งโ๐ป Contributing
Contributions and pull requests to improve this package are welcome!
๐ License
This package is released under the MIT License.