示例#1
1
        public TwilioResponse InitialOptions(VoiceRequest request)
        {
            TwilioResponse response = new TwilioResponse();

              var id = request.Digits;

              if (!directory.ExtensionExists(id))
              {
            response.Say("We couldn't find your I D.");
            response.Hangup();
              }

              response.BeginGather(new { finishOnKey = "#", action = string.Format("/Router/PingInital?callingPartyId={0}", id) });
              response.Say("To contact an individual, enter their 4 digit I D and then press the hash button");
              response.Say("To contact a team, enter star followed by the 4 digit I D and then press the hash button");
              response.EndGather();

              return response;
        }
示例#2
0
        public TwilioResponse PingTeamMember(string teamId, string callingPartyId, int idx)
        {
            var response = new TwilioResponse();

              Contact contact = directory.GetTeamMember(teamId, idx);
              Team team = directory.GetTeam(teamId);

              if (contact != null)
              {
            if (idx == 0)
            {
              response.Say(string.Format("Now attempting to connect you to {0}", team.Name));
            }
            else
            {
              response.Say("Trying next team member...");
            }

            response.Say("We are now contacting " + contact.Name + ", please hold the line");
            response.Dial(new Number(contact.MobileNumber, new { url = string.Format("/Router/PreConnect?callingPartyId={0}", callingPartyId) }),
              new { callerId = "+442033229301", timeLimit = 5, action = string.Format("/Router/NextTeamMember?callingPartyId={0}&TeamId={1}&Idx={2}", callingPartyId, teamId, idx) });
              }
              else
              {
            response.Say("Couldn't find a team member...");
            response.Hangup();
              }

              return response;
        }
示例#3
0
        public ActionResult ManageAccount(string CallSid, string Digits)
        {
            var call = GetCall(CallSid);
            TwilioResponse response = new TwilioResponse();
            response.Say("Sorry.  Account management is currently down for repairs.  Please try again in 6 to 8 weeks.");
            response.Hangup();

            return SendTwilioResult(response);
        }
        public ActionResult Hangup()
        {
            var response = new TwilioResponse();
            response.Say(
                "Your recording has been saved. Good bye");
            response.Hangup();

            return TwiML(response);
        }
        public HttpResponseMessage GoodByeMessage(TwilioVoiceRequest twilioVoiceRequest)
        {
            var twilioResponse = new TwilioResponse();

            twilioResponse.Say("Thank you for using VoxVoi. Goodbye!", _voicesettings);
            twilioResponse.Hangup();

            return Request.CreateResponse(HttpStatusCode.OK, twilioResponse.Element);
        }
        public TwilioResponse GetGreeting(VoiceRequest request)
        {
            string culture = LanguageHelper.GetDefaultCulture();
              var response = new TwilioResponse();

              try
              {
            var lookupPhoneNumber = request.GetOriginatingNumber();

            var knownNumber = profileManager.CheckNumber(lookupPhoneNumber);

            if (knownNumber)
            {
              culture = profileManager.GetCulture(lookupPhoneNumber);
              if (string.IsNullOrEmpty(culture))
              {
            culture = LanguageHelper.GetDefaultCulture();
              }
              else
              {
            culture = LanguageHelper.GetValidCulture(culture);
              }

              IVREntryLang.Culture = new System.Globalization.CultureInfo(culture);
              twiMLHelper = new TwiMLHelper(culture, LanguageHelper.IsImplementedAsMP3(culture));
            }
            else
            {
              twiMLHelper = new TwiMLHelper(LanguageHelper.GetDefaultCulture(), false);
            }

            twiMLHelper.SayOrPlay(response, IVREntryLang.Welcome);

            twiMLHelper.SayOrPlay(response, string.Format(IVREntryLang.PhoneLookup, string.Join(" ", lookupPhoneNumber.ToArray())));

            if (!knownNumber)
            {
              twiMLHelper.SayOrPlay(response, IVREntryLang.PhoneNumberNotFound);
              response.Hangup();
              return response;
            }

            response.BeginGather(new { finishOnKey = "#", action = string.Format("/api/IVRAuthenticate?language={0}", culture) });
            twiMLHelper.SayOrPlay(response, IVREntryLang.EnterPin);
            response.EndGather();

              }
              catch (Exception ex)
              {
            twiMLHelper.SayOrPlay(response, string.Format(IVREntryLang.Error, ex.Message));
            twiMLHelper.SayOrPlay(response, string.Format(IVREntryLang.Error, ex.Message));
            twiMLHelper.SayOrPlay(response, string.Format(IVREntryLang.Error, ex.Message));
            response.Hangup();
              }
              return response;
        }
示例#7
0
        public HttpResponseMessage Post(VoiceRequest request, string pin)
        {
            var user = AuthenticationService.GetUser(pin);

            var response = new TwilioResponse();
            response.Say(string.Format("Hello {0}", user.Name));
            response.Pause(2);
            response.Hangup();

            return this.TwiMLResponse(response);
        }
示例#8
0
        public ActionResult CallComplete(string CallSid)
        {
            LocationalCall call = (LocationalCall)GetCall(CallSid);
            StateManager.CompletedCall(call);
            StateManager.AddToLog(CallSid, "Call is completed.");

            TwilioResponse response = new TwilioResponse();
            response.Say("Goodbye baby cakes");
            response.Hangup();

            return SendTwilioResult(response);
        }
示例#9
0
  public TwiMLResult Index(VoiceRequest request)
  {
    var response = new TwilioResponse();
    
    // Use <Say> to give the caller some instructions
    response.Say("Hello. Please leave a message and I will transcribe it.");

    // Use <Record> to record and transcribe the caller's message
    response.Record(new { transcribe = true, maxLength = 30 });

    // End the call with <Hangup>
    response.Hangup();

    return TwiML(response);
  }
示例#10
0
  public TwiMLResult Index(VoiceRequest request)
  {
    var response = new TwilioResponse();
    
    // Use <Say> to give the caller some instructions
    response.Say("Hello. Please leave a message after the beep.");

    // Use <Record> to record the caller's message
    response.Record();

    // End the call with <Hangup>
    response.Hangup();

    return TwiML(response);
  }
        private TwiMLResult ReturnInstructions()
        {
            var response = new TwilioResponse();
            response.Say("To get to your extraction point, get on your bike and go down " +
                         "the street. Then Left down an alley. Avoid the police cars. Turn left " +
                         "into an unfinished housing development. Fly over the roadblock. Go " +
                         "passed the moon. Soon after you will see your mother ship.",
                         new {voice = "alice", language = "en-GB"});

            response.Say("Thank you for calling the ET Phone Home Service - the " +
                         "adventurous alien's first choice in intergalactic travel");

            response.Hangup();

            return TwiML(response);
        }
示例#12
0
        public HttpResponseMessage Post(VoiceRequest request, string userId)
        {
            var response = new TwilioResponse();

            var usernames = new Dictionary<string, string>
                                {
                                    { "12345", "Tom" }, 
                                    { "23456", "Dick" }, 
                                    { "34567", "Harry" }
                                };

            var username = usernames[userId];

            response.Say(string.Format("Hello {0}", username));
            response.Pause(5);
            response.Hangup();

            return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
        }
        public HttpResponseMessage Post(VoiceRequest request)
        {
            var response = new TwilioResponse();

            var validIds = new List<string> { "12345", "23456", "34567" };
            var userId = request.Digits;
            var authenticated = validIds.Contains(userId);

            if (!authenticated)
            {
                response.Say("You entered an invalid ID. Goodbye.");
                response.Hangup();
            }
            else
            {
                response.Say("ID is valid.");
                response.Redirect(string.Format("/api/Name?userId={0}", userId));
            }

            return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
        }
        public TwilioResponse GetAuthentication(VoiceRequest request, string language)
        {
            var response = new TwilioResponse();

              if (string.IsNullOrEmpty(language))
              {
            language = LanguageHelper.GetDefaultCulture();
              }
              else
              {
            language = LanguageHelper.GetValidCulture(language);
              }

              IVRAuthLang.Culture = new System.Globalization.CultureInfo(language);
              twiMLHelper = new TwiMLHelper(language, LanguageHelper.IsImplementedAsMP3(language));

              string lookupPhoneNumber = request.GetOriginatingNumber();

              var pin = request.Digits;

              var result = profileManager.CheckPin(lookupPhoneNumber, pin);

              string correctPin = profileManager.GetPin(lookupPhoneNumber);

              if (result)
              {
            response.Redirect(routeProvider.GetUrlMethod(IVRRoutes.PLAY_MAIN_MENU, language), "POST");
              }
              else
              {
            twiMLHelper.SayOrPlay(response, IVRAuthLang.IncorrectPIN);

            response.Hangup();
              }

              return response;
        }
        public TwiMLResult CallBackAfterConference(CallContextModel model)
        {
            var callSid = Request["CallSid"];
            var response = new TwilioResponse();
            try
            {
                if (model.IsCustomer)
                {
                    model.ReceiverSid = callSid;
                }
                else
                {
                    model.CallerSid = callSid;
                }

                response.Say(ConferenceConst.ThankForConsultantAndFollowupAction,
                            new { voice = VoiceInConference, language = LanguageInConference });
                response.Redirect(Url.Action("ConsultantAfterCall", model));

                return new TwiMLResult(response);
            }
            catch (Exception e)
            {
                Log.Error("Call back after conference. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult ConsultantAfterCall(CallContextModel model)
        {
            var response = new TwilioResponse();
            try
            {
                response.BeginGather(new { numDigits = 1, action = Url.Action("ConsultantAfterCallResponse", model) });

                // Check call duration
                var call = Services.Call.GetByCallSid(Request["CallSid"]);
                int startingTime = Convert.ToInt32(Services.SystemConfig.GetByKey(ParamatricBusinessRules.STARTING_TIME.ToString()).Value);

                if (call.Duration <= startingTime)
                {
                    response.Say(ConferenceConst.ConsultantAfterCallNoInvoice, new { voice = VoiceInConference, language = LanguageInConference });
                }
                else
                {
                    response.Say(ConferenceConst.ConsultantAfterCall, new { voice = VoiceInConference, language = LanguageInConference });
                }

                response.EndGather();
                response.Redirect(Url.Action("ConsultantAfterCall", model));
            }
            catch (Exception e)
            {
                // Log
                Log.Error("Consultant after call. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult ClientDenied(CallContextModel model)
        {
            var response = new TwilioResponse();
            try
            {
                // Update call status
                model.ReceiverStatus = Request["CallStatus"];
                Services.Call.UpdateCallStatus(model.CallId, model.ReceiverStatus, false);

                if (model.IsCustomer) // Customer initiate call >> Consultant called first
                {
                    response.Say(ConferenceConst.CustomerDenied, new { voice = VoiceInConference, language = LanguageInConference });
                }
                else // Consultant initiate call >>  Customer called first
                {
                    response.Say(ConferenceConst.ConsultantDenied, new { voice = VoiceInConference, language = LanguageInConference });
                }
            }
            catch (Exception e)
            {
                Log.Error("First client denied. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
            }

            // Hangup
            response.Hangup();
            return new TwiMLResult(response);
        }
        public TwiMLResult SecondClientResponse(CallContextModel model, string digits)
        {
            var response = new TwilioResponse();

            try
            {
                model.CallerStatus = Request["CallStatus"];

                switch (digits)
                {
                    case "1":

                        // Update database second client is ready now and update status
                        Services.Call.ReceiverReadyNow(model.CallId);
                        Services.Call.UpdateCallStatus(model.CallId, model.CallerStatus, true);

                        response.Redirect(Url.Action("SecondClientReady", model));
                        break;

                    default:
                        response.Pause(10);

                        response.Redirect(Url.Action("SecondClientStart", model));
                        break;
                }
            }
            catch (Exception e)
            {
                Log.Error("First client response. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult ConsultantAfterCallResponse(CallContextModel model, string digits)
        {
            var response = new TwilioResponse();
            var message = ConferenceConst.AcctionCompleted;
            var specialist = new UserDto();
            var call = new CallDto();

            bool canWaiveFee = true;
            int transcriptSuccess = 2;

            try
            {
                if (digits.Equals("2") || digits.Equals("3") || digits.Equals("4") || digits.Equals("5"))
                {
                    call = Services.Call.GetByCallSid(Request["CallSid"]);

                    if (string.IsNullOrWhiteSpace(model.RecordUrl))
                    {
                        model.RecordSid = call.RecordSid;
                        model.RecordDuration = call.RecordDuration;
                        model.RecordUrl = call.RecordUrl;
                    }

                    // Get specialist
                    if (model.IsCustomer) // Caller is customer
                    {
                        specialist = Services.Users.GetUserById(model.ReceiverId);
                    }
                    else
                    {
                        specialist = Services.Users.GetUserById(model.CallerId);
                    }

                    int startingTime = Convert.ToInt32(Services.SystemConfig.GetByKey(ParamatricBusinessRules.STARTING_TIME.ToString()).Value);
                    if (call.Duration <= startingTime)
                    {
                        canWaiveFee = false;
                    }
                }

                switch (digits)
                {
                    case "1": // Dictate your follow up action
                        var statusCallBack = Utilities.FormatLink(Url.Action("VoiceMail", "Conference", model));
                        Services.Call.RedirectToVoiceMail(Request["CallSid"], statusCallBack);

                        break;

                    case "2": // Transcript consultation
                        // Send transcription request
                        transcriptSuccess = SendTranscriptionRequest(specialist.Id.ToString(), specialist.UserName,
                                                                        specialist.Email, call.RecordUrl,
                                                                        call.RecordDuration, call.Booking);

                        if (transcriptSuccess == 0)
                        {
                            message = ConferenceConst.BalanceNotEnoughForTranscript;
                        }
                        else if (transcriptSuccess == 1)
                        {
                            message = ConferenceConst.TranscriptError;
                        }

                        break;

                    case "3": // Play consultation record
                        response.Pause(5);
                        response.Play(model.RecordUrl);

                        break;

                    case "4": //  Play consultation record and transcription
                        // Play consultation record
                        response.Pause(5);
                        response.Play(model.RecordUrl);

                        // Send transcription request
                        transcriptSuccess = SendTranscriptionRequest(specialist.Id.ToString(), specialist.UserName,
                                                                        specialist.Email, call.RecordUrl,
                                                                        call.RecordDuration, call.Booking);

                        if (transcriptSuccess == 0)
                        {
                            message = ConferenceConst.BalanceNotEnoughForTranscript;
                        }
                        else if (transcriptSuccess == 1)
                        {
                            message = ConferenceConst.TranscriptError;
                        }

                        break;

                    case "5": // Waive consultation fee
                        if (canWaiveFee)
                        {
                            response.Redirect(Url.Action("WaiveFeeAction", model));
                        }
                        else
                        {
                            response.Redirect(Url.Action("ConsultantAfterCall", model));
                        }

                        break;

                    default:
                        response.Redirect(Url.Action("ConsultantAfterCall", model));
                        return new TwiMLResult(response);
                }
            }
            catch (Exception e)
            {
                // Log
                Log.Error("Consultant after call response. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            response.Say(message, new { voice = VoiceInConference, language = LanguageInConference });
            response.Redirect(Url.Action("ConsultantAfterCall", model));
            return new TwiMLResult(response);
        }
        public TwiMLResult CallHangUpForDeferOrReSchedule(CallContextModel model)
        {
            var response = new TwilioResponse();
            try
            {
                Services.Call.UpdateCallStatus(Request["CallSid"], CallStatus.Completed);
                Services.Call.UpdateConferenceTime(model.CallId, false);

                response.Hangup();
            }
            catch (Exception e)
            {
                // Log
                Log.Error("Call hang up for defer or reschedule. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
示例#21
0
        public TwilioResponse RespondToPreConnect(VoiceRequest request)
        {
            var response = new TwilioResponse();

              if (request.Digits == "1")
              {
            response.Say("You are now being connected.");
              }
              else
              {
            response.Hangup();
              }

              return response;
        }
        public TwiMLResult FirstClientConference(CallContextModel model)
        {
            var response = new TwilioResponse();

            try
            {
                // Get fromUser and toUser
                var caller = Services.Users.GetUserById(model.CallerId);
                var receiver = Services.Users.GetUserById(model.ReceiverId);
                var callBackUrl = Utilities.FormatLink(Url.Action("CallBackAfterConference", "Conference", model));

                if (model.IsCustomer) // Customer initiate call >> Consultant called first
                {
                    // Get name conference room
                    var room = string.Format(ConferenceRoom, caller.UserName, receiver.UserName, model.BookingId);

                    // Check customer is readly in conference
                    if (Services.Call.CheckCallInStatus(model.CallId, CallStatus.InProgress, false))
                    {
                        response.Say(ConferenceConst.CustomerReadyTakeCall, new { voice = VoiceInConference, language = LanguageInConference });

                        // Update start time conference
                        Services.Call.UpdateConferenceTime(model.CallId, true);

                        // Begin call duration show popup to user
                        CallHelper.CallDuration(Request["CallSid"], model.IsCustomer, Services, true);

                        // Start conference timer
                        CallHelper.StartConferenceTimer(model.CallerId, model.CallId, model.BookingId, room);

                        // Dial conference
                        response.DialConference(room,
                            new
                            {
                                endConferenceOnExit = true,
                                waitUrl = "http://twimlets.com/holdmusic?Bucket=com.twilio.music.electronica"
                            },
                            new
                            {
                                record = false,
                                transcribe = false,
                                action = callBackUrl
                            });
                    }
                    else
                    {
                        response.Say(ConferenceConst.CustomerDenied, new { voice = VoiceInConference, language = LanguageInConference });
                    }
                }
                else // Consultant initiate call >>  Customer called first
                {
                    response.Say(ConferenceConst.ConsultantReadyTakeCall, new { voice = VoiceInConference, language = LanguageInConference });
                    // Get name conference room
                    var room = string.Format(ConferenceRoom, caller.UserName, receiver.UserName, model.BookingId);

                    // Update start time conference
                    Services.Call.UpdateConferenceTime(model.CallId, true);

                    // Begin call duration show popup to user
                    CallHelper.CallDuration(Request["CallSid"], model.IsCustomer, Services, true);

                    // Begin conference timer
                    CallHelper.StartConferenceTimer(model.ReceiverId, model.CallId, model.BookingId, room);

                    // Dial conference
                    var callHangUpUrl = Utilities.FormatLink(Url.Action("CallHangUp", "Conference", model));
                    response.DialConference(room,
                        new
                        {
                            endConferenceOnExit = true
                        },
                        new
                        {
                            record = true,
                            trim = "trim-silence",
                            transcribe = false,
                            action = callHangUpUrl
                        });
                }
            }
            catch (Exception e)
            {
                Log.Error("First client join conference. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult FirstClientHold(CallContextModel model)
        {
            var response = new TwilioResponse();
            try
            {
                bool pickedUp = Services.Call.ReceiverPickedUp(model.CallId);
                bool ready = Services.Call.ReceiverReady(model.CallId);

                // Update call status
                model.ReceiverStatus = Request["CallStatus"];
                Services.Call.UpdateCallStatus(model.CallId, model.ReceiverStatus, false);

                if (pickedUp && ready)
                {
                    // Join conference room
                    response.Redirect(Url.Action("FirstClientConference", model));
                }
                else
                {
                    response.Pause(20);

                    if (model.IsCustomer) //do Customer initiate call >> Consultant called first
                    {
                        response.Say(ConferenceConst.WaitForCustomer, new { voice = VoiceInConference, language = LanguageInConference });
                    }
                    else // Consultant initiate call >>  Customer called first
                    {
                        response.Say(ConferenceConst.WaitForConsultant, new { voice = VoiceInConference, language = LanguageInConference });
                    }

                    response.Redirect(Url.Action("FirstClientHold", model));
                }

                return new TwiMLResult(response);
            }
            catch (Exception e)
            {
                Log.Error("First client hold. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult FirstClientReady(CallContextModel model)
        {
            var response = new TwilioResponse();
            var message = string.Empty;

            try
            {
                // Make call to second client
                // If customer initiate call >> Customer will be call
                // If consultant initiate call >> Consultant will be call
                var customer = Services.Users.GetUserById(model.CallerId);
                var specialist = Services.Users.GetUserById(model.ReceiverId);

                try
                {
                    if (model.IsCustomer)
                    {
                        string fullPhoneNumber = customer.MobileCountryCode + customer.MobilePhone;

                        // Make call to customer
                        var call = Services.Call.Dial(Url.Action("SecondClientStart", model), fullPhoneNumber);

                        // Update callSid
                        Services.Call.UpdateCallSid(model.CallId, call.Sid, true);
                    }
                    else
                    {
                        customer = Services.Users.GetUserById(model.ReceiverId);
                        specialist = Services.Users.GetUserById(model.CallerId);

                        string fullPhoneNumber = specialist.MobileCountryCode + specialist.MobilePhone;

                        // Make call to consultant
                        var call = Services.Call.Dial(Url.Action("SecondClientStart", model), fullPhoneNumber);

                        // Update callSid
                        Services.Call.UpdateCallSid(model.CallId, call.Sid, true);
                    }
                }
                catch (Exception e)
                {
                    // Log
                    Log.Error("FirstClientReady_Call to second client failed. Error: ", e);
                }

                // Update call status
                model.ReceiverStatus = Request["CallStatus"];
                Services.Call.UpdateCallStatus(model.CallId, model.ReceiverStatus, false);

                if (model.IsCustomer) // Customer initiate call >> Consultant called first
                {
                    string template = ConferenceConst.AcceptCallNowForTalkNow;
                    message = string.Format(template, customer.Name);
                }
                else // Consultant initiate call >> Customer called first
                {
                    string template = ConferenceConst.AcceptCallNowForSchedule;
                    message = string.Format(template, specialist.Title, specialist.Name);
                }

                response.Say(message, new { voice = VoiceInConference, language = LanguageInConference });
                response.Redirect(Url.Action("FirstClientHold", model));
            }
            catch (Exception e)
            {
                Log.Error("First client ready. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
示例#25
0
        private TwilioResponse PingPerson(VoiceRequest request, string callingPartyId)
        {
            TwilioResponse response = new TwilioResponse();

              var person = directory.GetContact(request.Digits);

              if (person != null)
              {
            if (person.AcceptCalls)
            {
              response.Say("We are now contacting " + person.Name + ", please hold the line");
              response.Dial(new Number(person.MobileNumber, new { url = string.Format("/Router/PreConnect?callingPartyId={0}", callingPartyId) }), new { callerId = "+442033229301" });
            }
            else
            {
              var divertedTo = directory.GetContact(person.DivertToId);

              if (divertedTo != null)
              {
            response.Say(person.Name + " is not currently accepting calls. Diverting you to " + divertedTo.Name);
            response.Dial(new Number(divertedTo.MobileNumber, new { url = string.Format("/Router/PreConnect?callingPartyId={0}", callingPartyId) }), new { callerId = "+442033229301" });
              }
              else
              {
            response.Say("Unable to find someone to divert to...");
            response.Hangup();
              }
            }
              }
              else
              {
            response.Say("Person not found");
              }

              return response;
        }
        public TwiMLResult FirstClientStart(CallContextModel model)
        {
            var response = new TwilioResponse();

            try
            {
                var call = Services.Call.GetByCallSid(Request["CallSid"]);

                // Get info for call context
                model.CallId = call.Id;
                model.ReceiverSid = Request["CallSid"];
                model.ReceiverStatus = Request["CallStatus"];

                // Get first client and second client
                var fromUser = Services.Users.GetUserById(model.CallerId);
                var toUser = Services.Users.GetUserById(model.ReceiverId);

                // Update call status
                Services.Call.UpdateCallStatus(model.CallId, model.ReceiverStatus, false);

                var greeting = string.Empty;

                if (model.IsCustomer) // Customer initiate call >> Consultant called first
                {
                    string template = ConferenceConst.CallMenuForTalkNow;
                    greeting = string.Format(template, fromUser.Name, model.NatureOfEnquiry);
                }
                else // Consultant initiate call >> Customer called first
                {
                    string template = ConferenceConst.CallMenuForSchedule;
                    greeting = string.Format(template, toUser.Name, fromUser.Name, model.NatureOfEnquiry);
                }

                response.BeginGather(new { numDigits = 1, action = Url.Action("FirstClientResponse", model) });
                response.Pause(2);
                response.Say(greeting, new { voice = VoiceInConference, language = LanguageInConference });
                response.EndGather();
                response.Redirect(Url.Action("FirstClientStart", model));
            }
            catch (Exception e)
            {
                // Save Log
                Log.Error("First client start. Error:", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
示例#27
0
        public TwilioResponse PreConnect(VoiceRequest request, string callingPartyId)
        {
            var response = new TwilioResponse();

              var callingParty = directory.GetContact(callingPartyId);

              response.BeginGather(new { numDigits = 1, action = "/Router/RespondToPreConnect" });
              response.Say(string.Format("You have an incoming call from {0}", callingParty.Name));
              response.Say("Press 1 to be connected");
              response.Say("Press 2 to hangup");
              response.EndGather();
              response.Hangup();

              return response;
        }
        public TwiMLResult SecondClientReady(CallContextModel model)
        {
            var response = new TwilioResponse();

            try
            {
                model.CallerStatus = Request["CallStatus"];

                var message = string.Empty;

                // Get fromUser and toUser
                var fromUser = Services.Users.GetUserById(model.CallerId);
                var toUser = Services.Users.GetUserById(model.ReceiverId);

                if (model.IsCustomer) // Customer initiate call >> Second client and FromUser is customer
                {
                    // Check consultant is readly in conference
                    if (Services.Call.CheckCallInStatus(model.CallId, CallStatus.InProgress, true))
                    {
                        string template = ConferenceConst.SecondClientReadyForTalkNow;
                        message = string.Format(template, toUser.Name);

                        response.Say(message, new { voice = VoiceInConference, language = LanguageInConference });

                        // Get name conference room
                        var room = string.Format(ConferenceRoom, fromUser.UserName, toUser.UserName, model.BookingId);

                        // Update receiver call status
                        Services.Call.UpdateCallStatus(model.CallId, model.CallerStatus, true);

                        // Hangup Url
                        var callHangUpUrl = Utilities.FormatLink(Url.Action("CallHangUp", "Conference", model));
                        // Dial coference
                        response.DialConference(room,
                            new
                            {
                                endConferenceOnExit = true
                            },
                            new
                            {
                                record = true,
                                trim = "trim-silence",
                                transcribe = false,
                                action = callHangUpUrl
                            });
                    }
                    else
                    {
                        response.Say(ConferenceConst.ConsultantDenied, new { voice = VoiceInConference, language = LanguageInConference });
                    }
                }
                else
                {
                    string template = ConferenceConst.SecondClientReadyForSchedule;
                    message = string.Format(template, toUser.Name);
                    response.Say(message, new { voice = VoiceInConference, language = LanguageInConference });

                    // Get name conference room
                    var room = string.Format(ConferenceRoom, fromUser.UserName, toUser.UserName, model.BookingId); ;

                    // Dial coference
                    var callBackUrl = Utilities.FormatLink(Url.Action("CallBackAfterConference", "Conference", model));
                    response.DialConference(room,
                        new
                        {
                            endConferenceOnExit = true,
                            waitUrl = "http://twimlets.com/holdmusic?Bucket=com.twilio.music.electronica"
                        },
                        new
                        {
                            record = false,
                            transcribe = false,
                            action = callBackUrl
                        });

                    // Update receiver call status
                    Services.Call.UpdateCallStatus(model.CallId, model.CallerStatus, true);
                }
            }
            catch (Exception e)
            {
                Log.Error("Second client ready. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult FirstClientResponse(CallContextModel model, string digits)
        {
            var response = new TwilioResponse();
            try
            {
                if (model.IsCustomer) // Customer initiate call >> Consultant called first
                {
                    var optionKey = string.Empty;
                    var optionNotify = ConferenceConst.OptionNotifyForDefer;
                    var deferMinute = 5;

                    switch (digits)
                    {
                        case "1":
                            response.Redirect(Url.Action("FirstClientReady", model));

                            // Update on time and total consultation
                            Services.Call.UpdateOnTime(model.ReceiverId);
                            Services.Call.UpdateTotalConsultation(model.ReceiverId);

                            // Change css
                            CallHelper.ChangeCssDialToPhone(Services.Users.GetUserById(model.CallerId));
                            break;

                        case "2":

                            optionKey = ConferenceConst.OptionDefer5Minutes;
                            break;

                        case "3":

                            optionKey = ConferenceConst.OptionDefer10Minutes;
                            deferMinute = 10;
                            break;

                        case "4":

                            optionKey = ConferenceConst.OptionDefer15Minutes;
                            deferMinute = 15;
                            break;

                        case "5":

                            optionKey = ConferenceConst.OptionSchedule24Hours;
                            optionNotify = ConferenceConst.OptionNotifyForSchedule;
                            deferMinute = 24 * 60;
                            break;

                        case "6":

                            optionKey = ConferenceConst.OptionScheduleOver24Hours;
                            optionNotify = ConferenceConst.OptionNotifyForSchedule;
                            deferMinute = 48 * 60;
                            break;

                        case "9":

                            optionNotify = ConferenceConst.OptionDeclineConsultation;

                            // Update on time and total consultation
                            Services.Call.UpdateTotalConsultation(model.ReceiverId);
                            break;

                        default:

                            response.Redirect(Url.Action("FirstClientStart", model));
                            return new TwiMLResult(response);
                    }

                    var specialist = Services.Users.GetUserById(model.ReceiverId);

                    if (digits != "1")
                    {
                        if (digits != "9")
                        {
                            // Update booking to database
                            if (Services.Booking.UpdateBookingForDeferOrReSchedule(model.BookingId, deferMinute))
                            {
                                if (("7".Equals(digits) == false) || ("8".Equals(digits) == false))
                                {
                                    // Call function to show popup defer or reschedule for customer
                                    bool isDefer = false;
                                    if ("2".Equals(digits) || "3".Equals(digits) || "4".Equals(digits))
                                    {
                                        isDefer = true;
                                    }
                                    else
                                    {
                                        // Update status "Not available" for specilist when reschedule 5,6
                                        _cache.Remove(string.Format(ConferenceConst.CacheSpecialistStatus, specialist.Id));
                                        Services.Users.UpdateAvaibilityStatus(model.ReceiverId, AvailabilityStatus.NotAvailable);
                                    }

                                    CallHelper.ShowPopupTalkNowDeferOrReSchedule(model.CallerId, model.BookingId, isDefer, Services);
                                }
                            }
                            else // If update booking defer unsuccess
                            {
                                // Log
                                Log.Error("FirstClientResponse_Update booking fail");

                                throw new Exception("Update booking fail.");
                            }

                            response.Say(String.Format(ConferenceConst.PressKeyForSelectOption, digits, optionKey),
                                            new { voice = VoiceInConference, language = LanguageInConference });
                        }
                        else // Specialist declined the consultation
                        {
                            // Update defer for booking is -1
                            Services.Booking.UpdateDeferBooking(model.BookingId, -1);

                            // Notify for customer conference was declined by consultant
                            var customer = Services.Users.GetUserById(model.CallerId);
                            var sepecialist = Services.Users.GetUserById(model.ReceiverId);

                            CallHelper.ShowPopupNotifyInConference(customer,
                                    ConferencePopupConst.DeclinedTitle,
                                    string.Format(ConferencePopupConst.DeclinedContent, specialist.Name));

                            // Update status "Maybe available" for specilist when decline 9
                            _cache.Remove(string.Format(ConferenceConst.CacheSpecialistStatus, specialist.Id));

                            // Compare current status and only change status when it is available
                            if (AvailabilityStatus.Available.Equals(specialist.AvailabilityStatus))
                            {
                                Services.Users.UpdateAvaibilityStatus(model.ReceiverId, AvailabilityStatus.MaybeAvailable);
                            }
                        }

                        response.Say(optionNotify, new { voice = VoiceInConference, language = LanguageInConference });
                        response.Redirect(Url.Action("CallHangUpForDeferOrReSchedule", model));
                    }
                    else
                    {
                        // Add cache status for specialist when talk now to use reupdate after talknow
                        _cache.Add(string.Format(ConferenceConst.CacheSpecialistStatus, specialist.Id), specialist.AvailabilityStatus, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddDays(1) });

                        // Set status "NotAvailable" when begin talk now
                        Services.Users.UpdateAvaibilityStatus(model.ReceiverId, AvailabilityStatus.NotAvailable);
                    }
                }
                else // Consultant initiate call >>  Customer called first
                {
                    switch (digits)
                    {
                        case "1":

                            response.Redirect(Url.Action("FirstClientReady", model));
                            break;

                        default:
                            response.Redirect(Url.Action("FirstClientStart", model));
                            break;
                    }
                }

                return new TwiMLResult(response);
            }
            catch (Exception e)
            {
                // Log
                Log.Error("First client response. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            return new TwiMLResult(response);
        }
        public TwiMLResult WaiveFeeActionResponse(CallContextModel model, string digits)
        {
            var response = new TwilioResponse();

            try
            {
                switch (digits)
                {
                    case "1":
                        // Check waive fee already
                        var invoice = Services.Invoices.GetByBookingIdAndUserId(model.BookingId, model.CallerId);

                        if (invoice != null)
                        {
                            if (!invoice.IsWaiveFee)
                            {
                                // Send waive fee request
                                SendWaiveFeeRequest(model);

                                response.Say(ConferenceConst.AcctionCompleted, new { voice = VoiceInConference, language = LanguageInConference });
                            }
                            else
                            {
                                // Say waive fee alreadly
                                response.Say(ConferenceConst.WaiveFeeAlready, new { voice = VoiceInConference, language = LanguageInConference });
                            }
                        }

                        break;

                    default:
                        response.Redirect(Url.Action("ConsultantAfterCall", model));

                        break;
                }
            }
            catch (Exception e)
            {
                Log.Error("Waive fee action response. Error: ", e);

                // Error
                response.Say(ConferenceConst.ErrorMessage, new { voice = VoiceInConference, language = LanguageInConference });
                response.Hangup();
            }

            response.Redirect(Url.Action("ConsultantAfterCall", model));
            return new TwiMLResult(response);
        }