📦 Provides integration with Sinch.com SMS API.
Currently in development process! Things can be changed at any moment!
- PHP 7.1 and later
- Symfony 4.0 and later
Sing up in Sinch.com and create a new app.
composer req fresh/sinch-bundle='dev-master'
Add the following lines to your parameters.yml.dist
file:
parameters:
sinch.key: EnterKeyForYourSinchApp
sinch.secret: EnterSecretForYourSinchApp
During the composer update you have to enter your own key and secret for your Sinch application, which you can find in your Sinch dashboard.
Add the following lines to config.yml
file:
fresh_sinch:
key: "%sinch.key%"
secret: "%sinch.secret%"
use Fresh\SinchBundle\Service\Sinch;
class Foo {
public function bar(Sinch $sinch) {
// Set the outbound number where you want to send the SMS
$messageId = $sinch->sendSMS('+13155555552', 'Your message');
// If success then the ID of sent message is returned (it is an integer value)
echo $messageId;
}
}
use Fresh\SinchBundle\Service\Sinch;
class Foo {
public function bar(Sinch $sinch) {
$messageId = 123456789; // The ID of Sinch message you get after successful SMS sending
// Status is a string with one of these values: pending, successful, faulted, unknown
$status = $sinch->getStatusOfSMS($messageId);
// Other helper methods, return true of false
$sinch->smsIsSentSuccessfully($messageId);
$sinch->smsIsPending($messageId);
$sinch->smsIsFaulted($messageId);
$sinch->smsInUnknownStatus($messageId);
}
}
use Fresh\SinchBundle\Exception\PaymentRequired\SinchPaymentRequiredException;
use Fresh\SinchBundle\Service\Sinch;
class Foo {
public function bar(Sinch $sinch) {
try {
$messageId = $sinch->sendSMS($phoneNumber, 'Your message');
// Some logic related to SMS processing...
} catch (SinchPaymentRequiredException $e) {
$logger->error('SMS was not sent. Looks like your Sinch account run out of money.');
// Here you can, for example, send urgent emails to admin users
// to notify that your Sinch account run out of money
}
}
}
See CONTRIBUTING file.