user2337213
user2337213

Reputation: 27

Pass Data to use in TwiML for Outbound Call

I created a WCF service hosted in Azure. This service is used to in-jest data from a SalesForce workflow. The service will then call a specific file (cshtml was suggested) depending on which team needs to be notified via outbound call from Twilio. I need to pass data from the webservice to the file that is creating/returning the TwiML. I can't figure out a way to do this, guessing cshtml is not the way to go? I am currently using the Twilio NuGet package to place the outbound call. I'm using the demo URL for testing (http://demo.twilio.com/docs/voice.xml). This is working fine. Just now need to pass the SalesForce data to use when creating the TwiML. There is going to be a lot of fields that need to be passed so would like to stay away from appending them to my URL if possible. The code I have so far is below. Any help/suggestions would be appreciated. Thanks!

        var client = new TwilioRestClient(accountSid, authToken);

        client.SendSmsMessage("", "", "Test Twilio SMS from Windows Azure Webservice", r =>
        {
            if (r.RestException != null)
            {
                //an exception occurred making the REST call
                string message = r.RestException.Message;
            }
        });

        CallOptions options = new CallOptions();
        options.To = "";
        options.From = "";
        options.Url = "http://demo.twilio.com/docs/voice.xml";
        options.Timeout = 5;
        options.IfMachine = "Hangup";

        client.InitiateOutboundCall(options);

Upvotes: 0

Views: 1163

Answers (1)

xmjw
xmjw

Reputation: 3434

Twilio Evangelist here, if you want to avoid putting all data in the URL, then you can probably just add an ID as a piece of state data that allows you to find the original SalesForce data. So basically, you need an ID along one of these lines:

https://example.com/calls/1234567890
https://example.com/calls?some_id=1234567890

Then when you application receives this request, it can use this ID to find the data that will allow it to generate the TwiML.

Now there are lots of different things you can do:

  • Use an ID that is associated to Sales Force
  • Create a Key-Value pair that stores your Sales Force data in memory (cache) - although remember to handle having multiple servers or lots of requests.
  • Store the data in a database, and use the ID of the record.
  • Or precompute your TwiML from the Sales Force data, make the call, and store the TwiML against one of the options above.

A second option is to the do the reverse. When you create a Twilio call with the API, you will get an identifier for the call (Call SID). When Twilio makes the request to get the TwiML, it will provide this SID, so you can easily join the API request with the TwiML request. You just need to store that SID in a way that allows you to find the original data, or once again, some pre-generated TwiML.

Hope this helps!

Upvotes: 2

Related Questions