for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Messenger\SMSProviders;
use Twilio\Rest\Client;
class TwilioSMS implements SMSProvider
{
/**
* @var Client
*/
var $client;
* @var string
var $sid;
var $number;
* TwilioMessage constructor.
*
* @param $sid
* @param $token
* @param $number
* @throws \Twilio\Exceptions\ConfigurationException
public function __construct($sid, $token, $number)
$this->client = new Client($sid, $token);
$this->sid = $sid;
$this->number = $number;
}
* Sends an sms message.
* @param string $to
* @param string $message
* @return array
public function send(string $to, string $message)
try {
$result = $this
->client
->messages
->create($to, ['from' => $this->number, 'body' => $message]);
$sid = $result->sid;
} catch (\Exception $e) {
return [
'error' => 'Error sending SMS: ' . $e->getMessage(),
'sent' => false,
];
if (empty($sid)) {
'error' => 'Error sending SMS: Unknown error',
'message_id' => $sid,
'sent' => true,
* Checks providers credentials.
* @return bool
public function isValid()
$account = $this->client->api->v2010->accounts($this->sid)->fetch();
if ($account->friendlyName && $account->sid) {
return true;
return false;