예제 #1
0
            //create a TwiML response to answer the call
            public static TwilioResponse GetResponseAnswer(TwilioRequestVoice request, Entity.Client client, Entity.Call call)
            {
                TwilioResponse resp = new TwilioResponse();

                if (client == null ||
                    client.ClientState != Entity.Client.ClientStateEnum.Available)
                {
                    if (log.IsDebugEnabled) { log.Debug("GetResponseAnswer.Unavailable.request." + (request == null ? "null" : request.ToJsonString())); }

                    //transfer to unavailable voicemail
                    return GetResponseVoicemail(request, client, call);
                }
                else
                {
                    if (log.IsDebugEnabled) { log.Debug("GetResponseAnswer.request." + (request == null ? "null" : request.ToJsonString())); }

                    resp.Pause(1);

                    if (request.CallRecord)
                        GetResponseRecord(resp, request, client, call);

                    resp.Say("Your call is being answered now.");

                    //find the number to dial
                    string toNumber = request.To;
                    if (string.IsNullOrEmpty(toNumber))
                        toNumber = call.ToNumber;

                    //TODO: pull caller id from database
                    //caller ID is required for outbound calls; it must be registered with your twilio account
                    string callerId = ConfigurationManager.AppSettings["DemoCallerId"];;

                    if (toNumber.StartsWith("client:"))
                    {
                        //call is being routed to a twilio client
                        Twilio.TwiML.Client clientToCall = new Twilio.TwiML.Client(toNumber.Replace("client:",""));
                        resp.Dial(clientToCall, new { callerId = callerId });
                    }
                    else
                    {
                        //call is being routed to an external number
                        Twilio.TwiML.Number number = new Twilio.TwiML.Number(toNumber);
                        resp.Dial(number, new { callerId = callerId });
                    }

                    //log the current call state
                    if (call != null)
                    {
                        call.CallResult = "answered by " + request.To;
                        call.Save();
                    }
                }

                return resp;
            }
예제 #2
0
            //create a TwiML response to transfer the call
            public static TwilioResponse GetResponseTransfer(TwilioRequestVoice request, Entity.Client client, Entity.Call call)
            {
                TwilioResponse resp = new TwilioResponse();

                if (call != null &&
                    !string.IsNullOrEmpty(call.TransferTo))
                {
                    if (log.IsDebugEnabled) { log.Debug("GetResponseTransfer.request." + (request == null ? "null" : request.ToJsonString())); }

                    if (request.CallRecord)
                        GetResponseRecord(resp, request, client, call);

                    resp.Pause(1);
                    resp.Say("You are being transferred now.");

                    //TODO: pull caller id from database
                    //caller ID is required for outbound calls; it must be registered with your twilio account
                    string callerId = ConfigurationManager.AppSettings["DemoCallerId"];

                    Twilio.TwiML.Number number = new Twilio.TwiML.Number(call.TransferTo);
                    resp.Dial(number, new { callerId = callerId });

                    //update call result
                    if (call != null)
                    {
                        call.CallResult = "transfered to " + call.TransferTo;
                        call.Save();
                    }
                }
                else
                {
                    if (log.IsDebugEnabled) { log.Error("GetResponseTransfer.NoTransferNumber.request." + (request == null ? "null" : request.ToJsonString())); }

                    //no transfer number, send to voicemail
                    resp = GetResponseVoicemail(request, client, call);
                }

                return resp;
            }