Twilio Browser Call Sends Wrong Call Sid in POST - twilio

I have setup browser calls and in my TwiML App , setup the Status CallBack url . Twilio posts the status in the format
array (
'ApiVersion' => '2010-04-01',
'Called' => NULL,
'CallStatus' => 'completed',
'Duration' => '1',
'From' => 'client:browser',
'CallDuration' => '13',
'Direction' => 'inbound',
'Timestamp' => 'Mon, 16 Apr 2018 19:35:26 +0000',
'AccountSid' => 'asdasdasdadasdasdasdasdasdasdas',
'CallbackSource' => 'call-progress-events',
'ApplicationSid' => 'rwerwerwerwewewewewwrwe',
'Caller' => 'client:browser',
'SequenceNumber' => '0',
'To' => NULL,
'CallSid' => 'CA9c6408108969fsf6f1c53396003d931',
)
I am trying to get the call to ,from and other details. I did was
$callsid = $_POST['CallSid'];
$call = $client->calls($callsid)->fetch();
But it failed everytime. When I checked my dashboard for the CallSod , it is different from what they sent in the webhook.
Is there something I am missing ?

Resolved it. I need to get the Child Call SID to get that information .
$call = $client->calls->read(
array("ParentCallSid" => $callsid )
);

Related

Validate Twilio Notify deliveryCallbackUrl - What is the desired format for a nested request?

I'm working on a project that uses Twilio Notify for mass text notifications. I would like to track the status of individual messages, so I added a deliveryCallbackUrl to the notification resource.
$notification = $service->notifications->create([
"toBinding" => $binding,
"body" => $message_text,
"deliveryCallbackUrl" => "https://username:password#mysite/notification_delivery_callback.php"
]);
I can successfully receive the callback payload, but when I attempt to validate the request, it fails.
use Twilio\Rest\Client;
use Twilio\Security\RequestValidator;
$configs = get_configs();
$signature = $_SERVER["HTTP_X_TWILIO_SIGNATURE"];
$request_url = $_SERVER['SCRIPT_URI'];
$validator = new RequestValidator($configs['twilio_auth_token']);
$request = $_REQUEST;
// $is_valid always returns false
$is_valid = $validator->validate($signature, $request_url, $request);
The payload is nested and includes json.
Array(
[NotificationSid] => NTxxxxxxxxx
[ServiceSid] => ISxxxxxxxxx
[Count] => 4
[IsFinal] => true
[DeliveryState] => Array(
[3] => {"status":"SENT","type":"sms","identity":"xxxxxxxxx","sid":"SMxxxxxxxxx"}
[2] => {"status":"SENT","type":"sms","identity":"xxxxxxxxx","sid":"SMxxxxxxxxx"}
[1] => {"status":"SENT","type":"sms","identity":"xxxxxxxxx","sid":"SMxxxxxxxxx"}
[0] => {"status":"SENT","type":"sms","identity":"xxxxxxxxx","sid":"SMxxxxxxxxx"}
)
[AccountSid] => ACxxxxxxxxx
[SequenceId] => 0
)
It seems the DeliveryState array is the issue, as I am able to successfully validate non-nested requests for other webhooks. I've crawled through Twilio help docs, but so far, haven't found anything about how to validate nested requests. I've attempted to flatten the array and escape the json (one or the other, both at the same time), but no luck.
Array(
...
[DeliveryState] => Array(
[0] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
[1] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
[2] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
[3] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
)
...
)
Array(
...
[0] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
[1] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
[2] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
[3] => "{\"status\":\"SENT\",\"type\":\"sms\",\"identity\":\"xxxxxxxxx\",\"sid\":\"SMxxxxxxxxx\"}"
...
)
Does anyone know what the desired format is to validate this properly?
Worked with Twilio Support to solve the issue.
There was a bug in the sdk: The PHP library didn't support multi-dimensional arrays in the RequestValidator (twilio/sdk has been fixed and updated to 6.42.1)
Format: The validator is looking for a specific format -- need to unnest the DeliveryState array and reformat the keys (order is also important)
Example format that passes validation
(
[NotificationSid] => NTxxx
[ServiceSid] => ISxxx
[Count] => 5
[IsFinal] => true
[DeliveryState[0]] => {"status":"SENT","type":"sms","identity":"xxxxxxxxxx","sid":"SMxxx"}
[DeliveryState[1]] => {"status":"SENT","type":"sms","identity":"xxxxxxxxxx","sid":"SMxxx"}
[DeliveryState[2]] => {"status":"SENT","type":"sms","identity":"xxxxxxxxxx","sid":"SMxxx"}
[DeliveryState[3]] => {"status":"SENT","type":"sms","identity":"xxxxxxxxxx","sid":"SMxxx"}
[DeliveryState[4]] => {"status":"SENT","type":"sms","identity":"xxxxxxxxxx","sid":"SMxxx"}
[AccountSid] => ACxxx
[SequenceId] => 0
)

Unable to know the reason for the response "This tracking number cannot be found. Please check the number or contact the sender"

I am getting a response "This tracking number cannot be found. Please check the number or contact the sender.", which is present in this object.
when I execute a php code to get tracking-id(781193603730) status data got from Fedex. But when I try to check the status of tracking id by loging into their portal I am able to get response. I need help on this, please help. Response object =>
stdClass Object
(
[HighestSeverity] => SUCCESS
[Notifications] => stdClass Object
(
[Severity] => SUCCESS
[Source] => trck
[Code] => 0
[Message] => Request was successfully processed.
[LocalizedMessage] => Request was successfully processed.
)
[TransactionDetail] => stdClass Object
(
[CustomerTransactionId] => *** Track Request using PHP ***
)
[Version] => stdClass Object
(
[ServiceId] => trck
[Major] => 16
[Intermediate] => 0
[Minor] => 0
)
[CompletedTrackDetails] => stdClass Object
(
[HighestSeverity] => SUCCESS
[Notifications] => stdClass Object
(
[Severity] => SUCCESS
[Source] => trck
[Code] => 0
[Message] => Request was successfully processed.
[LocalizedMessage] => Request was successfully processed.
)
[DuplicateWaybill] =>
[MoreData] =>
[TrackDetailsCount] => 0
[TrackDetails] => stdClass Object
(
[Notification] => stdClass Object
(
[Severity] => ERROR
[Source] => trck
[Code] => 9040
[Message] => This tracking number cannot be found. Please check the number or contact the sender.
[LocalizedMessage] => This tracking number cannot be found. Please check the number or contact the sender.
)
[TrackingNumber] => 781193603730
[StatusDetail] => stdClass Object
(
[Location] => stdClass Object
(
[Residential] =>
)
)
[PackageSequenceNumber] => 0
[PackageCount] => 0
[DeliveryAttempts] => 0
[TotalUniqueAddressCountInConsolidation] => 0
[DeliveryOptionEligibilityDetails] => Array
(
[0] => stdClass Object
(
[Option] => INDIRECT_SIGNATURE_RELEASE
[Eligibility] => INELIGIBLE
)
[1] => stdClass Object
(
[Option] => REDIRECT_TO_HOLD_AT_LOCATION
[Eligibility] => INELIGIBLE
)
[2] => stdClass Object
(
[Option] => REROUTE
[Eligibility] => INELIGIBLE
)
[3] => stdClass Object
(
[Option] => RESCHEDULE
[Eligibility] => INELIGIBLE
)
)
)
)
)
I found that the fedex tracking id that I was testing was real, and the credentials that I was using for fedex tracking api were of test/sandbox type not production.

How to send messages using AWS Pinpoint service using PHP SDK

Hi I am trying to send a message using AWS Pinpoint with the PHP SDK, but I am getting an error. Any ideas why? Here is my code:
$client = new PinpointClient([
'version' => 'latest',
'region' => 'us-east-1',
'credentials' => [
'key' => 'MYIAMAWSKEY',
'secret' => 'MYAWSSECRET',
]
]);
$result = $client->sendMessages([
'ApplicationId' => 'MyAppId',
'MessageRequest' => [
'Addresses' => [
'AnIOSDeviceToken' => [
'BodyOverride' => 'aaa',
'ChannelType' => 'APNS',
'RawContent' => 'bbb',
'Context' => ['ccc' => '222'],
'TitleOverride' => 'ddd',
],
],
],
'MessageConfiguration' => [
'APNSMessage' => [
'Action' => 'OPEN_APP',
'Body' => 'Hello',
'RawContent' => 'World',
'SilentPush' => false,
'Title' => 'Hello World!!!',
],
],
]);
I get the following error:
DeliveryStatus: 'PERMANENT_FAILURE'
StatusCode: 400
StatusMessage: Invalid notification: Notification is malformed
According to the API Docs, 'MessageConfiguration' needs to be inside the 'MessageRequest' field. Please make sure your input parameters fully match the documented API Parameter Syntax.

twilio sipendpoint call is failed

I have used following code make a call to twilio sipendpoint. But i'm getting call failed status.
The call flow is like this when agent click on customer number, first i'm connecting to agent to his sip url like this sip:name#sip.twilio.com on request call back i'll connect to customer number using dial verb.
The sip log gives following error
X-Twilio-Error: 400: Bad value for header: X-Twilio-OutboundRouteCount
$client = new Services_Twilio($sid, $token);
$client->account->calls->create(
'name',
'sip:name#sip.twilio.com',
'http://twiliocallback,
array(
'Record' => true,
'Method' => "GET",
'StatusCallback' => 'http://url,
'StatusCallbackMethod' => 'GET',
'StatusCallbackEvent' => array("initiated", "ringing", "answered", "completed"),
'SipAuthPassword' => '****',
'SipAuthUsername' => '****'
));

twitter login not working on my server

When I try to login from server
[http_code] => 401
[url] => https://api.twitter.com/oauth/request_token
[host] => https://api.twitter.com/1.1/
[timeout] => 30
[connecttimeout] => 30
[ssl_verifypeer] =>
[format] => json
[decode_json] => 1
[http_info] => Array
(.....
When I try to login from my Localhost its working fine
[http_code] => 200
[url] => https://api.twitter.com/oauth/request_token
[host] => https://api.twitter.com/1.1/
[timeout] => 30
[connecttimeout] => 30
[ssl_verifypeer] =>
[format] => json
[decode_json] => 1
[http_info] => Array
(.....
Can anyone help me. My twitter_consumer_token and twitter_consumer_secret are correct
I think your server time has not set properly

Resources