Am trying to send push notifications to mobile devices using Twilio Notify with PHP, For this first creating a user using following code
require_once 'vendor/autoload.php';
use Twilio\Rest\Client;
$accountSid = "sid";
$authToken = "your_auth_token";
$serviceSid = "serviceSid";
// Initialize the client
$client = new Client($accountSid, $authToken);
// Create a user
$user = $client
->notify->services($serviceSid)
->users->create([
'identity' => 'push token', //am not sure what is identity also?
'segment' => ['segmentName']
]);
// print_r($user);
echo $user->sid;
Getting an exception in
Fatal error: Uncaught exception 'Twilio\Exceptions\TwilioException' with message 'Unknown domain notify' in Twilio/Rest/Client.php
How to solve this? Googled a lot but no luck.
Twilio developer evangelist here.
You are currently using Twilio PHP 5.11.0. Twilio Notify is a beta product right now so is not included in the main library.
You will need to install the alpha version of the library that includes beta and preview products. You can install this with composer with
composer require twilio/sdk:5.11.0-alpha1
As for the identity, that refers to the identity of a User in Notify. To send notifications you need to create bindings, which are addresses for your users to receive notifications on. Then when you create a notification you supply the identity of the user to send the notification to.
i guess you are using 5.x version from your code
so use this code to create a user
$notification = $client
->notify->services($serviceSid)
->notifications->create([
'identity' => '00000001',
'body' => 'Hello Bob'
]);
echo $notification->sid;