// Handles conversation cleanup. private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await _stateAccessor.GetAsync(stepContext.Context, () => new PointOfInterestSkillState(), cancellationToken); bool shouldInterrupt = stepContext.Context.TurnState.ContainsKey(StateProperties.InterruptKey); if (stepContext.Context.IsSkill() && !shouldInterrupt) { var result = stepContext.Result; if (state.IsAction && result == null) { result = new SingleDestinationResponse { ActionSuccess = false }; } state.Clear(); return(await stepContext.EndDialogAsync(result, cancellationToken)); } else { state.Clear(); return(await stepContext.ReplaceDialogAsync(InitialDialogId, _templateManager.GenerateActivity(POIMainResponses.CompletedMessage), cancellationToken)); } }
protected SingleDestinationResponse ConvertToResponse(PointOfInterestModel model) { var response = new SingleDestinationResponse(); response.ActionSuccess = true; response.Name = model.Name; response.Latitude = model.Geolocation.Latitude; response.Longitude = model.Geolocation.Longitude; response.Telephone = model.Phone; response.Address = model.Address; return(response); }
protected async Task <DialogTurnResult> ProcessPointOfInterestActionAsync(WaterfallStepContext sc, CancellationToken cancellationToken) { var state = await Accessor.GetAsync(sc.Context, () => new PointOfInterestSkillState(), cancellationToken); bool shouldInterrupt = sc.Context.TurnState.ContainsKey(StateProperties.InterruptKey); if (shouldInterrupt) { return(await sc.CancelAllDialogsAsync(cancellationToken)); } var choice = sc.Result as FoundChoice; int choiceIndex = choice.Index; if (choiceIndex == SpecialChoices.GoBack) { return(await sc.ReplaceDialogAsync(GoBackDialogId, null, cancellationToken)); } SingleDestinationResponse response = null; // TODO skip call button if (string.IsNullOrEmpty(state.Destination.Phone)) { choiceIndex += 1; } if (choiceIndex == 0) { if (SupportOpenDefaultAppReply(sc.Context)) { await sc.Context.SendActivityAsync(CreateOpenDefaultAppReply(sc.Context.Activity, state.Destination, OpenDefaultAppType.Telephone), cancellationToken); } response = state.IsAction ? ConvertToResponse(state.Destination) : null; } else if (choiceIndex == 1) { return(await sc.ReplaceDialogAsync(nameof(RouteDialog), cancellationToken : cancellationToken)); } else if (choiceIndex == 2) { if (SupportOpenDefaultAppReply(sc.Context)) { await sc.Context.SendActivityAsync(CreateOpenDefaultAppReply(sc.Context.Activity, state.Destination, OpenDefaultAppType.Map), cancellationToken); } response = state.IsAction ? ConvertToResponse(state.Destination) : null; } return(await sc.NextAsync(response, cancellationToken)); }
public async Task <DialogTurnResult> ResponseToStartRoutePromptAsync(WaterfallStepContext sc, CancellationToken cancellationToken) { try { var state = await Accessor.GetAsync(sc.Context, () => new PointOfInterestSkillState(), cancellationToken); SingleDestinationResponse response = null; if (sc.Result is bool && (bool)sc.Result) { // TODO do not care multiple routes var activeRoute = state.FoundRoutes[0]; if (activeRoute != null) { state.ActiveRoute = activeRoute; state.FoundRoutes = null; } if (SupportOpenDefaultAppReply(sc.Context)) { await sc.Context.SendActivityAsync(CreateOpenDefaultAppReply(sc.Context.Activity, state.Destination, OpenDefaultAppType.Map), cancellationToken); } response = state.IsAction ? ConvertToResponse(state.Destination) : null; } else { var replyMessage = TemplateManager.GenerateActivity(RouteResponses.AskAboutRouteLater); await sc.Context.SendActivityAsync(replyMessage, cancellationToken); } return(await sc.EndDialogAsync(response, cancellationToken)); } catch (Exception ex) { await HandleDialogExceptionsAsync(sc, ex, cancellationToken); return(new DialogTurnResult(DialogTurnStatus.Cancelled, CommonUtil.DialogTurnResultCancelAllDialogs)); } }