English 中文(简体)
IVR vs Asp.net MVC: How can I stop reinventing the browser?
原标题:

I m making an IVR system for a project, and have decided on Twilio to handle the phone portion (making and receiving calls, sending and receiving SMS messages). This will surface a website with an IVR front-end, allowing users to navigate the site using their touch-tone phone.

I m not making all the content browse-able over the phone, just what makes sense.

Twilio sends in parameters to your URL on the querystring or via POST, and you respond with a special subset of XML that tells the IVR how to act. I made a lot of headway very quickly with ASP.net MVC, treating the Twilio XML content as a View and rendering the site s data to it.

Here s what a response to Twilio looks like:

<?xml version="1.0" encoding="UTF-8" ?> 
<Response>
<Say>Hello World</Say>
<Play>http://api.twilio.com/Cowbell.mp3</Play>
</Response> 

Here s what a menu looks like to Twilio:

<?xml version="1.0" encoding="UTF-8" ?> 
<Gather action="http://your_url" numdigits="1">
<Say>Press 1 to execute your_url, passing a parameter named "digits"</Say>
</Response> 

Here s where I m stuck:

I m trying to add a universal "back" button, maybe a "skip" button, a "repeat" button, etc, and I m finding that on each view, I m detecting the digit pressed and then if-ing to a hardcoded Response.Redirect(). I know this is going to quickly become unmaintainable for large numbers of views and menus.

So, how can I model the MVC app so that it s more like an application and less like a game of Zork? Stacks of Menu objects, each with Lists of MenuItem objects? How can I make, say "9" the universal option for "back" and have the app respect it, no matter where in the menu system the user is, without having to code for it in each view?

The back feature is just a symptom of the chaos this project will step into if I don t take a moment now to design it properly. Are there .net IVR frameworks out there I can inspect for ideas? Any help would be appreciated, I know this is not a novel problem, I just can t seem to get my head around the best path to take.

最佳回答

Although I almost don t have a clue about what you are talking, since nobody sofar said anything I will have a shot at it (don t shoot me if I m totally not in the direction).

In MVC 2 you can render actions in your views:

<%= Html.Action("home", "menu" , new { someparam = somevalue, someotherparam = someothervalue }) %>

This would call the Menu action in your Home controller with the given parameters. The Result of this Action would then be inserted in your view.
This way you can keep your views clean, and all your Menu stuff in one place. Just have to add the above stated line in every view.

Again the same can be done with HtmlHelper s, yet sometimes the above stated way is just easier.

问题回答

Ricky from Twilio here.

For some reason, having code that s organized like Zork sounds like fun to me but in practice I can understand how that may drive someone crazy!

We just launched a bunch of non-trivial, production ready tutorials to help when developers have questions about how to organize a specific kind of application. One tutorial is an IVR built using C# with ASP.NET MVC.

Taking a look out how we decide to structure things, we re using 3 controllers to control our logic:

  • IVRController.cs: This controller contains the code that welcomes a user when they call into our IVR.
  • MenuController.cs: This controller is where we determine the appropriate IVR menu for the user depending on their inputs.
  • PhoneExchangeController.cs: In this controller, we have the logic to forward a call from our IVR to another phone number.

As you re looking to customize the experience by adding something like "Press 9 to go back", making changes to MenuController.cs should help get you there.





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签