Jithin Jose
Jithin Jose

Reputation: 1821

Get status of SMS send though Twilio notify

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?

Upvotes: 3

Views: 1137

Answers (3)

Rohit
Rohit

Reputation: 1

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"
]);

Upvotes: 0

Maxim Pokrovskii
Maxim Pokrovskii

Reputation: 353

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'
                }
  })

Upvotes: 5

Shachaf.Gortler
Shachaf.Gortler

Reputation: 5735

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

Upvotes: 0

Related Questions