I am trying to make an outgoing call using Twilio and C#.
I gave the (fromnumber, tonumber, twiliodemourl) as 3 parameters for initiate
outbound call.Then it is working with default twilio demo voice content.
Now i need to customize the voice content attribute and some other attributes
every time i trigger the initiate outbound call method
I have gone through Twilio docs i did not find any good option for customize the
content dynamically from the code using C# every time i send the request.
My client application running periodically to verify for any new messages and then
trigger initiateoutboundcall.
I don't have any custom URL to post any new XML which voice is looking for in 3rd
parameter of initiateOutBoundCall.
So is it required a external domain URL to customize the voice content dynamically from code?
If no please provide the options/sample i have to do it from C# console application.
I tried to use the twimlets.com to echo the custom text to speak in the call.
For text change it is working fine with custom text. But i am not sure whether twimlets.com/echo can be used for production use? Please confirm. Twimlets is not supporting some of the features which i am looking for like Gather input
like IVR message for outbound call.
Using Twilio Voice and C# client:
Voice Request using Twilio C# client?
Dial the number with custom voice content(). If user not responds leave a
voice mail with the custom voice content().
Dial the number with custom voice content (). If user responds, after reading
the message need to provide options like:
press 1 for repeat the same voice message.
press 2 to confirm the action on the message.
press 3 to send SMS for the voice message.
Need to get the response for each voice call / message?
For the sms it send i am getting response as "queued" instead of message sent.
Based on the SMS sent successfully or not i need to update some flag.
So how i can get the SMS reponse as "sent".
SMSMessage sms = twilio.SendSmsMessage(sFromNumber, sToNumber, sMessage);
Console.WriteLine("SMS Status::::::" + sms.Status);
Similarly I need the reponse for voice call once the call is ring id done.
But it is giving "queued".
var call = twilio.InitiateOutboundCall(sFromNumber,sToNumber, url);
Console.WriteLine("Call Status" + call.Status);
So please provide me options for doing it using Twilio.
It would be great if you provide any sample example using C#.
Twilio evangelist here.
You do need some kind of public URL that Twilio can make an HTTP request to once the outbound call is answered. This is how Twilio gets the instructions it needs in order to proceed with the live, in-progress call.
As you noted there are a number of free options for hosting static TwiML content. Twimlets is one. Twimlbin.com is another. Both services are free and great places to at least get started prototyping or setting up a simple MVP of your application, but bear in mind that if you expect a large amount of traffic or you need to build something with your own custom logic in it you'll probably want to move to something else.
That something else could be your own website hosted as as Azure Website (which you can also get for free). Moving to your own website also means that you can scale it as needed and you can start serving up dynamically generated TwiML instead of just being limited to dynamic TwiML as you basically are with Twimlets or Twimlbin.
If you want to process input from <Gather> and none of the Twimlets meet your needs, then you will likely need to look at the Azure option (or some kind of hosted website, doesn't have to be Azure). This will let you build your own custom logic in order to process the callers input and dynamically generate a TwiML response based on that logic.
Twilio provides helper libraries for TwiML generation and for building Twilio apps using ASP.NET MVC, which you can get from NuGet.
Lets say you want to go down the road of building you own custom Twilio app using ASP.NET MVC and hosting it using an Azure Website. In that scenario, using our helper libraries you could build an action method in your controller that returns the TwiML with the <Say> and <Gather> verbs. Something like:
var response = new TwilioResponse();
response.Say("Hello World");
response.BeginGather(new { action="http://example.azurewebsites.com/gather/" } );
response.EndGather();
You would provide the URL that executes that action method as the third parameter in the initiaizeOutboundCall method eg:
client.IntializeOutboundCall(FROM, TO, "http://example.azurewebsites.net");
Once the user enters their input, Twilio will request the URL you specified in the <Gather> verbs action parameter passing you an extra HTTP parameter named Digits, which you can grab in your action method and use in your app logic:
public void Gather(string Digits) {
var response = new TwilioResponse();
response.Say("You pressed " + Digits);
return TwiML(response);
}
To get the status of a phone call or an SMS, you can include use the statuscallback parameter:
SMS: var result = client.SendMessage(FROM, TO, BODY, "http://example.azurewebsites.net/status");
Voice: var result = client.InitiateOutboundCall(FROM, TO, VOICEURL, "http://example.azurewebsites.net/status");
Twilio will make HTTP request to the statusCallback URL's once the final status of the message or call is reached.
Hope that helps.
As of version 5.32 of the C# SDK, you can pass a dynamic twiml string into the CallResource.Update() method like so:
CallResource.Update(
twiml: "<Response><Say>Custom Message Here</Say></Response>"
pathSid: call.Sid);
Or even:
string customMessage = "<Response><Say>Custom Message Here</Say></Response>"
CallResource.Update(
twiml: customMessage,
pathSid: call.Sid);
Related
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.
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.
I am looking at implementing an SMS gateway to send SMS messages to phones from my application.
I was wondering if there are any services that would support sending of messages via AJAX from my views. So ideally, I would have a button on my page that calls the SMS service and passes a json message object to a SMS gateway and retrieves a response.
I'm more than happy building ajax post requests, but I have never used any form of SMS gateway so would appreciate any advice or pointers.
Many thanks
If I understand correctly you would like to use some paid SMS gateway provider like Twilio.
Sending sms via ajax from client application is possible but should not be done in public avaliable websites. Using REST api provided by Twilio you must provide authToken and sid these two will be avaliable for everyone who see your view, so everyone will have possibility to send sms/mms on your cost.
Correct architecture for such solution is to pass custom ajax request to your own server and then in private back end use gateway API library.
This topic was already raised, for example here:
Backbone/JS: looking to access the Twilio SMS API via an AJAX call
Here https://www.twilio.com/docs/libraries you can find libraries for all modern server technologies like .Net, Node.ja, Ruby etc.
And here is a little sample how to send a SMS from C#.
using System;
using Twilio;
class Example
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "AC32a3c49700934481addd5ce1659f04d2";
string AuthToken = "";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage("+14158141829", "+14159352345", "Jenny please?! I love you <3", "");
Console.WriteLine(message.Sid);
}
}
We've been working on browser to phone as per the doc provided by twilio which is in C# razor. We have to same the same for our clients using asp.net4.0.
When a phone number is entered in the textbox the call gets forwarded to the number that is specified in the VoiceURL of the TWIMLAPP rather than forwarding it to the number entered in the textbox.
Below listed are some of the queries that are haunting us;
How do we create dynamic TWIML's to pass the phone number to the Dial Verb?
How to over write the VoiceURL of the TWIML app programmatically?
Are there any examples in asp.net 4.0?
Twilio evangelist here.
Lets take your questions one at a time.
How do we create dynamic TWIML's to pass the phone number to the Dial Verb?
TwiML is just XML, so there are a number of ways to dynamically generate XML in .NET. We do provide a special library (available on NuGet) called Twilio.TwiML that will generate the TwiML for you to return to Twilio. I wrote a blog post a while ago that shows you how to use it.
If you want to generate a <Dial> verb using the TwiML library, you would do something like:
var response = new TwilioResponse();
response.Dial(phoneNumber);
string xml = response.ToString();
How to over write the VoiceURL of the TWIML app programmatically?
The Twilio REST API can be used to modify a TwiML Application. The Twilio .NET helper library makes it easy to do this as well:
var client = new TwilioRestClient("[YOUR_ACCOUNT_SID]","[YOUR_AUTH_TOKEN]");
client.UpdateApplication(applicationSid, friendlyName, applicationOptions);
Hope that helps.
How do you use the Twilio sandbox mode with C#? I have a ashx.cs file that I am using to write my code. Would I put it there? If so, what does that look like?
There is no real great examples on their website on how to do this except for CURL and Ruby.
We are using TwiML to general an XML file tha t parses our data to send back and forth to the Twilio service. We don't want to be charged every time we send a test text message.
How would we set the Sandbox up so we could do some testing.
I found the Test auth Token and account Sid, but how do I use those?
We don't have them in our current application and we are specifying our .ashx page in Twilio to process our code.
Thanks in advance.
Twilio evangelist here.
So if you just want to test that your ASHX handler is generating the right results the easiest way to do this is to just fake a POST or a GET request to that handler. This lets you simulate the GET or POST request that Twilio will make to your app when it gets a text message.
You can see the parameters that Twilio will pass to your app when it receives a text message here:
http://www.twilio.com/docs/api/twiml/sms/twilio_request#synchronous
There are a whole bunch of ways to simulate these requests. cURL is one of them. If your ASHX is expecting query string values, you can also just load the ASHX directly in the browser and append those values in the URL. If the handler is expecting a POST request, I used a chrome plugin called Simple REST Client to make these.
Of course you can also Fiddler to make just about any HTTP request.
The Test Credentials really are more for simulating the use of the REST API (programatically sending SMS messages). I just wrote a blog post that shows how to use the test credentials to create integration tests:
http://www.twilio.com/blog/2013/05/automating-twilio-integration-tests-with-test-credentials.html
Hope that helps.
Devin
I need to send MMS thought a C# application. I have already found 2 interesting components:
http://www.winwap.com
http://www.nowsms.com
Does anyone have experience with other third party components?
Could someone explain what kind of server I need to send those MMS? Is it a classic SMTP Server?
Typically I have always done this using a 3rd party aggregator. The messages are compiled into SMIL, which is the description language for the MMS messages. These are then sent on to the aggregator who will then send them through the MMS gateway of the Network Operator. They are typically charged on a per message basis and the aggregators will buy the messages in a block from the operators.
If you are trying to send an MMS message without getting charged then I am not sure how to do this, or if it is possible.
You could do it yourself. Some MMS companies just have a SOAP API that you can call. All you need to do is construct the XML and send it off via a URL. I have done this once before, but can't remember the name of the company I used.
This post earlier discussed different approaches for SMS and might be helpful for you.
You could use Twilio to accomplish this. You can dive into the docs for specific implementation details but using the C# helper library the code to send an MMS would look like this:
// Send a new outgoing MMS by POSTing to the Messages resource */
client.SendMessage(
"YYY-YYY-YYYY", // From number, must be an SMS-enabled Twilio number
person.Key, // To number, if using Sandbox see note above
// message content
string.Format("Hey {0}, Monkey Party at 6PM. Bring Bananas!", person.Value),
// media url of the image
new string[] {"https://demo.twilio.com/owl.png" }
);
Disclaimer: I work for Twilio.