Skip to content

Prihod/alphasms-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alphasms-client

This is client library for the alphasms.ua API.

1. Prerequisites

  • PHP 7.4 or later

2. Installation

The alphasms-client can be installed using Composer by running the following command:

composer require prihod/alphasms-client

3. Initialization

Create Client object using the following code:

<?php

use AlphaSMS\Client;

require_once __DIR__ . '/vendor/autoload.php';

$apiKey = '7d514e5b-81e9-40fb-8a9e-7105ffddd3ed';
$client = new Client($apiKey);

4. API Requests

4.1. Request get balance

use AlphaSMS\Request\BalanceRequest;
use AlphaSMS\Exception\RequestException;

try {
    $request = new BalanceRequest();
    $response = $client->execute($request);
    
    if ($response->isSuccess()) {
        echo "Response to array:\n";
        print_r($response->toArray());
        echo "Response get data:\n";
        print_r($response->getData());
        echo "Response get all entries:\n";
        print_r($response->getEntries());
        echo "Response get first entry:\n";
        $entry = $response->getFirstEntry();
        print_r($entry);

        if ($entry->isSuccess()) {
            echo "Entry to array:\n";
            print_r($entry->toArray());
            echo "Entry get data:\n";
            print_r($entry->getData());
        } else {
            echo "Entry Error: {$entry->getError()}";
        }
    } else {
        echo "Response Error: {$response->getError()}";
    }
} catch (RequestException $e) {
    echo "Exception: {$e->getMessage()}\n";
    print_r($e->request->toArray());
}

4.2. Request to send SMS

use AlphaSMS\Request\SMSRequest;

$request = (new SMSRequest())
    ->setPhone('380971234567')
    ->setSender('SMSTest')
    ->setMessage('Message text to be sent via SMS');

$response = $client->execute($request);
...

4.3. Multiple SMS sending request

use AlphaSMS\Request\SMSRequest;

$requests = [];
$requests[] = (new SMSRequest())
    ->setPhone('380971234567')
    ->setSender('SMSTest')
    ->setMessage('Message text to be sent via SMS 1');

$requests[] = (new SMSRequest())
    ->setPhone('380971234568')
    ->setSender('SMSTest')
    ->setMessage('Message text to be sent via SMS 2');

$requests[] = (new SMSRequest())
    ->setPhone('380971234569')
    ->setSender('SMSTest')
    ->setMessage('Message text to be sent via SMS 3');

$response = $client->execute($requests);
...

4.4. Request to send a message to Viber

4.4.1. Text message

use AlphaSMS\Request\ViberRequest;

$request = (new ViberRequest())
    ->setType(ViberRequest::TYPE_TEXT)
    ->setPhone('380971234567')
    ->setSender("ViberTest")
    ->setMessage("Message text to send via Viber");

$response = $client->execute($request);
...

4.4.2. Image

use AlphaSMS\Request\ViberRequest;

$request = (new ViberRequest())
    ->setType(ViberRequest::TYPE_IMAGE)
    ->setPhone('380971234567')
    ->setSender("ViberTest")
    ->setImage('https://...... /storage/images/json.png');

$response = $client->execute($request);
...

4.4.3. Text with link

use AlphaSMS\Request\ViberRequest;

$request = (new ViberRequest())
    ->setType(ViberRequest::TYPE_TEXT_LINK)
    ->setPhone('380971234567')
    ->setSender("ViberTest")
    ->setMessage("Message text to send via Viber")
    ->setLink('https://alphasms.ua')
    ->setButtonText('Test');

$response = $client->execute($request);
...

4.4.4. Text with link and image

use AlphaSMS\Request\ViberRequest;

$request = (new ViberRequest())
    ->setType(ViberRequest::TYPE_TEXT_IMAGE_LINK)
    ->setPhone('380971234567')
    ->setSender("ViberTest")
    ->setMessage("Message text to send via Viber")
    ->setLink('https://alphasms.ua')
    ->setButtonText('Test')
    ->setImage('"https://...... /storage/images/json.png');

$response = $client->execute($request);
...

4.5. Request to send RCS

use AlphaSMS\Request\RCSRequest;

$request = (new RCSRequest())
    ->setPhone('380971234567')
    ->setSender('RCSTest')
    ->setMessage('Message text to be sent via RCS')
    ->setImage('https://alphasms.ua/storage/images/json.png')
    ->setLink('https://alphasms.ua')
    ->setButtonText('Test');
    
$response = $client->execute($request);
...

4.6. Request voice OTP

use AlphaSMS\Request\VoiceOTPRequest;

$request = (new VoiceOTPRequest())
    ->setPhone('380971234567');

$response = $client->execute($request);
...

4.7. Request HLR

use AlphaSMS\Request\HLRRequest;

$request = (new HLRRequest())
    ->setPhone('380971234567');

$response = $client->execute($request);
...

4.8. Request status message

use AlphaSMS\Request\StatusMessageRequest;

$request = (new StatusMessageRequest())
    ->setMessageId(12332);

$response = $client->execute($request);
...

5. Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages