fromni-oy / notifications-sdk
NOTIFICATIONS SDK
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/fromni-oy/notifications-sdk
Requires
- php: ^7.4 || ^8.0 || ^8.1
- guzzlehttp/guzzle: ^7.0
- monolog/monolog: ^2.10 || ^3.7
Requires (Dev)
- phpunit/phpunit: 9.6
- spatie/ray: ^1.28
This package is auto-updated.
Last update: 2025-12-19 15:30:50 UTC
README
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.