3

I have send notification messages using Twilio api. Messages are sending properly.

$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        "toBinding" => [
            '{"binding_type":"sms", "address":"+971444444444"}',
            '{"binding_type":"sms", "address":"+971444444445"}'
        ],
        'body' => 'Test message 8'
    ]);

Response of the request is 201 and returning a sid starting with 'NT'. How to track status of this messages?

Jithin Jose
  • 1,761
  • 2
  • 19
  • 35

3 Answers3

5

Should be like this:

PHP:

$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        "toBinding" => [
            '{"binding_type":"sms", "address":"+971444444444"}',
            '{"binding_type":"sms", "address":"+971444444445"}'
        ],
        'body' => 'Test message 8'
        'sms' => ['status_callback' => 'https://youcallbackurl.com']
    ]);

Or Javascript

const service = twilio.notify.services(notifyId);
const bindings = numbers.map(number => {
        return JSON.stringify({ 
            binding_type: 'sms', 
            address: number,
        });
    });

service.notifications.create({
        toBinding: bindings,
        body: message,
                sms: {
                    status_callback: 'https://youcallbackurl.com'
                }
  })
Maxim Pokrovskii
  • 353
  • 4
  • 11
  • 1
    I don't know why this answer was sitting at -1 votes because this seems to be the correct way to configure your callback URL with the Notify API (in PHP anyway) while the chosen answer does not work. – Gazillion Sep 12 '18 at 14:19
0

twilio has a callback status webhook , you need to configure it inorder to track the delivery status of an sms message

$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        "toBinding" => [
            '{"binding_type":"sms", "address":"+971444444444"}',
            '{"binding_type":"sms", "address":"+971444444445"}'
        ],
        'body' => 'Test message 8'
        'statusCallback' => "your public end point to track sms delivery status"
    ]);

see more here

Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71
0

Step to send Multiple SMS via Twilio using PHP

  1. Create Account on Twilio
  2. Get a Twilio Number
  3. Add Phone numbers here: https://www.twilio.com/console/phone-numbers/verified
  4. Create a notification Service here: https://www.twilio.com/console/notify/services and copy "SERVICE SID" (This will be used in code)
  5. Create a Message Service here: https://www.twilio.com/console/sms/services
  6. Select MESSAGING SERVICE SID under Notify - Configuration's page, what you have created on 5th step:
$sid = 'ACb2f967a907520b85b4eba3e8151d0040'; //twilio service SID
$token = '03e066de1020f3a87cec37bb89f56dea'; //twilio Account SID
$serviceSid = 'IS4220abf29ae4169992b8db5fc2668b10'; //Notify service SID
$client = new Client($sid, $token);
$rs = $client->notify->services($serviceSid)->notifications->create([
    "toBinding" => [
        '{"binding_type":"sms", "address":"+919999999999"}',
        '{"binding_type":"sms", "address":"+919999999999"}'
    ],
    'body' => 'Test message 8',
    'statusCallback' => "your public end point to track sms delivery status"
]);

tshimkus
  • 1,173
  • 2
  • 17
  • 24
Rohit
  • 1