public SkillResponse Handle(IntentRequest intentRequest, ILambdaContext context, Session session) { var goApiClient = new GoApiClient(); var intent = intentRequest.Intent; if (IsDialogIntentRequest(intentRequest)) { if (IsDialogSequenceComplete(intentRequest) == false) { return(ResponseBuilder.DialogDelegate(session)); } } var dateSlotValue = intent.Slots["date"].Value; var timeSlotValue = intent.Slots["time"].Value; var classNameSlotValue = intent.Slots["className"].Value; var time = Convert.ToDateTime(timeSlotValue); context.Logger.LogLine($"Date:{dateSlotValue}"); var localBindDate = NodaTime.AmazonDate.AmazonDateParser.Parse(dateSlotValue); var dateFrom = localBindDate.From.ToDateTimeUnspecified(); var bookingDateTime = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, time.Hour, time.Minute, time.Second); var result = goApiClient.BookClass(new BookClassParams { ClassStartDate = bookingDateTime, ClassName = classNameSlotValue }).Result; return(ResponseBuilder.Tell(result.Errors.Any() ? "There was an error booking a class. Please try again." : "Classes was booked.")); }
public SkillResponse Handle(IntentRequest intentRequest, ILambdaContext context, Session session) { if (IsDialogIntentRequest(intentRequest)) { if (IsDialogSequenceComplete(intentRequest) == false) { return(ResponseBuilder.DialogDelegate(session)); } } var intent = intentRequest.Intent; var dateSlotValue = intent.Slots["date"].Value; var clubNameSlotValue = intent.Slots["clubName"].Value; var classNameSlotValue = intent.Slots["className"].Value; var date = NodaTime.AmazonDate.AmazonDateParser.Parse(dateSlotValue); var dateFrom = date.From.ToDateTimeUnspecified(); var dateTo = date.To.ToDateTimeUnspecified(); if (dateFrom == dateTo) { dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, 0, 0, 0); dateTo = new DateTime(dateTo.Year, dateTo.Month, dateTo.Day, 23, 59, 59); } var goApiClient = new GoApiClient(); var result = goApiClient.UpcomingClasses(classNameSlotValue, clubNameSlotValue, dateFrom, dateTo).Result; if (result.Errors.Any()) { return(ResponseBuilder.Tell($"{result.Errors.First().Message}")); } var bookingsResponse = string.Join(',', result.Data.OrderBy(x => x.StartDate). Select(x => { var startDate = x.StartDate.ToString("dddd dd MMMM hh:mm tt", CultureInfo.CreateSpecificCulture("en-US")); return($" {x.ClassName} on {startDate}"); })); var speech = new SsmlOutputSpeech { Ssml = $"<speak>{ GetFirstPartResponse(result.Data.Count())}{ bookingsResponse}</speak>" }; var repromptMessage = new PlainTextOutputSpeech { Text = "Would you like to book one ?" }; var repromptBody = new Reprompt(); repromptBody.OutputSpeech = repromptMessage; var finalResponse = ResponseBuilder.Ask(speech, repromptBody); return(finalResponse); //return ResponseBuilder.Ask($"{GetFirstPartResponse(result.Data.Count())}{bookingsResponse}", // new Reprompt("Whould you like to book one? ")); }
public async Task UpcomingBooking_Should_Return_UpcomingBookings_For_Valid_Request() { var goApiClient = new GoApiClient(); var result = await goApiClient.UpcomingBookings(); Assert.NotNull(result); Assert.True(result.Data.Any()); }
public async Task UpcomingClasses_Should_Return_UpcomingBookings_For_Valid_Request() { var goApiClient = new GoApiClient(); var result = await goApiClient.UpcomingClasses("Aerobics", "PerfectFit", new DateTime(2018, 8, 22), new DateTime(2018, 8, 24)); Assert.NotNull(result); Assert.True(result.Data.Any()); }
public async Task UpcomingClasses_Should_Return_Error_For_BadRequest() { var goApiClient = new GoApiClient(); var result = await goApiClient.UpcomingClasses("", "", new DateTime(2018, 8, 22), new DateTime(2018, 8, 24)); Assert.NotNull(result); Assert.True(result.Errors.Any()); }
public async Task BookClass_Should_Return_Error_For_BadRequest() { var goApiClient = new GoApiClient(); var result = await goApiClient.BookClass(new BookClassParams() { ClassName = "aaa", ClassStartDate = DateTime.Now }); Assert.NotNull(result); Assert.True(result.Errors.Any()); }
public SkillResponse Handle(IntentRequest intent, ILambdaContext context, Session inputSession) { var goApiClient = new GoApiClient(); var result = goApiClient.UpcomingBookings().Result; if (result.Errors.Any()) { return(ResponseBuilder.Tell($"{result.Errors.First().Message}")); } if (result.Data.Any() == false) { var speech = new SsmlOutputSpeech { Ssml = "<speak>I didn't find any bookings.</speak>" }; var repromptMessage = new PlainTextOutputSpeech { Text = "Would you like to book class now ?" }; var repromptBody = new Reprompt(); repromptBody.OutputSpeech = repromptMessage; var finalResponse = ResponseBuilder.Ask(speech, repromptBody); return(finalResponse); } var day = result.Data.Select(x => x.ClassStartDate).First().ToString("dddd d MMMM", CultureInfo.CreateSpecificCulture("en-US")); var bookingsResponse = string.Join(',', result.Data.OrderBy(x => x.ClassStartDate). Select(x => $" {x.ClassName} at {x.ClassStartDate.ToShortTimeString()}")); var speech1 = new SsmlOutputSpeech { Ssml = $"<speak>{GetFirstPartResponse(result.Data.Count(), day)}{bookingsResponse}</speak>" }; var repromptMessage1 = new PlainTextOutputSpeech { Text = "" }; var repromptBody1 = new Reprompt(); repromptBody1.OutputSpeech = repromptMessage1; var finalResponse1 = ResponseBuilder.Ask(speech1, repromptBody1); return(finalResponse1); // return ResponseBuilder.Tell($"{GetFirstPartResponse(result.Data.Count(), day)}{bookingsResponse}"); }
public async Task CancelBooking_Should_Return_Success_For_ValidRequest() { var goApiClient = new GoApiClient(); var bookClassResult = await goApiClient.BookClass(new BookClassParams { ClassName = "Aerobics", ClassStartDate = new DateTime(2018, 8, 31, 0, 0, 0) }); Assert.NotNull(bookClassResult); Assert.False(bookClassResult.Errors.Any()); var result = await goApiClient.CancelBooking(new CancelBookingParams { ClassName = "Aerobics", ClassStartDate = new DateTime(2018, 8, 31, 0, 0, 0) }); Assert.NotNull(result); Assert.False(result.Errors.Any()); }