/** * Initiates an outbound call from the Bandwidth network to the to caller. * @param to */ public static void makeOutboudCall(string to, string from) { ApiCreateCallRequest callRequest = new ApiCreateCallRequest(); callRequest.ApplicationId = applicationId; callRequest.To = to; callRequest.AnswerUrl = host + "/call/me/message"; callRequest.From = from; try { voiceClient.CreateCall(accountId, callRequest); } catch (APIException e) { WriteLine(e.Message); } catch (IOException e) { WriteLine(e.Message); } }
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(); }