Installation
Composer
The easiest way to install bulkgate/php-sdk into a project is by using Composer via the command line.
composer require bulkgate/php-sdk
If you have the package installed just plug in the autoloader.
require_once __DIR__ . '/vendor/autoload.php';
use BulkGate\Sdk\Connection\ConnectionStream;
use BulkGate\Sdk\MessageSender;
use BulkGate\Sdk\Scheduler\Simple;
use BulkGate\Sdk\Configurator\ViberConfigurator;
In order to send messages, you need an instance of the BulkGate\Sdk\MessageSender
class that requires instance dependency on the BulkGate\Sdk\Connection\Connection
class. See how to get API access data.
$connection = new ConnectionStream(/*application_id: */ 0000, /*application_token:*/ 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
$sender = new MessageSender($connection);
At this point, you are ready to send a message.
$message = new Sms('420777777777', 'test message');
$sender->send($message);
The send()
method will send a message $message
.
Optional configuration
$sender->setTag('your identificator');
If you want to use national phone numbers you must set default country.
$sender->setDefaultCountry('sk');
You can add configurators to sender.
$viber_configurator = new ViberConfigurator('Sender');
$sender->addSenderConfigurator($viber_configurator);
For scheduling you can add instance of BulkGate\Sdk\Scheduler\Scheduler
.
$scheduler = new Simple(new DateTime('2022-05-14 20:00:00'));
$sender->setScheduler($scheduler);