Skip to content

About

Notifications SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTIFICATIONS SDK

Latest Version on Packagist Tests Total Downloads

Library for sending messages via services notifications.fromni.com

Installation

You can install the package using composer:

composer require fromni-oy/notifications-sdk

Usage

The sandbox mode is activated with its own token before creating a client:

$sandboxApiKey = '...';
$sandbox = Nexus\Message\Sdk\Client::enableSandbox($sandboxApiKey);

Checking the sandbox activity:

$activated = $sandbox->active();

Disable the sandbox:

Nexus\Message\Sdk\Client::disableSandbox();

Creating a client with an access key:

use Nexus\Message\Sdk\Exceptions\CollectionException;
use Nexus\Message\Sdk\Exceptions\ConnectionException;
use Nexus\Message\Sdk\Exceptions\HttpInvalidArgumentException;
use Nexus\Message\Sdk\Exceptions\LowBalanceException;
use Nexus\Message\Sdk\Exceptions\TokenException;
use Nexus\Message\Sdk\Exceptions\ViolationIntegrityEntityException;

try {
    $apiKey = '...';
    $client = new Nexus\Message\Sdk\Client($apiKey);
    $login = $client->getLogin();
} catch (CollectionException $exception) {
    echo 'CollectionException: ' . $exception->getMessage();
} catch (ConnectionException $exception) {
    echo 'ConnectionException: ' . $exception->getMessage();
} catch (HttpInvalidArgumentException $exception) {
    echo 'HttpInvalidArgumentException: ' . $exception->getMessage();
} catch (TokenException $exception) {
    echo 'TokenException: ' . $exception->getMessage();
} catch (LowBalanceException $exception) {
    echo 'LowBalanceException: ' . $exception->getMessage();
} catch (ViolationIntegrityEntityException $exception) {
    echo 'ViolationIntegrityEntityException: ' . $exception->getMessage();
} catch (\InvalidArgumentException $exception) {
    echo 'InvalidArgumentException: ' . $exception->getMessage();
} catch (\Exception $exception) {
    echo 'Exception: ' . $exception->getMessage();
}

Balance:

$balance = $client->getBalance();

Checking phone numbers:

$collection = $client->checkPhones(['358451086128', '...']);

if ($collection->count() > 0) {
    foreach ($collection as $phone) {
        $checked = $phone->checked();
        $valid = $phone->valid();
        $phoneNumber = $phone->getNumber();
        $country = $phone->getCountry();
        $operator = $phone->getOperator();
        $regionId = $phone->getRegionId();
        $regionName = $phone->getRegionName();
        $timezone = $phone->getTimezone();
    }
}

List of senders names:

$collection = $client->getSenders();

if ($collection->count() > 0) {
    foreach ($collection as $sender) {
        $checked = $sender->checked();
        $senderName = $sender->getSender();
        $channel = $sender->getChannel();
    }
}

Sending messages:

Before sending messages, you need to create metadata for working with statuses:

$reportUrl = 'https://example.com/report'; // Message statuses and sending errors will be sent to this URL.
$replyUrl = 'https://example.com/reply'; // Responses to messages will be sent to this URL if the channel supports this functionality.
$metadata = Nexus\Message\Sdk\ValueObject\MessageMetadata::create($reportUrl, $replyUrl, 600);

Sending confirmation codes to Telegram:

$client->sendTelegram(['358451086128', '...'], 'Message text', $metadata);

Sending via Viber channel:

$client->sendViber(['358451086128', '...'], 'Message text', $metadata);

Sending via SMS channel:

$client->sendSms(['358451086128', '...'], 'Message text', $metadata);

Sending by default channels:

$client->sendSimple(['358451086128', '...'], 'Message text', $metadata);

Omnichannel sending:

$channels = ['telegram', 'viber', 'sms']; // The order of channels to send
$client->sendHybrid(['358451086128', '...'], 'Message text', $channels, $metadata);

Handling statuses, reply and errors:

Handling statuses and errors:

$post = file_get_contents('php://input');
$handler = Nexus\Message\Sdk\Client::statusHandler($post);
$error = $handler->getError();
$messageId = $handler->getEntityId();
$status = $handler->getStatus();
$channel = $handler->getChannel();

Reply processing:

$post = file_get_contents('php://input');
$handler = Nexus\Message\Sdk\Client::replyHandler($post);
$messageId = $handler->getMessageId();
$customId = $handler->getCustomId();
$text = $handler->getText();
$date = $handler->getDate();

Testing

phpunit --coverage-text

History of changes

See CHANGELOG for more information about what has changed recently.

About

Notifications SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages