using System;
using System.Collections.Generic;
using Plivo.XML;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace Receivecall.Controllers {
public class MultilevelIvrController: Controller {
// Welcome message, first branch
String WelcomeMessage = "Welcome to the demo. Press 1 for your account balance. Press 2 for your account status. Press 3 to speak to a representative";
// Message for second branch
String RepresentativeBranch = "Press 1 for sales. Press 2 for support";
// Message that Plivo reads when the caller does nothing
String NoInput = "Sorry, I didn't catch that. Please hang up and try again";
// Message that Plivo reads when the caller presses a wrong digit
String WrongInput = "Sorry, that's not a valid input";
// GET: /<controller>/
public IActionResult Index() {
var resp = new Response();
GetInput get_input = new GetInput("", new Dictionary < string, string > () {
{
"action",
"https://<ngrok_identifier>.ngrok.io/multilevelivr/firstbranch/"
},
{
"method",
"POST"
},
{
"digitEndTimeout",
"5"
},
{
"inputType",
"dtmf"
},
{
"redirect",
"true"
},
});
resp.Add(get_input);
get_input.AddSpeak(WelcomeMessage, new Dictionary < string, string > () {});
resp.AddSpeak(NoInput, new Dictionary < string, string > () {});
var output = resp.ToString();
return this.Content(output, "text/xml");
}
public IActionResult FirstBranch() {
String digit = Request.Form["Digits"];
Debug.WriteLine("Digit pressed : {0}" + digit);
var resp = new Response();
if (digit == "1") {
// Add Speak XML element
resp.AddSpeak("Your account balance is $20", new Dictionary < string, string > () {});
}
else if (digit == "2") {
// Add Speak XML element
resp.AddSpeak("Your account status is active", new Dictionary < string, string > () {});
}
else if (digit == "3") {
String getinput_action_url = "https://<ngrok_identifier>.ngrok.io/multilevelivr/secondbranch/";
// Add GetInput XML element
GetInput get_input = new GetInput("", new Dictionary < string, string > () {
{
"action",
getinput_action_url
},
{
"method",
"POST"
},
{
"digitEndTimeout",
"5"
},
{
"inputType",
"dtmf"
},
{
"redirect",
"true"
},
});
resp.Add(get_input);
get_input.AddSpeak(RepresentativeBranch, new Dictionary < string, string > () {});
resp.AddSpeak(NoInput, new Dictionary < string, string > () {});
}
else {
// Add Speak XML element
resp.AddSpeak(WrongInput, new Dictionary < string, string > () {});
}
Debug.WriteLine(resp.ToString());
var output = resp.ToString();
return this.Content(output, "text/xml");
}
// Second branch of IVR phone tree
public IActionResult SecondBranch() {
String FromNumber = Request.Form["From"];
var resp = new Response();
String digit = Request.Form["Digits"];
Debug.WriteLine("Digit pressed : {0}" + digit);
// Add Speak XMLTag
if (digit == "1") {
Dial dial = new Dial(new
Dictionary < string, string > () {
{
"callerId",
FromNumber
},
{
"action",
"https://<ngrok_identifier>.ngrok.io/multilevelivr/action/"
},
{
"method",
"POST"
},
{
"redirect",
"false"
}
});
dial.AddNumber("<number_1>", new Dictionary < string, string > () {});
resp.Add(dial);
}
else if (digit == "2") {
Dial dial = new Dial(new
Dictionary < string, string > () {
{
"callerId",
FromNumber
},
{
"action",
"https://<ngrok_identifier>.ngrok.io/multilevelivr/action/"
},
{
"method",
"POST"
},
{
"redirect",
"false"
}
});
dial.AddNumber("<number_2>", new Dictionary < string, string > () {});
resp.Add(dial);
}
else {
resp.AddSpeak(WrongInput, new Dictionary < string, string > () {});
}
Debug.WriteLine(resp.ToString());
var output = resp.ToString();
return this.Content(output, "text/xml");
}
}
}