Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[Hospitality] LateCheckOut uses time #2652

Merged
merged 1 commit into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
// When the token is cached we get a TokenResponse object.
if (sc.Result is ProviderTokenResponse providerTokenResponse)
{
var state = await StateAccessor.GetAsync(sc.Context);
state.Token = providerTokenResponse.TokenResponse.Token;
return await sc.NextAsync(providerTokenResponse);
}
else
{
return await sc.NextAsync();
}

return await sc.NextAsync();
}
catch (SkillException ex)
{
Expand Down Expand Up @@ -152,15 +153,7 @@ protected async Task GetLuisResult(DialogContext dc)
if (dc.Context.Activity.Type == ActivityTypes.Message)
{
var state = await StateAccessor.GetAsync(dc.Context, () => new HospitalitySkillState());

// Get luis service for current locale
var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
var localeConfig = Services.CognitiveModelSets[locale];
var luisService = localeConfig.LuisServices["Hospitality"];

// Get intent and entities for activity
var result = await luisService.RecognizeAsync<HospitalityLuis>(dc.Context, CancellationToken.None);
state.LuisResult = result;
state.LuisResult = dc.Context.TurnState.Get<HospitalityLuis>(StateProperties.SkillLuisResult);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Specialized;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,6 +12,7 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;

namespace HospitalitySkill.Dialogs
{
Expand Down Expand Up @@ -63,9 +65,24 @@ private async Task<DialogTurnResult> LateCheckOutPrompt(WaterfallStepContext sc,
await Task.Delay(1600);
var lateTime = await _hotelService.GetLateCheckOutAsync();

var convState = await StateAccessor.GetAsync(sc.Context, () => new HospitalitySkillState());
var entities = convState.LuisResult.Entities;
if (entities.datetime != null && (entities.datetime[0].Type == "time" || entities.datetime[0].Type == "timerange"))
{
var timexProperty = new TimexProperty();
TimexParsing.ParseString(entities.datetime[0].Expressions[0], timexProperty);
var preferedTime = new TimeSpan(timexProperty.Hour ?? 0, timexProperty.Minute ?? 0, timexProperty.Second ?? 0) + new TimeSpan((int)(timexProperty.Hours ?? 0), (int)(timexProperty.Minutes ?? 0), (int)(timexProperty.Seconds ?? 0));
if (preferedTime < lateTime)
{
lateTime = preferedTime;
}
}

convState.UpdatedReservation = new ReservationData { CheckOutTimeData = lateTime };

var tokens = new StringDictionary
{
{ "Time", lateTime },
{ "Time", convState.UpdatedReservation.CheckOutTime },
};

return await sc.PromptAsync(DialogIds.LateCheckOutPrompt, new PromptOptions()
Expand All @@ -87,7 +104,8 @@ private async Task<bool> ValidateLateCheckOutAsync(PromptValidatorContext<bool>
// TODO process late check out request here
userState.LateCheckOut = true;

userState.UserReservation.CheckOutTime = await _hotelService.GetLateCheckOutAsync();
var convState = await StateAccessor.GetAsync(promptContext.Context, () => new HospitalitySkillState());
userState.UserReservation.CheckOutTimeData = convState.UpdatedReservation.CheckOutTimeData;

// set new checkout in hotel service
_hotelService.UpdateReservationDetails(userState.UserReservation);
Expand Down
29 changes: 27 additions & 2 deletions skills/csharp/experimental/hospitalityskill/Dialogs/MainDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ public MainDialog(
AddDialog(roomServiceDialog ?? throw new ArgumentNullException(nameof(roomServiceDialog)));
}

protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
{
if (innerDc.Context.Activity.Type == ActivityTypes.Message)
{
// Get cognitive models for the current locale.
var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
var localizedServices = _services.CognitiveModelSets[locale];

// Run LUIS recognition on Skill model and store result in turn state.
var skillResult = await localizedServices.LuisServices["Hospitality"].RecognizeAsync<HospitalityLuis>(innerDc.Context, cancellationToken);
innerDc.Context.TurnState.Add(StateProperties.SkillLuisResult, skillResult);

// Run LUIS recognition on General model and store result in turn state.
var generalResult = await localizedServices.LuisServices["General"].RecognizeAsync<GeneralLuis>(innerDc.Context, cancellationToken);
innerDc.Context.TurnState.Add(StateProperties.GeneralLuisResult, generalResult);
}

return await base.OnContinueDialogAsync(innerDc, cancellationToken);
}

protected override async Task OnMembersAddedAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
{
await dc.Context.SendActivityAsync(_responseManager.GetResponse(MainResponses.WelcomeMessage));
Expand All @@ -87,7 +107,12 @@ public MainDialog(
}
else
{
var result = await luisService.RecognizeAsync<HospitalityLuis>(dc.Context, CancellationToken.None);
if (string.IsNullOrEmpty(dc.Context.Activity.Text))
{
return;
}

var result = dc.Context.TurnState.Get<HospitalityLuis>(StateProperties.SkillLuisResult);
var intent = result?.TopIntent().intent;

switch (intent)
Expand Down Expand Up @@ -209,7 +234,7 @@ protected override async Task OnUnhandledActivityTypeAsync(DialogContext innerDc
}
else
{
var luisResult = await luisService.RecognizeAsync<GeneralLuis>(dc.Context, cancellationToken);
var luisResult = dc.Context.TurnState.Get<GeneralLuis>(StateProperties.GeneralLuisResult);
var topIntent = luisResult.TopIntent();

if (topIntent.score > 0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace HospitalitySkill.Models
{
public class HospitalitySkillState
{
public string Token { get; set; }

public HospitalityLuis LuisResult { get; set; }

public ReservationData UpdatedReservation { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public HospitalityUserSkillState()
{
CheckInDate = DateTime.Now.ToString("MMMM d, yyyy"),
CheckOutDate = DateTime.Now.AddDays(4).ToString("MMMM d, yyyy"),
CheckOutTime = "12:00 pm"
CheckOutTimeData = new TimeSpan(12, 0, 0)
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Microsoft.Bot.Builder.Solutions.Responses;

namespace HospitalitySkill.Models
Expand All @@ -13,7 +14,9 @@ public class ReservationData : ICardData

public string CheckOutDate { get; set; }

public string CheckOutTime { get; set; }
public string CheckOutTime { get { return CheckOutTimeData.ToString(@"hh\:mm"); } }

public TimeSpan CheckOutTimeData { get; set; }

public ReservationData Copy()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace HospitalitySkill.Models
{
public class StateProperties
{
public const string GeneralLuisResult = "generalLuisResult";
public const string SkillLuisResult = "skillLuisResult";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public HotelService()
.First();
}

public async Task<string> GetLateCheckOutAsync()
public async Task<TimeSpan> GetLateCheckOutAsync()
{
// make request for the late check out time
var lateTime = "4:00 pm";
var lateTime = new TimeSpan(16, 0, 0);

return await Task.FromResult(lateTime);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using HospitalitySkill.Models;
Expand All @@ -18,7 +19,7 @@ public interface IHotelService
void UpdateReservationDetails(ReservationData reservation);

// check late check out availability
Task<string> GetLateCheckOutAsync();
Task<TimeSpan> GetLateCheckOutAsync();

// request items to be brought
Task<bool> RequestItems(List<ItemRequestClass> items);
Expand Down