private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Get the token from the previous step. Note that we could also have gotten the // token directly from the prompt itself. There is an example of this in the next method. var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse != null) { OnboardingState onboardingState = null; var virtualFriendState = await StateHelper .RetrieveFromStateAsync <ConversationState, DiscussionState>(_serviceProvider, stepContext.Context); virtualFriendState.UserToken = tokenResponse; try { var gh = new GraphHelper(tokenResponse.Token); var currentUser = await gh.GetMeAsync(); virtualFriendState.SignedInUserId = GenerateAuthenticatedUserId(currentUser); virtualFriendState.UpdateActivityFromId(stepContext.Context); onboardingState = await StateHelper .RetrieveFromStateAsync <UserState, OnboardingState>(_serviceProvider, stepContext.Context, true); if (String.IsNullOrEmpty(onboardingState.Name)) { onboardingState.Name = currentUser.GivenName; } onboardingState.SignedInUserId = virtualFriendState.SignedInUserId; await stepContext.Context.SendActivityAsync(MessageFactory.Text( $"Hi {onboardingState.Name}! You are now logged in."), cancellationToken); } catch (Exception ex) { await stepContext.Context.SendActivityAsync(MessageFactory.Text("You are now logged in."), cancellationToken); } await StateHelper.PersistInStateAsync <UserState, OnboardingState>( _serviceProvider, stepContext.Context, onboardingState, true); await StateHelper.PersistInStateAsync <ConversationState, DiscussionState>( _serviceProvider, stepContext.Context, virtualFriendState); return(await stepContext.EndDialogAsync(onboardingState)); } await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync()); }
private async Task <DialogTurnResult> SelectNotebookProcess(WaterfallStepContext stepContext, CancellationToken cancellationToken) { await PopulateStateObjects(stepContext); var notebooks = (List <Notebook>)stepContext.Values["Notebooks"]; var sectionId = String.Empty; AddUpdateStepContextValue(stepContext, "NotebookCreated", false); Notebook currentNotebook = new Notebook(); FoundChoice selected = stepContext.Result as FoundChoice; if (selected != null) { currentNotebook = notebooks.FirstOrDefault(n => n.DisplayName == selected.Value); } if (String.IsNullOrEmpty(currentNotebook.Id)) { // Try to find the notebook with the default name string notebookName = JournalHelper.DefaultNotebookName; currentNotebook = notebooks.FirstOrDefault(n => n.DisplayName == notebookName); if (currentNotebook == null) { // Get or create the notebook _graphHelper = new GraphHelper(_discussionState.UserToken.Token, true); currentNotebook = await _graphHelper.CreateNotebook(notebookName); AddUpdateStepContextValue(stepContext, "NotebookCreated", true); } } _onboardingState.Journal.NotebookId = currentNotebook.Id; await StateHelper.PersistInStateAsync <UserState, OnboardingState>( _serviceProvider, stepContext.Context, _onboardingState, true); AddUpdateStepContextValue(stepContext, "Notebook", currentNotebook); return(await stepContext.NextAsync(sectionId, cancellationToken)); }
protected async Task SaveOnboardingState(ITurnContext ctx) { await StateHelper.PersistInStateAsync <UserState, OnboardingState>( _serviceProvider, ctx, _onboardingState, true); }