how to record inbound calls with twilio - twilio

Outbound calls in Twilio can be recorded by setting the TwiML passed to the client.calls.create() API method to have a <Conference> tag with the record attribute set to true. If recordingStatusCallback is set to a URL it'll post a notification to that URL when the recording is available.
How do you do this for inbound calls?
For my specific phone number, for Voice & Fax, I have, on twilio.com, "Accept Incoming" set to "Voice Calls", "Configure With" set to "TwiML App" and "TwiML App" set to my custom app. For that app I have the Voice Request URL set to a given URL.
When a call is incoming an HTTP POST is made to my TwiML App, which responds with an <Enqueue>. Later, a Conference Instruction Reservation is made in the client side javascript with ConferenceRecord set to true and ConferenceRecordingStatusCallback set to the same URL that we used with recordingStatusCallback for the outbound calls.
Here's what my "Conference Instruction Reservation" request payload looks like:
stdClass Object
(
[url] => https://taskrouter.twilio.com/v1/Workspaces/.../Tasks/.../Reservations/...
[method] => POST
[token] => ...
[params] => stdClass Object
(
[Instruction] => conference
[From] =>
[PostWorkActivitySid] =>
[Timeout] => 10
[To] =>
[EndConferenceOnExit] => true
[EndConferenceOnCustomerExit] => true
[ConferenceStatusCallback] => https://my.domain.tld/twilio/conference
[ConferenceStatusCallbackMethod] => POST
[ConferenceStatusCallbackEvent] => start,end,join,leave,mute,hold
[ConferenceRecord] => true
[ConferenceRecordingStatusCallback] => https://my.domain.tld/twilio/conference/recording
[ConferenceRecordingStatusCallbackMethod] => POST
[ConferenceRecordingStatusCallbackEvent] => completed
)
)
As a result of that Twilio calls the ConferenceStatusCallback URL multiple times but the ConferenceRecordingStatusCallback URL is never called.
Any ideas?

So idk why the "Conference Instruction Reservation" request approach wasn't working but calling client.calls.recordings.create() did the trick

Related

Twilio always returns "in-progress" regardless of actual outcome

I'm trying to detect if the number being dialed answers the phone or not, but it always returns the status CallStatus as "in-progress". For example when I get a call from Twilio and I let the phone ring I still see
[CallStatus] => in-progress
This is the code snippet I use to generate the call. As you can see I subscribed to answered, so I'm not even sure why it pings the statusCallback URL, but it does.
$client = new Twilio\Rest\Client($this->account_sid, $this->auth_token);
$call = $client->calls->create(
$to,
$from,
array(
'statusCallback' => 'https://statusCallbackURL',
'statusCallbackEvent' => ['answered'],
'fallbackUrl' => '',
'url' => '',
'timeout' => 60,
)
);

Forward message similar to webhook from a Studio Flow

I have the ability to receive the full incoming message from setting a url in the number section under "A message comes in" to Webhook and entering my url. I would like my messages to be processed in a Studio Flow first. Is there any way from the flow I could then pass it out to a webhook url? I know the webhook sends this info in json, but I'm not sure if I can build all of this data with the html widget. Any idea for how I could do it?
(
[inbound] =>
[ToCountry] => US
[ToState] => OK
[SmsMessageSid] => xxx
[NumMedia] => 0
[ToCity] => NOBLE
[FromZip] => 73003
[SmsSid] => xxx
[FromState] => OK
[SmsStatus] => received
[FromCity] => EDMOND
[Body] => Test
[FromCountry] => US
[To] => +xxx
[ToZip] => 73068
[NumSegments] => 1
[MessageSid] => xxx
[AccountSid] => xxx
[From] => +xxx
[ApiVersion] => 2010-04-01
)
Twilio developer evangelist here.
You could certainly pass it to a Studio Flow first, as you describe, and then use the HTTP request to send all the data onto a webhook URL of your own.
To send all the data onto your own URL, you would need to add all the parameters to the widget too. You'll find all that data in the trigger object within the flow.

StatusCallBack Example

What I want to do is simply call a list of numbers. If a number do not answer, I will need to call an alternative number for that specific number.
So I have put together the code below, which makes the outbound call. But I have no sample of StatusCallback code that will be called for the status of the call being made and in the StatusCallback, it will call another number if the status was un-answered.
$account_sid = 'Some Value';
$auth_token = 'Some Value';
$client = new \Services_Twilio($account_sid, $auth_token);
$client->account->calls->create('+448008021203', '+441604280111', 'xyz.com/play_msg.html', array(
'Method' => 'GET',
"StatusCallback" => "xyz.com/call_events.php",
"StatusCallbackMethod" => "POST",
"StatusCallbackEvent" => array("answered", "completed"),
'Record' => 'false',
));
Can someone please share existing sample to do this?
Twilio evangelist here.
In your call_events.php file you're going to check the CallStatus parameter which is passed by Twilio in its HTTP request as a form-encoded parameter. If the value is not "completed" or "queued" start the next call:
$status = $_REQUEST['CallStatus']
if ($status != "completed" || $status!="queued") {
/* start the next call */
}
Hope that helps.

Twilo Unanswered calls Should trigger a URL

Is it possible that if a call is triggered using API to a Number and the user doesn't attend the call a url should be triggered to tell my application that call was unanswered.
While create a call request to twilio we can pass parameters to it:
status_callback and status_callback_method I am using it in rails
#client.account.calls.create(:from => 'xxxxxxx', :to => "xxxxx", :url =>"url", :method => :get, :status_callback=>"status_call_backurl", :status_callback_method=>:get)

How I can use IPN handler with Pay operation and receive messages?

I have function, which paying users:
def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
user = User.find(params[:user_id])
#params_id = params[:user_id]
credentials = {
'USER' => 'payer_1342623102_biz_api1.gmail.com',
'PWD' => '1342623141',
'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
}
header = {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
"X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T"
}
//here is data what is posting to PayPal
data = {"actionType" => "PAY",
"receiverList.receiver(0).email"=> user.email,
"receiverList.receiver(0).amount" => "10",
"currencyCode" => "USD",
"cancelUrl" => "http://127.0.0.1:3000/",
"returnUrl" => "http://127.0.0.1:3000/",
"requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
end
From documentation:
Adaptive Payments API operation - use -
ipnNotificationUrl field of the Pay or Preapproval request
So, I should add into data variable:
"ipnNotificationUrl" => "myaapp.com"//my site url yes ?
I should put in this field my site url or not ?
How to get info from this notification ?
How to send some emails and do some action if transaction is successful ?
I can't test it locally, yes ?
How can I test it in sandbox ?
Yes, you should include the field if you want to receive notifications related to the payment,
You need to specify a URL that is reachable from the outside (As this is where PayPal will post the information to, from their servers).
This URL could be a PHP page, that upon receiving the IPN, and verifying it, sends out the emails you mentioned.
To simulate an IPN coming from PayPal, you can use the following tool from the sandbox developer page: https://developer.paypal.com/cgi-bin/devscr?cmd=_ipn-link-session
(Alternatively, you can complete a purchase in the sandbox, and if you specified the ipnNotificationURL in the API call, PayPal will send you one upon completion of the payment)

Resources