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

Commit 2641ae1

Browse files
xieofxiebobokids
authored andcommitted
[Hospitality] LateCheckOut uses time (#2652)
* Remove redundant luis calls
1 parent 86e9dcd commit 2641ae1

File tree

9 files changed

+78
-24
lines changed

9 files changed

+78
-24
lines changed

skills/csharp/experimental/hospitalityskill/Dialogs/HospitalityDialogBase.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ protected async Task<DialogTurnResult> GetAuthToken(WaterfallStepContext sc, Can
101101
// When the token is cached we get a TokenResponse object.
102102
if (sc.Result is ProviderTokenResponse providerTokenResponse)
103103
{
104-
var state = await StateAccessor.GetAsync(sc.Context);
105-
state.Token = providerTokenResponse.TokenResponse.Token;
104+
return await sc.NextAsync(providerTokenResponse);
105+
}
106+
else
107+
{
108+
return await sc.NextAsync();
106109
}
107-
108-
return await sc.NextAsync();
109110
}
110111
catch (SkillException ex)
111112
{
@@ -152,15 +153,7 @@ protected async Task GetLuisResult(DialogContext dc)
152153
if (dc.Context.Activity.Type == ActivityTypes.Message)
153154
{
154155
var state = await StateAccessor.GetAsync(dc.Context, () => new HospitalitySkillState());
155-
156-
// Get luis service for current locale
157-
var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
158-
var localeConfig = Services.CognitiveModelSets[locale];
159-
var luisService = localeConfig.LuisServices["Hospitality"];
160-
161-
// Get intent and entities for activity
162-
var result = await luisService.RecognizeAsync<HospitalityLuis>(dc.Context, CancellationToken.None);
163-
state.LuisResult = result;
156+
state.LuisResult = dc.Context.TurnState.Get<HospitalityLuis>(StateProperties.SkillLuisResult);
164157
}
165158
}
166159

skills/csharp/experimental/hospitalityskill/Dialogs/LateCheckOutDialog.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Collections.Specialized;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -11,6 +12,7 @@
1112
using Microsoft.Bot.Builder;
1213
using Microsoft.Bot.Builder.Dialogs;
1314
using Microsoft.Bot.Builder.Solutions.Responses;
15+
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
1416

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

68+
var convState = await StateAccessor.GetAsync(sc.Context, () => new HospitalitySkillState());
69+
var entities = convState.LuisResult.Entities;
70+
if (entities.datetime != null && (entities.datetime[0].Type == "time" || entities.datetime[0].Type == "timerange"))
71+
{
72+
var timexProperty = new TimexProperty();
73+
TimexParsing.ParseString(entities.datetime[0].Expressions[0], timexProperty);
74+
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));
75+
if (preferedTime < lateTime)
76+
{
77+
lateTime = preferedTime;
78+
}
79+
}
80+
81+
convState.UpdatedReservation = new ReservationData { CheckOutTimeData = lateTime };
82+
6683
var tokens = new StringDictionary
6784
{
68-
{ "Time", lateTime },
85+
{ "Time", convState.UpdatedReservation.CheckOutTime },
6986
};
7087

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

90-
userState.UserReservation.CheckOutTime = await _hotelService.GetLateCheckOutAsync();
107+
var convState = await StateAccessor.GetAsync(promptContext.Context, () => new HospitalitySkillState());
108+
userState.UserReservation.CheckOutTimeData = convState.UpdatedReservation.CheckOutTimeData;
91109

92110
// set new checkout in hotel service
93111
_hotelService.UpdateReservationDetails(userState.UserReservation);

skills/csharp/experimental/hospitalityskill/Dialogs/MainDialog.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ public MainDialog(
6262
AddDialog(roomServiceDialog ?? throw new ArgumentNullException(nameof(roomServiceDialog)));
6363
}
6464

65+
protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
66+
{
67+
if (innerDc.Context.Activity.Type == ActivityTypes.Message)
68+
{
69+
// Get cognitive models for the current locale.
70+
var locale = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
71+
var localizedServices = _services.CognitiveModelSets[locale];
72+
73+
// Run LUIS recognition on Skill model and store result in turn state.
74+
var skillResult = await localizedServices.LuisServices["Hospitality"].RecognizeAsync<HospitalityLuis>(innerDc.Context, cancellationToken);
75+
innerDc.Context.TurnState.Add(StateProperties.SkillLuisResult, skillResult);
76+
77+
// Run LUIS recognition on General model and store result in turn state.
78+
var generalResult = await localizedServices.LuisServices["General"].RecognizeAsync<GeneralLuis>(innerDc.Context, cancellationToken);
79+
innerDc.Context.TurnState.Add(StateProperties.GeneralLuisResult, generalResult);
80+
}
81+
82+
return await base.OnContinueDialogAsync(innerDc, cancellationToken);
83+
}
84+
6585
protected override async Task OnMembersAddedAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
6686
{
6787
await dc.Context.SendActivityAsync(_responseManager.GetResponse(MainResponses.WelcomeMessage));
@@ -87,7 +107,12 @@ public MainDialog(
87107
}
88108
else
89109
{
90-
var result = await luisService.RecognizeAsync<HospitalityLuis>(dc.Context, CancellationToken.None);
110+
if (string.IsNullOrEmpty(dc.Context.Activity.Text))
111+
{
112+
return;
113+
}
114+
115+
var result = dc.Context.TurnState.Get<HospitalityLuis>(StateProperties.SkillLuisResult);
91116
var intent = result?.TopIntent().intent;
92117

93118
switch (intent)
@@ -209,7 +234,7 @@ protected override async Task OnUnhandledActivityTypeAsync(DialogContext innerDc
209234
}
210235
else
211236
{
212-
var luisResult = await luisService.RecognizeAsync<GeneralLuis>(dc.Context, cancellationToken);
237+
var luisResult = dc.Context.TurnState.Get<GeneralLuis>(StateProperties.GeneralLuisResult);
213238
var topIntent = luisResult.TopIntent();
214239

215240
if (topIntent.score > 0.5)

skills/csharp/experimental/hospitalityskill/Models/HospitalitySkillState.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace HospitalitySkill.Models
99
{
1010
public class HospitalitySkillState
1111
{
12-
public string Token { get; set; }
13-
1412
public HospitalityLuis LuisResult { get; set; }
1513

1614
public ReservationData UpdatedReservation { get; set; }

skills/csharp/experimental/hospitalityskill/Models/HospitalityUserSkillState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public HospitalityUserSkillState()
1515
{
1616
CheckInDate = DateTime.Now.ToString("MMMM d, yyyy"),
1717
CheckOutDate = DateTime.Now.AddDays(4).ToString("MMMM d, yyyy"),
18-
CheckOutTime = "12:00 pm"
18+
CheckOutTimeData = new TimeSpan(12, 0, 0)
1919
};
2020
}
2121

skills/csharp/experimental/hospitalityskill/Models/ReservationData.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using Microsoft.Bot.Builder.Solutions.Responses;
56

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

1415
public string CheckOutDate { get; set; }
1516

16-
public string CheckOutTime { get; set; }
17+
public string CheckOutTime { get { return CheckOutTimeData.ToString(@"hh\:mm"); } }
18+
19+
public TimeSpan CheckOutTimeData { get; set; }
1720

1821
public ReservationData Copy()
1922
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
9+
namespace HospitalitySkill.Models
10+
{
11+
public class StateProperties
12+
{
13+
public const string GeneralLuisResult = "generalLuisResult";
14+
public const string SkillLuisResult = "skillLuisResult";
15+
}
16+
}

skills/csharp/experimental/hospitalityskill/Services/HotelService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public HotelService()
3535
.First();
3636
}
3737

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

4343
return await Task.FromResult(lateTime);
4444
}

skills/csharp/experimental/hospitalityskill/Services/IHotelService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Threading.Tasks;
67
using HospitalitySkill.Models;
@@ -18,7 +19,7 @@ public interface IHotelService
1819
void UpdateReservationDetails(ReservationData reservation);
1920

2021
// check late check out availability
21-
Task<string> GetLateCheckOutAsync();
22+
Task<TimeSpan> GetLateCheckOutAsync();
2223

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

0 commit comments

Comments
 (0)