public async Task <TwilioResponse> ConfirmClose(TwilioRequest request)
        {
            var response = new TwilioResponse();
            int targetId;

            BeginMenu(response);
            if (int.TryParse(GetQueryParameter("targetId") ?? string.Empty, out targetId))
            {
                if (request.Digits != "9")
                {
                    response.SayVoice("{0} was not closed.", GetEventName());
                }
                else
                {
                    var target = await eventService.QuickClose(targetId);

                    this.session.EventId = null;
                    LoadActiveEvents();
                    response.SayVoice("{0} was closed.", target.Name);
                }
            }
            await EndMenu(response);

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <TwilioResponse> SetTimeOut(TwilioRequest request)
        {
            int minutes;
            var response = new TwilioResponse();

            // add prompt for miles
            response.BeginGather(new { timeout = 10, action = GetAction("SetMiles") });
            if (int.TryParse(request.Digits, out minutes))
            {
                using (var db = dbFactory())
                {
                    var signin = await GetMembersLatestSignin(db, this.session.MemberId);

                    signin.TimeOut = signin.TimeOut.Value.AddMinutes(minutes);
                    await db.SaveChangesAsync();

                    this.config.GetPushHub <CallsHub>().updatedRoster(RosterController.GetRosterEntry(signin.Id, db), true);
                    var sayDate = TimeUtils.GetMiltaryTimeVoiceText(signin.TimeOut.Value);
                    response.SayVoice(Speeches.SignedOutTemplate, this.session.MemberName, sayDate);
                }
            }
            response.SayVoice(Speeches.MilesPrompt);
            response.EndGather();

            return(LogResponse(response));
        }
Ejemplo n.º 3
0
        private async Task EndMenu(TwilioResponse response, bool isContinuation = false)
        {
            await StartMultiEventMenu(response, GetSignInOutPrompt(), isContinuation);

            response.SayVoice(this.session.HasRecording ? Speeches.PromptRecordReplacementMessageTemplate : Speeches.PromptRecordMessageTemplate, 3);
            response.SayVoice(Speeches.PromptChangeResponder, 8);
            response.SayVoice(Speeches.PromptAdminMenu, 9);
            response.EndGather();
        }
        public async Task <TwilioResponse> DoMenu(TwilioRequest request)
        {
            var response = new TwilioResponse();

            if (request.Digits == "1")
            {
                var now      = TimeUtils.GetLocalDateTime(this.config);
                var newEvent = new SarEvent {
                    Name = "New Event at " + TimeUtils.GetMiltaryTimeVoiceText(now), Opened = now
                };
                await this.eventService.Create(newEvent);

                LoadActiveEvents();
                this.session.EventId = newEvent.Id;

                BeginMenu(response);
                response.SayVoice("Created " + newEvent.Name);

                await EndMenu(response);
            }
            else if (request.Digits == "2")
            {
                using (var db = dbFactory())
                {
                    BuildSetEventMenu(response, string.Empty, Url.Content("~/api/VoiceAdmin/Menu"));
                }
            }
            else if (request.Digits == "3")
            {
                response.SayVoice("Record a short description of this event at the tone");
                response.Record(new { maxLength = 120, action = GetAction("SetDescription", controller: "VoiceAdmin") });
                BeginMenu(response);
                await EndMenu(response);
            }
            else if (request.Digits == "9")
            {
                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("targetId", this.session.EventId.ToString());
                response.BeginGather(new { numDigits = 1, action = GetAction("ConfirmClose", args, controller: "VoiceAdmin"), timeout = 10 });
                response.SayVoice("Press 9 to confirm close of {0}. Press any other key to return to menu.", GetEventName());
                response.EndGather();
            }
            else if (request.Digits == "0")
            {
                response.Redirect(GetAction("Menu"));
            }
            else
            {
                response.SayVoice("I didn't understand.");
                BeginMenu(response);
                await EndMenu(response);
            }
            return(response);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="response"></param>
        private async Task EndMenu(TwilioResponse response)
        {
            await StartMultiEventMenu(response, "create a new event");

            if (this.session.EventId != null)
            {
                response.SayVoice("Press 3 to record a new greeting");
                response.SayVoice("Press 9 to close this mission");
            }
            response.SayVoice("Press 0 to return to main menu");
            response.EndGather();
        }
Ejemplo n.º 6
0
        private async Task AddLoginPrompt(TwilioResponse response, string next)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add(NextKey, next ?? Url.Content("~/api/Voice/Menu"));

            response.BeginGather(new { timeout = 10, action = GetAction("DoLogin", args) });
            response.SayVoice(Speeches.DEMPrompt);
            response.SayVoice(Speeches.GoBack);
            response.EndGather();
            BeginMenu(response);
            await EndMenu(response);
        }
Ejemplo n.º 7
0
        public async Task <TwilioResponse> Answer(TwilioRequest request)
        {
            await SetMemberInfoFromPhone(request.From);
            await UpdateSigninStatus();

            using (var db = dbFactory())
            {
                var call = new VoiceCall
                {
                    CallId   = request.CallSid,
                    Number   = request.From,
                    CallTime = TimeUtils.GetLocalDateTime(this.config),
                    Name     = this.session.MemberName
                };

                db.Calls.Add(call);
                await db.SaveChangesAsync();

                this.config.GetPushHub <CallsHub>().updatedCall(CallsController.GetCallEntry(call));
            }

            var response = new TwilioResponse();

            BeginMenu(response);
            if (this.session.MemberId == null)
            {
                response.SayVoice(Speeches.WelcomeUnknownCaller);
            }

            await EndMenu(response);

            return(LogResponse(response));
        }
Ejemplo n.º 8
0
        public async Task <TwilioResponse> StopRecording(TwilioRequest request)
        {
            TwilioResponse response = new TwilioResponse();

            using (var db = dbFactory())
            {
                var call = db.Calls.Single(f => f.CallId == request.CallSid);
                //if (!string.IsNullOrWhiteSpace(call.RecordingUrl))
                //{
                //  // Delete previous recording
                //}
                call.RecordingDuration = request.RecordingDuration;
                call.RecordingUrl      = request.RecordingUrl;
                await db.SaveChangesAsync();

                this.session.HasRecording = true;

                this.config.GetPushHub <CallsHub>().updatedCall(CallsController.GetCallEntry(call));

                BeginMenu(response);
                response.SayVoice(Speeches.CallerRecordingSaved);
                await EndMenu(response, true);
            }
            return(LogResponse(response));
        }
Ejemplo n.º 9
0
        public async Task <TwilioResponse> SetMiles(TwilioRequest request)
        {
            var response = new TwilioResponse();

            BeginMenu(response);

            int miles;

            if (int.TryParse(request.Digits, out miles))
            {
                using (var db = dbFactory())
                {
                    var signin = db.SignIns.OrderByDescending(f => f.TimeIn).FirstOrDefault(f => f.MemberId == this.session.MemberId);
                    signin.Miles = miles;
                    await db.SaveChangesAsync();

                    this.config.GetPushHub <CallsHub>().updatedRoster(RosterController.GetRosterEntry(signin.Id, db), true);
                }
                response.SayVoice(Speeches.MilesUpdated);
            }

            await EndMenu(response, true);

            return(LogResponse(response));
        }
Ejemplo n.º 10
0
        protected void BuildSetEventMenu(TwilioResponse response, string prompt, string thenUrl)
        {
            Dictionary <string, string> args = new Dictionary <string, string>();

            args.Add("evtIds", string.Join(".", this.CurrentEvents.Select(f => f.Id.ToString())));
            args.Add("next", thenUrl);

            response.BeginGather(new { timeout = 10, action = GetAction("SetEvent", args) });
            if (!string.IsNullOrWhiteSpace(prompt))
            {
                response.SayVoice(prompt);
            }
            response.SayVoice(string.Format("There are {0} events in progress. ", this.CurrentEvents.Count));
            for (int i = 0; i < this.CurrentEvents.Count; i++)
            {
                response.SayVoice(string.Format("Press {0} then pound for {1}. ", i + 1, this.CurrentEvents[i].Name));
            }
            response.EndGather();
        }
Ejemplo n.º 11
0
        public async Task <TwilioResponse> DoMenu(TwilioRequest request)
        {
            var response = new TwilioResponse();

            if (request.Digits == "1")
            {
                if (this.session.MemberId == null)
                {
                    await AddLoginPrompt(response, Url.Content("~/api/Voice/DoSignInOut"));
                }
                else
                {
                    response = await DoSignInOut(request);
                }
            }
            else if (request.Digits == "2")
            {
                BuildSetEventMenu(response, string.Empty, Url.Content("~/api/voice/Menu"));
            }
            else if (request.Digits == "3")
            {
                response.SayVoice(Speeches.StartRecording);
                response.Record(new { maxLength = 120, action = GetAction("StopRecording") });
                BeginMenu(response);
                await EndMenu(response);
            }
            else if (request.Digits == "8")
            {
                await AddLoginPrompt(response, Url.Content("~/api/voice/Menu"));
            }
            else if (request.Digits == "9")
            {
                response.Redirect(GetAction("Menu", controller: "VoiceAdmin"));
            }
            else
            {
                response.SayVoice(Speeches.InvalidSelection);
                BeginMenu(response);
                await EndMenu(response);
            }

            return(LogResponse(response));
        }
        public async Task <TwilioResponse> SetDescription(TwilioRequest request)
        {
            await this.eventService.SetRecordedDescription(this.session.EventId.Value, request.RecordingUrl);

            TwilioResponse response = new TwilioResponse();

            BeginMenu(response);
            response.SayVoice("New greeting saved.");
            await EndMenu(response);

            return(response);
        }
        public async Task <TwilioResponse> Menu()
        {
            var response = new TwilioResponse();

            if (this.session.IsAdmin == false)
            {
                response.BeginGather(new { numDigits = 10, action = GetAction("Login", controller: "VoiceAdmin"), timeout = 10 });
                response.SayVoice("Enter admin password followed by pound");
                response.EndGather();
            }
            else
            {
                BeginMenu(response);
                await EndMenu(response);
            }

            return(response);
        }
Ejemplo n.º 14
0
        public async Task <TwilioResponse> SetSigninEvent(TwilioRequest request)
        {
            var response = new TwilioResponse();

            using (var db = dbFactory())
            {
                var signin = await GetMembersLatestSignin(db, session.MemberId);

                await RosterController.AssignInternal(signin, session.EventId, db, this.config);

                var name = CurrentEvents.Where(f => f.Id == session.EventId).Select(f => f.Name).SingleOrDefault();
                response.SayVoice(Speeches.ChangeEventTemplate, name);
            }

            response.Redirect(Url.Content("~/api/Voice/Menu") + session.ToQueryString());

            return(LogResponse(response));
        }
Ejemplo n.º 15
0
        protected async Task <List <SarEvent> > StartMultiEventMenu(TwilioResponse response, string pressOnePrompt, bool isContinuation = false)
        {
            var activeEvents = await this.eventService.ListActive();

            if (activeEvents.Count > 1)
            {
                response.SayVoice(Speeches.ActiveEventsTemplate, activeEvents.Count);
            }
            if (this.session.EventId != null)
            {
                var theEvent = activeEvents.Where(f => f.Id == this.session.EventId).SingleOrDefault();
                response.SayVoice(Speeches.CurrentEventTemplate, theEvent == null ? Speeches.UnknownEvent : theEvent.Name);

                if (this.EventWasChanged && theEvent != null)
                {
                    if (!string.IsNullOrWhiteSpace(theEvent.OutgoingUrl))
                    {
                        response.Play(theEvent.OutgoingUrl);
                    }
                    else if (!string.IsNullOrWhiteSpace(theEvent.OutgoingText))
                    {
                        response.SayVoice(theEvent.OutgoingText);
                    }
                }
            }
            if (isContinuation)
            {
                response.SayVoice(Speeches.HangUpOr);
            }
            response.SayVoice(Speeches.PressOneTemplate, pressOnePrompt);
            if (activeEvents.Count > 1)
            {
                response.SayVoice(Speeches.PromptSwitchEventTemplate, 2);
            }
            return(activeEvents);
        }
Ejemplo n.º 16
0
        public async Task <TwilioResponse> DoSignInOut(TwilioRequest request)
        {
            var response = new TwilioResponse();

            using (var db = dbFactory())
            {
                var signin = await db.SignIns.Where(f => f.MemberId == this.session.MemberId).OrderByDescending(f => f.TimeIn).FirstOrDefaultAsync();

                var call = await db.Calls.SingleAsync(f => f.CallId == request.CallSid);

                DateTimeOffset time    = TimeUtils.GetLocalDateTime(this.config);
                var            sayDate = TimeUtils.GetMiltaryTimeVoiceText(time);

                if (signin == null || signin.TimeOut.HasValue)
                {
                    if (this.session.IsSignedIn)
                    {
                        throw new InvalidOperationException("Tried to sign out when not signed in");
                    }

                    signin = new MemberSignIn
                    {
                        MemberId = this.session.MemberId,
                        isMember = true,
                        Name     = this.session.MemberName,
                        TimeIn   = time,
                        EventId  = (this.CurrentEvents.Count == 1) ? this.CurrentEvents[0].Id : this.session.EventId,
                    };

                    db.SignIns.Add(signin);
                    call.Actions.Add(new CallAction {
                        Call = call, CallId = call.Id, Time = signin.TimeIn, Action = "Signed in " + signin.Name
                    });
                    await db.SaveChangesAsync();

                    this.session.IsSignedIn = true;

                    if (this.CurrentEvents.Count == 0)
                    {
                        await RosterController.AssignInternal(signin, null, db, this.config);

                        BeginMenu(response);
                        response.SayVoice(Speeches.SignedInUnassignedTemplate, this.session.MemberName, sayDate);
                        await EndMenu(response);
                    }
                    else if (this.CurrentEvents.Count == 1)
                    {
                        await RosterController.AssignInternal(signin, this.CurrentEvents[0].Id, db, this.config);

                        BeginMenu(response);
                        response.SayVoice(Speeches.SignedInTemplate, this.CurrentEvents[0].Name, this.session.MemberName, sayDate);
                        await EndMenu(response);
                    }
                    else
                    {
                        await RosterController.AssignInternal(signin, null, db, this.config);

                        BuildSetEventMenu(response, string.Format(Speeches.SignedInUnassignedTemplate, this.session.MemberName, sayDate), Url.Content("~/api/voice/SetSigninEvent"));
                    }
                }
                else
                {
                    signin.TimeOut = time;
                    call.Actions.Add(new CallAction {
                        Call = call, CallId = call.Id, Time = time, Action = "Signed out " + this.session.MemberName
                    });
                    this.session.IsSignedIn = false;
                    await db.SaveChangesAsync();

                    this.config.GetPushHub <CallsHub>().updatedRoster(RosterController.GetRosterEntry(signin.Id, db), true);

                    // add prompt for timeout beyond right now
                    response.BeginGather(new { timeout = 10, action = GetAction("SetTimeOut") });
                    response.SayVoice(Speeches.SignedOutTemplate, this.session.MemberName, sayDate);
                    response.SayVoice(Speeches.TimeoutPrompt);
                    response.EndGather();
                }
            }

            return(LogResponse(response));
        }