Forward message similar to webhook from a Studio Flow - twilio

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.

Related

how to record inbound calls with 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

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 to pass form data to an external API in ROR

Hello I am designing an online application that uses mobile money as a means of payment. But I need assistance on how I can pass my order form data to the API of the mobile money service providers who complete the transaction.
Try httparty, post method.
An existed example could be
options = {:type => auto}
payload = options.to_json
query = {
:request_id => request_id,
......................
:user_id => user
}
response = post("/tbc/submit_job.json", :body => payload, :query => query)
You can use httparty to customize yours.

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)

Create record example for Quickbooks Online and Intuit Anywhere using Ruby and httparty?

Can someone post an example of creating a record in quickbooks online / intuit anywhere, using ruby and httparty?
I am working on an integration to a ruby on rails app using intuit anywhere, and am running into an issue with my POST request when attempting to create a new record. I have been able to successfully retrieve data (customers) using a POST command that doesn't require XML data in the body of the request, but am running into trouble when trying to create new records that have required fields that need to be passed in XML in the body of the request.
I get the same flavor of error in any entity for which I try to create a record for: an invalid or missing required field. It seems to me that the XML in the body (where the data for the required fields is added) is either being ignored (incorrect formatting?) or is not being attached.
I was hoping the someone else familiar with ruby could post an example of a record creation using httparty. If I could see how to correctly pass the XML using httparty, I can fix my problem myself.
I have been using the customer.com example (https://code.intuit.com/integration/viewvc/viewvc.cgi/IntuitAnywhere-Ruby/customer.com/?root=intuitanywhere&system=exsy1003) mostly as posted, with a few irrelevant modifications needed to get it to work in Rails 3.1. I am using the data pull and handling provided in the example, which looks like a pretty standard API wrapper built using httparty.
I am using a pull similar to the one found in the company_controller customers method. Here are two different ways I have tried submitting the XML:
#########################################
#Example 1 - XML
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}",
{ :body =>
"<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\">
<Name>Test Account 2</Name>
<Desc>Test Account</Desc>
<Subtype>Savings</Subtype>
<AcctNum>5001</AcctNum>
<OpeningBalanceDate>2010-05-14</OpeningBalanceDate>
</Account>",
:headers => {
"Content-Type" => "application/xml"
}}
)
#########################################
#Example 2 - hash
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}",
{ :body => {
:Account => {
:Name => "Loan Account 2",
:Desc => "Loac Account 2",
:Subtype => "Savings",
:AcctNum => "5001",
:OpeningBalanceDate => "2011-04-22"
}
},
:headers => {
"Content-Type" => "application/xml"
}}
)
I incorrectly assumed the customer.com example provided by intuit was using the httparty gem to make the POST call, so I was using the wrong syntax. They are actually using the OAuth gem's POST call, who's syntax can be found here: http://oauth.rubyforge.org/rdoc/classes/OAuth/AccessToken.html
I also had to modify the headers to get the Intuit Anywhere service to accept the XML body. Here is the code that finally worked for me to create a record in quickbooks online using intuit anywhere:
e = #company.intuit_token.post("https://qbo.intuit.com/qbo1/resource/account/v2/#{#company.realm}", "<Account xmlns:ns2=\"http://www.intuit.com/sb/cdm/qbo\" xmlns=\"http://www.intuit.com/sb/cdm/v2\"><Name>Test Account </Name><Desc>Test Account</Desc><Subtype>Savings</Subtype><AcctNum>5002</AcctNum><OpeningBalanceDate>2010-05-14</OpeningBalanceDate></Account>", {"Content-Type" => "application/xml", "standalone" => "yes", "encoding" => "UTF-8"})

Resources