0
votes

I'm attempting to use CallResource.Update() in C# to provide dynamic twiml instructions to a call in progress. I'd rather use CallResource.Create(), but it only accepts a twiml url.

I've not been able to find any documentation or examples on how to do this, and the only documentation I can find that even hints at this capability is in the API reference for the Call resource Update method here: https://www.twilio.com/docs/voice/api/call#update-a-call-resource

Where it states: TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive

Essentially what I want to accomplish is the appointment reminder tutorial but with outbound voice calls as opposed to sms messages.

I need the call to say "Hello {Name}, This is {Company}. We have you scheduled for a {Typeof} appointment on {date} at {time}, if you need to reschedule, please call {Number}" All of the above data is in our database.

I've tried a mish-mash of syntax trying to hopefully luck into the correct way of doing this, but haven't yet managed to find a solution outside of twimlets.

I'd rather not have to stage a public webserver or setup free hosting to do this even though it wouldn't contain any propretary info or PII, it's beyond the scope of my knowledge and time-frame to develop this solution.

I can do this via SMS all day long with twilio so I'm developing a decent knowledge and appreciation for the API, but we have clients that arent sms friendly and require voice calls so I need a solution for them.

var from = new PhoneNumber("Insert Valid Twilio nyumber");
var call = CallResource.Create(to,from, url:new uri("http://demo.twilio.com/docs/voice.xml"));

CallResource.update(
method: twilio.http.httpmethod.post,
url: new uri("http://twimlets.com/message?Message%5B0%5D=Testing&")
pathSid: call.Sid);

In testing this, I'm expecting the message to play the demo, and then switch to say the word testing (which I would later like to implement dynamic twiml instead of using twimlets).

What is actually happening though is that I get an exception stating that the call is not in progress when it gets to the call update statement.

So two problems, one, how do I update the call to the new twiml url, and then how do I substitute the url for twiml instructions like the API documentation states that I can.

Any help would be greatly appreciated.

1
I was able to get the update working with twimlets, still trying to find any documentation on the twiml instruction parameter for CallResource.Update() though.Acy.Forsythe

1 Answers

0
votes

Twilio developer evangelist here.

That's the first time I've seen the twiml parameter for any REST API resource and given that is the only mention of it, my guess is that we are working on this and have let something slip into the documentation by mistake. For that reason, I would not try to use the twiml parameter right now.

For the error that you're getting when you try to create then update a call:

When you create a call there are more steps than the phone starting to ring. After the call resource is created it is in the "Queued" state. Shortly after, Twilio dispatches the call putting into the "Initiated" state, then when the destination starts to ring it goes into the "Ringing" state. You can check the call lifecycle here. Since your code to update the call runs directly after you receive the response the call is likely in the "Queued" state, thus the error.

If you just need the call to read out a message, then I see no problem with using the Message Twimlet as the initial call URL.

If you need something more dynamic without you having to deal with your own hosting, can I recommend taking a look at Twilio Functions.