public ActionResult CallInitiatedCallback() { _logger.LogInformation($"{Request.Path.Value} requested."); var unavailableSpeakSentence = new SpeakSentence { Sentence = "You have reached Vandelay Industries, Kal Varnsen is unavailable at this time." }; var messageSpeakSentence = new SpeakSentence { Sentence = "At the tone, please record your message, when you have finished recording, you may hang up." }; var playAudio = new PlayAudio { Url = "/files/tone" }; var record = new Record { RecordingAvailableUrl = "/callbacks/recordingAvailableCallback" }; var response = new Response( unavailableSpeakSentence, messageSpeakSentence, playAudio, record ); return(new OkObjectResult(response.ToBXML())); }
/** * Reply to an incoming call with a sentence and a gather */ public static void letsPlayAGame() { post("/incoming/call", (request, response) => { string json = ControllerHelpers.getBody(request); BandwidthCallbackMessageVoice callbackMessageVoice = APIHelper.JsonDeserialize <BandwidthCallbackMessageVoice>(json); string eventType = callbackMessageVoice.EventType; Response bxmlResponse = new Response(); if ("initiate".Equals(eventType)) { SpeakSentence speakSentence = new SpeakSentence(); speakSentence.Sentence = "lets play a game"; SpeakSentence speakSentence1 = new SpeakSentence(); speakSentence1.Sentence = "What is the sum of 2 plus 3. Enter the sum followed by the pound symbol."; Gather gather = new Gather(); gather.TerminatingDigits = "#"; gather.SpeakSentence = speakSentence1; //If the destination of the gather url is on the same server, a relative URL will work too //gather.GatherUrl = "/incoming/call"; gather.GatherUrl = host + "/incoming/call"; bxmlResponse.Add(speakSentence); bxmlResponse.Add(gather); } else if ("gather".Equals(eventType)) { string digits = callbackMessageVoice.Digits; PlayAudio playAudio; if ("5".Equals(digits)) { //Correct playAudio = new PlayAudio(); playAudio.Url = "https://www23.online-convert.com/dl/web2/download-file/58b6885c-7ecc-4a55-b7ed-8a849e96965e/Smartest%20man%20alive.wav"; } else { //Wrong playAudio = new PlayAudio(); playAudio.Url = "https://www8.online-convert.com/dl/web2/download-file/1eb741cf-9c40-4166-8a63-40cf70c06348/Never%20Gonna%20Give%20You%20Up%20Original.wav"; } bxmlResponse.Add(playAudio); } return(bxmlResponse.ToXml()); }); }
/** * Sends a Gather BXML to the http requester */ public static void callMeMessage() { post("/call/me/message", ((request, response) => { SpeakSentence speakSentence = new SpeakSentence(); speakSentence.Sentence = "Hey you asked to call, who should I call for you. Enter their phone number followed by the pound symbol"; Gather gather = new Gather(); gather.SpeakSentence = speakSentence; //If the destination of the gather url is on the same server, a relative URL will work too //gather.GatherUrl = "/transfer/number"; gather.GatherUrl = host + "/transfer/number"; Response res = new Response(); res.Add(gather); return(res.ToXml()); })); }
public string VoiceCallback() { SpeakSentence speakSentence = new SpeakSentence(); speakSentence.Voice = "kate"; speakSentence.Sentence = "Let's play a game, what is 9 plus 2"; Gather gather = new Gather(); gather.SpeakSentence = speakSentence; gather.MaxDigits = 2; gather.GatherUrl = "gather"; gather.FirstDigitTimeout = 10; Response response = new Response(); response.Add(gather); string bxml = response.ToBXML(); return(bxml); }
public void TestGetSchema() { var instance = new SpeakSentence() as IXmlSerializable; Assert.Null(instance.GetSchema()); }
public void TestReadXml() { var instance = new SpeakSentence() as IXmlSerializable; Assert.Throws <NotImplementedException>(() => instance.ReadXml(null)); }
static void Main(string[] args) { useHttp(true); port("8080"); startServerInstance(); get("/", (body, reponse) => { return("Hello World"); }); post("/Create/Call", (body, reponse) => { ApiCreateCallRequest apiCreateCallRequest = new ApiCreateCallRequest(); apiCreateCallRequest.To = body.To; apiCreateCallRequest.From = body.From; apiCreateCallRequest.AnswerUrl = body.AnswerUrl; apiCreateCallRequest.ApplicationId = voiceApplicationId; try { voiceController.CreateCall(voiceAccountId, apiCreateCallRequest); } catch (APIException ex) { throw new HttpStatusAwareException(ex.ResponseCode, ex.Message); } return("Creates a call"); }); post("/Create/Message", (body, reponse) => { MessageRequest messageReqeust = new MessageRequest(); Newtonsoft.Json.Linq.JArray arr = body.To; messageReqeust.To = arr.ToObject <List <string> >(); messageReqeust.From = body.From; messageReqeust.Text = body.Text; messageReqeust.ApplicationId = msgApplicationId; try { msgController.CreateMessage(msgApiToken, messageReqeust); } catch (APIException ex) { throw new HttpStatusAwareException(ex.ResponseCode, ex.Message); } return(""); }); post("/Callbacks/Messaging", (body, reponse) => { return("Handle message callback"); }); post("/Callbacks/Voice/Outbound", (body, reponse) => { return("Handle outboud voice callback"); }); post("/Callbacks/Voice/Inbound", (body, reponse) => { return("Handle inbound voice callback"); }); post("/Bxml", (body, reponse) => { Response response = new Response(); SpeakSentence speakSentence = new SpeakSentence { Sentence = "Hello World!" }; response.Add(speakSentence); return(response.ToBXML()); }); post("/status", (body, reponse) => { string strBody = body; return(strBody); }); post("/stop", (body, reponse) => { Task.Run(() => { Thread.Sleep(2000); stop(); }); return("Server Shutting Down"); }); WaitOnServerToStop(); }