feridev/avanak

A modern, well-tested, PSR-compliant PHP SDK for Avanak SMS API.

dev-main 2025-05-06 10:46 UTC

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.