Eric
Eric

Reputation: 2293

use local xml file for a twilio call

The sample code on how-to-make-a-call looks like this:

static void Main(string[] args)
{
    // Find your Account Sid and Auth Token at twilio.com/console
    const string accountSid = "ACc610c3a41a31c91a01396f7bf92c517d";
    const string authToken = "your_auth_token";
    TwilioClient.Init(accountSid, authToken);

    var to = new PhoneNumber("+14155551212");
    var from = new PhoneNumber("+15017122661");
    var call = CallResource.Create(to,
                                   from,
                                   url: new Uri("http://demo.twilio.com/docs/voice.xml"));

Console.WriteLine(call.Sid);
}

The xml of the referenced voice.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say voice="alice">Thanks for trying our documentation. Enjoy!</Say>
    <Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>

I would like to just create an xml file in memory, and reference that, rather than a remote uri. Is there anyway to take something like the below and attach it to the CallResource.Create argument?

    System.Xml.XmlDocument xmlDocument = new XmlDocument();
    String s = "My custom message!";
    xmlDocument.LoadXml(string.Format(@"<Response><Say voice=""alice"">{0}</Say></Response>", s));

Upvotes: 3

Views: 2106

Answers (3)

Shai
Shai

Reputation: 31

It seems like you actually can send it from you local xml file:

    client.calls
    .create({
        twiml: '<Response><Say>### THIS STRING CAN BE REPLACED WITH YOUR XML FILE CONTENT ###</Say></Response>',
        from: '',
        to: ''
    })
    .then(call => console.log(message.sid));

Upvotes: 1

Dut20819463
Dut20819463

Reputation: 11

Well its funny Before I have asked a similar question and now I'm answering it. Try this: I created an method that takes a string message as parameter which is the message I want to over the call. I call this method before execution of the create call and I put a break, and found that the xml was created in the correct format in the specified directory.<?xml version="1.0" encoding="utf-8"?> <Response>enter code here <Say>HELLO WORLD</Say> </Response> Line 43 I created the method. Then in line 70 I called the method the Xml file was created like below:

enter code here HELLO WORLD

My code

Upvotes: 1

philnash
philnash

Reputation: 73055

Twilio developer evangelist here.

Currently there is no way to send the TwiML for a call with the request to create the call. You do need the TwiML to be hosted somewhere.

If it would be difficult for you to host TwiML, then you could look into TwiML Bins or Twilio Functions for static and dynamic ways of hosting TwiML within Twilio.

Upvotes: 3

Related Questions