public async Task <DialogTurnResult> ShowNextEvent(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); var askParameter = new AskParameterModel(state.AskParameterContent); if (string.IsNullOrEmpty(state.APIToken)) { return(await sc.EndDialogAsync(true)); } var calendarService = ServiceManager.InitCalendarService(state.APIToken, state.EventSource); var eventList = await calendarService.GetUpcomingEvents(); var nextEventList = new List <EventModel>(); foreach (var item in eventList) { if (item.IsCancelled != true && (nextEventList.Count == 0 || nextEventList[0].StartTime == item.StartTime)) { nextEventList.Add(item); } } if (nextEventList.Count == 0) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ShowNoMeetingMessage)); } else { if (nextEventList.Count == 1) { // if user asked for specific details if (askParameter.NeedDetail) { var tokens = new StringDictionary() { { "EventName", nextEventList[0].Title }, { "EventStartTime", TimeConverter.ConvertUtcToUserTime(nextEventList[0].StartTime, state.GetUserTimeZone()).ToString("h:mm tt") }, { "EventEndTime", TimeConverter.ConvertUtcToUserTime(nextEventList[0].EndTime, state.GetUserTimeZone()).ToString("h:mm tt") }, { "EventDuration", nextEventList[0].ToSpeechDurationString() }, { "EventLocation", nextEventList[0].Location }, }; await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.BeforeShowEventDetails, tokens)); if (askParameter.NeedTime) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadTime, tokens)); } if (askParameter.NeedDuration) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadDuration, tokens)); } if (askParameter.NeedLocation) { // for some event there might be no localtion. if (string.IsNullOrEmpty(tokens["EventLocation"])) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadNoLocation)); } else { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadLocation, tokens)); } } } var speakParams = new StringDictionary() { { "EventName", nextEventList[0].Title }, { "PeopleCount", nextEventList[0].Attendees.Count.ToString() }, }; speakParams.Add("EventTime", SpeakHelper.ToSpeechMeetingDateTime(TimeConverter.ConvertUtcToUserTime(nextEventList[0].StartTime, state.GetUserTimeZone()), nextEventList[0].IsAllDay == true)); if (string.IsNullOrEmpty(nextEventList[0].Location)) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ShowNextMeetingNoLocationMessage, speakParams)); } else { speakParams.Add("Location", nextEventList[0].Location); await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ShowNextMeetingMessage, speakParams)); } } else { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ShowMultipleNextMeetingMessage)); } var reply = await GetGeneralMeetingListResponseAsync(sc, CalendarCommonStrings.UpcommingMeeting, nextEventList, null, null); await sc.Context.SendActivityAsync(reply); } state.Clear(); return(await sc.EndDialogAsync(true)); } catch (SkillException ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }
private async Task <DialogTurnResult> ShowAskParameterDetails(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); var options = sc.Options as ShowMeetingsDialogOptions; // this step will answer the question like: "when is my next meeting", next meeting is only one meeting will have answer if (state.ShowMeetingInfor.ShowingMeetings.Count == 1) { var askParameter = new AskParameterModel(state.ShowMeetingInfor.AskParameterContent); if (askParameter.NeedDetail) { var tokens = new StringDictionary() { { "EventName", state.ShowMeetingInfor.ShowingMeetings[0].Title }, { "EventStartDate", TimeConverter.ConvertUtcToUserTime(state.ShowMeetingInfor.ShowingMeetings[0].StartTime, state.GetUserTimeZone()).ToString(CalendarCommonStrings.DisplayDateLong) }, { "EventStartTime", TimeConverter.ConvertUtcToUserTime(state.ShowMeetingInfor.ShowingMeetings[0].StartTime, state.GetUserTimeZone()).ToString(CommonStrings.DisplayTime) }, { "EventEndTime", TimeConverter.ConvertUtcToUserTime(state.ShowMeetingInfor.ShowingMeetings[0].EndTime, state.GetUserTimeZone()).ToString(CommonStrings.DisplayTime) }, { "EventDuration", state.ShowMeetingInfor.ShowingMeetings[0].ToSpeechDurationString() }, { "EventLocation", state.ShowMeetingInfor.ShowingMeetings[0].Location }, }; await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.BeforeShowEventDetails, tokens)); if (askParameter.NeedTime) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadTime, tokens)); } if (askParameter.NeedDuration) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadDuration, tokens)); } if (askParameter.NeedLocation) { // for some event there might be no localtion. if (string.IsNullOrEmpty(tokens["EventLocation"])) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadNoLocation)); } else { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadLocation, tokens)); } } if (askParameter.NeedDate) { await sc.Context.SendActivityAsync(ResponseManager.GetResponse(SummaryResponses.ReadStartDate, tokens)); } } } return(await sc.NextAsync()); } catch (SkillException ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } catch (Exception ex) { await HandleDialogExceptions(sc, ex); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }