private async Task <DialogTurnResult> ShowNextMeeting(WaterfallStepContext sc, CancellationToken cancellationToken = default(CancellationToken)) { try { var state = await Accessor.GetAsync(sc.Context); // if only one next meeting, show the meeting detail card, otherwise show a meeting list card if (state.ShowMeetingInfo.ShowingMeetings.Count == 1) { var speakParams = new { EventName = state.ShowMeetingInfo.ShowingMeetings[0].Title, PeopleCount = state.ShowMeetingInfo.ShowingMeetings[0].Attendees.Count.ToString(), EventTime = SpeakHelper.ToSpeechMeetingDateTime( TimeConverter.ConvertUtcToUserTime(state.ShowMeetingInfo.ShowingMeetings[0].StartTime, state.GetUserTimeZone()), state.ShowMeetingInfo.ShowingMeetings[0].IsAllDay == true), Location = state.ShowMeetingInfo.ShowingMeetings[0].Location ?? string.Empty }; if (string.IsNullOrEmpty(state.ShowMeetingInfo.ShowingMeetings[0].Location)) { var activity = TemplateEngine.GenerateActivityForLocale(SummaryResponses.ShowNextMeetingNoLocationMessage, speakParams); await sc.Context.SendActivityAsync(activity); } else { var activity = TemplateEngine.GenerateActivityForLocale(SummaryResponses.ShowNextMeetingMessage, speakParams); await sc.Context.SendActivityAsync(activity); } } else { var activity = TemplateEngine.GenerateActivityForLocale(SummaryResponses.ShowMultipleNextMeetingMessage); await sc.Context.SendActivityAsync(activity); } state.ShowMeetingInfo.ShowingCardTitle = CalendarCommonStrings.UpcommingMeeting; var reply = await GetGeneralMeetingListResponseAsync(sc, state, true); await sc.Context.SendActivityAsync(reply); state.Clear(); return(await sc.EndDialogAsync()); } 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)); } }
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)); } }