I am relatively new to Twilio, although it seems like an awesome application!
Basically what I need to accomplish is the following:
I have a .net application that generates an outgoing call and prompts the person for a numeric input - how do I get that input (just numbers of course) back into my .aspx page to deal with it further? For instance, if it said "enter your age" and then I wanted the .aspx page to display their age in a label.
I currently have a button on a page that sends goes to an .ashx file that runs the twiml code, which ends in
context.Response.Write(twiml.ToString());
context.Response.End();`
and the type is "text/xml"
Maybe I am stupid and totally missing the point, but I cannot for the life of me figure out how to accomplish this.
Thank you so much in advance!
Syd
Twilio developer evangelist here.
What you're looking for is the Gather verb. With that you can get the digits entered on a call. So when a call comes in, you could for example return TwiML as such:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather timeout="10" finishOnKey="*">
<Say>Please enter your pin number and then press star.</Say>
</Gather>
</Response>
If you want that information to get to your server, you could use actions as such:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/process_gather.aspx" method="GET">
<Say>
Please enter your age and press star on your keypad.
</Say>
</Gather>
<Say>We didn't receive any input. Goodbye!</Say>
</Response>
Twilio will then make a POST request to your server with those digits and you can do whatever you like with that.
Generating TwiML in .NET MVC for example could be accomplished as follows:
public ActionResult MainMenu()
{
var response = new TwilioResponse();
response.BeginGather(new {
action = "/process_gather.aspx", numDigits = "2" });
response.Say("Please enter your age");
response.EndGather();
response.Hangup();
return TwiML(response);
}
Also, have a look at this blog post to read about call flows in .NET using Twilio.
Hope that helps you
Related
Ok, I've been bugging with this for too long.
I need to call my website from a rough VB.net app. Then only thing I need is to attach a query string parameter to the calling url, so I can distinguish the pages to be shown to different VB app users.
So I want to click a button and launch that website, giving this parameter.
First I was bugging with adding the system.web libraries. Now I can't use Request/Response.QueryString as well.
I tried getting some example help from this post. but as I said before - I cannot make use of Request.QueryString as I cannot import it.
I am stuck here:
Process.Start("http://localhost:56093/WebSite1?id=")
I need to attach a query string parameter to the url and then open the website with that url.
Can someone just give me a sample code for my problem.
Query parameters are parsed by the web server/http handler off the URL you use to call the page. They consist of key and value pairs that come at the end of the URL. Your code is nearly there. Say you needed to pass through the parameters:
ID = 1234
Page = 2
Display = Portrait
Then you'd turn them into a URL like this:
http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait
Therefore in your code you'd have:
Process.Start("http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait");
I have an ASP.NET (.NET v4) web application running on IIS 7.5. I have a 3rd party which wants to pass information to my system. They support passing this information using HTTP POST, the information they provide is:
"This method simply calls a script on your server and passes each
field as a CGI variable. When you have received the data your server
should return a '1' on a line by itself to indicate success. Anything
else will generate an error on our server which will be investigated.
To set up this delivery method we need a URL to post to. We can use
HTTP or HTTPS."
My web application currently implements many WCF services but as I don't know what the variables passed in will be I cannot define a specific contract. Can I create a normal aspx page which they can post to and then read each of the parameters passed and do the appropriate processing.
If I do this how do I send back a line containing '1'?
Do I need to do anything else to make this HTTP POST compatible.
The last time I had to tackle a similar situation, i did it using a standard ASPX page, and it all worked quite well.
In my case the output was XML, so I had to make sure that I changed the output mime type to match "text/xml" in my case.. "text/plain" I would guess in yours..
Anyway, C# sharp code below, and make sure that your ASPX file has ONLY the very top line in, that is:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="myservices.register" ContentType="text/xml" %>
and nothing else, no carriage returns or anything.
Then do all your work in the code behind:
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "text/plain";
//Get your CGI variables here... you will have to get them to tell you what to expect
string myparam = (string)Request.QueryString["myparam"];
//do what ever you need here with your variables
Response.Write("1");
Response.End();
}// End page load handler
If you need to follow the one with a carriage return, then i believe you can use the carriage return property in the system.environment object, but I've not got doc's to hand to look it up. That should however get you started.
The MOST important thing to remember is to make sure NOTHING is output from the aspx, not even a carriage return.
I've previously written an article on my Blog about how to use this method for producing phone directories for Cisco-IP phones if you want to read it. You can find it here: http://shawtyds.wordpress.com/2009/09/26/cisco-ip-phone-directories-using-c/
I read some values from text boxes and send them via jQuerys post method to an server. If the user enters text containing something like "bla bla", the call fails. The data looks like this in that case:
var data = { myKey: 'bla <script> bla' };
And I send it to the server like this:
$.post(targetUrl, data, function(x) {...});
On the server side (an Asp.Net web form) it looks like the call never reaches the server. Any hint how to solve that? If there's a convenient function which cleans data from bad tags, that would be fine too.
Have you desactivate the validate request of your aspx page?
add this in your page declaration: validateRequest="false"
To strip tags using a jQuery function:
jQuery.fn.stripTags = function() {
return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') );
};
Do you receive a page_load in ASP.NET? If yes, isn't there anything in Request.Params?
I would suggest escaping your values client side using the javascript escape function as shown below
var data = { myKey: escape('bla <script> bla') };
Once you have done that, you can retrieve the correct value on the server side using the following (.Net Code)
HttpUtility.UrlDecode(param_value_to_decode)
I tested this and the correct value is being passed correctly to the server via the post request.
Hope this helps.
Additional Info : I forgot to mention the cause of the error. When inspecting the request using firebug, it returns a "500 Internal Server Error - A potentially dangerous Request.Form value was detected from...". This is a built in protection mechanism from asp.net to protect against script injection. The following page directive ValidateRequest="false" did not solve the problem as expected (Works in traditional WebForms). It might be something specific to the Mvc platform, not to sure. The above solution does work, so just use that.
Regards
G
We have a web-service within an existing ASP.NET website which works fine when accessed via other ASP.NET bits. I'd like to get Excel 2007 and 2003 to call the w-s and refresh part of a worksheet with the results using VBA.
Ideally I'd like a vanilla version of Excel to be able to do this (ie without the client having to install extra bits).
As a starter (in 2007) I tried Data->Get External Data->From Web. Pointed it at : http://myhost/myvirtdir/ABCInfoWS.asmx?WSDL&op=testwebservice1
Stuff appears in Excel (albeit with 'The Specified XML source does not refer to a schema' message) but it turns out that it's actually a description of all web-services offered under the same WSDL.
Can anyone tell me how I can get the data from testwebservice via VBA ?
Remove the ?WSDL part from the URL above.
EDIT: What does your webservice return?
Excel's Data -> Import Data expects a tabular structure built with tr & td to get the data in.
If your webservice returns XML, it should work as well.
Sorry it turns out I can't provide enough infromation via comments. This is what is appearing in Excel when I select SOAP 2 and XML:
Just responding to your edits my w-s returns XML and this is what it looks like - it doesn't contain tr/td because it's previously been used as a 'real' webservice .
I've realised that I'm not getting the actual data at all but instead a description of the data that the webservice provides - I guess my URL is still off the beat a bit ?
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetBookJobStatusResponse xmlns="http://www.protecttheguilty.com/">
<GetBookJobStatusResult>
<BookJobStatus>
<JobStatus>string</JobStatus>
<JobType>string</JobType>
<RequestTime>dateTime</RequestTime>
<StartTime>dateTime</StartTime>
<EndTime>dateTime</EndTime>
<PathToOutput>string</PathToOutput>
</BookJobStatus>
<BookJobStatus>
<JobStatus>string</JobStatus>
<JobType>string</JobType>
<RequestTime>dateTime</RequestTime>
<StartTime>dateTime</StartTime>
<EndTime>dateTime</EndTime>
<PathToOutput>string</PathToOutput>
</BookJobStatus>
</GetBookJobStatusResult>
</GetBookJobStatusResponse>
</soap12:Body>
</soap12:Envelope>
I've got a simple ASP.NET webservice. I'm wanting to return a string of json as the result. By default, my webservice is wrapping my json result in some xml.
eg.
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://webservice.streetadvisor.com/">{.... json result in here ... }</string>
Booo.
Is there any way i can make my webservice NOT return some xml, but just write my result as raw output?
Can I define the HTTP-StatusCode in the webservice? eg. 200, 201, 202, 404, 500, etc?
Can i define the response type? eg. application/json
Cheers!
You can do this fairly easily by creating a .ashx handler instead of a normal web service - but at that point you lose a lot of the infrastructure around web services, in particular anything interpreting the data coming from the client in the structured way that SOAP gives you.
Here's an example of creating an RSS feed as a "raw" handler, and here's a more general tutorial. It's not particularly tricky - if those don't help you much, do a search for ashx and you'll get lots of hits.
I don't know how easy it is to do from a web service project though - I've only done it from a straight ASP.NET web application project. It may well "just work" though - it's worth a try.
Sometimes if im wanting to return JSON i just use a .aspx page with:
Response.Clear();
Response.ContentType = "text/javascript";
Then using a .NET Json framework (like the 1 here) i create the json i want it to return.
You can simply use
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
This worked for me.