quentinrasidy/onesixty

PHP lib to communicate with onesixty API

1.0.0 2019-07-20 12:32 UTC

This package is auto-updated.

Last update: 2025-06-23 03:26:26 UTC


README

This package allows you to communicate with the OneSixty API in order to send SMS to belgian phone numbers.

You will need to create an account on One Sixty. Upon registration, you have 10 free SMS in order to test this package.

Prerequisites

Composer

Installation

composer require quentinrasidy/onesixty

How to use

  1. Create the recipient(s)
  2. Set the content
  3. Authenticate with OneSixty API
  4. Send the SMS

The recipients should be an array of belgian phone numbers.

Sending

$recipients = [];

array_push($recipients,'0492234222');
array_push($recipients,'0492845355');

try{
    //Create the sms
    $s = new Quentinrasidy\Onesixty\Sms;

    //Set the content; the recipients; authenticate and send
    $sms = new Quentinrasidy\Onesixty\Sms;

    $sms->setRecipients($recipients)
    ->setContent('this is a super sms content')
    ->authenticate('mytoken')
    ->send();
    
}catch(Quentinrasidy\Onesixty\SmsException $e){
      //Treat the exception here
}

Reponse

The send() method will return an array of the handled smss with their respective IDs.

If we take the same code as above and store the send() result into a variable :


$results = $sms->setRecipients($recipients)
->setContent('this is a super sms content')
->authenticate('mytoken')
->send();
    
foreach($results as $result){
    var_dump($result);
}

The var_dump method will display the following result :

{
  ["id"]=>
  int(58)
  ["content"]=>
  string(27) "this is a super sms content"
  ["status"]=>
  int(0)
  ["recipient"]=>
  string(12) "+32492234222"
}
array(4) {
  ["id"]=>
  int(59)
  ["content"]=>
  string(27) "this is a super sms content"
  ["status"]=>
  int(0)
  ["recipient"]=>
  string(12) "+32492845355"
}

Therefore, you can store the IDs of the SMS that you have sent. This will allow you to get their status later on, for example.

Also, you can notice that the numbers have been translated to E.169 format.

Callbacks

You can get callbacks for every new SMS states. You need to set a callback URL on the Website under the "developpers" page.

If we keep the example above, two SMSes were created, with ID 58 and 59.

If the SMSes are successfully sent, the API will send an HTTP PUT request to your callback URL with the following data :

[{"id":58,"status":"1"},{"id":59,"status":"1"}]

Status

Those are the possible status for SMSes :

  1. TO_SEND => Your SMS has been stored, we need to send it.
  2. SENT => Your SMS has been sent to the recipient.
  3. HANDLED => Your SMS has been handled by our backend.
  4. ERROR => There was an error with that SMS.
  5. CANCELLED => You have cancelled this SMS via the DELETE method.

Authors

Quentin Rasidy