/// <summary> /// This method makes descision based upon the actual command received from the user. /// </summary> /// <param name="turnContext"></param> /// <param name="cancellationToken"></param> /// <returns></returns> private async Task <DialogContext> ProcessCommandsAsync(ITurnContext turnContext, CancellationToken cancellationToken) { //Create the dialog context for the current turn var dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken); string adaptiveCardData; string command = turnContext.Activity.Text; // Based upon the parse command different logic will be called to construct the reply activities switch (command) { case "logoff": case "signoff": case "signout": case "logout": var botAdapter = turnContext.Adapter as BotFrameworkAdapter; //Signout and cancel the token saved in the Azure Bot Service await botAdapter.SignOutUserAsync(turnContext, Constants.OAuthConnectionName, cancellationToken : cancellationToken); //Tell the user that they are signed out adaptiveCardData = string.Format(Constants.AdaptiveCardPath, Constants.AdaptiveCards.SignOutMessage.ToString()); await turnContext.SendActivityAsync(DialogHelpers.CreateReply(turnContext, adaptiveCardData, true), cancellationToken); //end the dialog as the user is signed out. A new login will begin the new dialog. await dc.EndDialogAsync(Constants.RootDialogName, cancellationToken); await _accessors.ApplicationState.DeleteAsync(turnContext, cancellationToken : cancellationToken); await _accessors.HostState.DeleteAsync(turnContext, cancellationToken); await _accessors.OrchestrationState.DeleteAsync(turnContext, cancellationToken); await _accessors.SendPortState.DeleteAsync(turnContext, cancellationToken); await _accessors.FeedbackState.DeleteAsync(turnContext, cancellationToken); List <string> reports = await _accessors.Reports.GetAsync(turnContext, () => new List <string>(), cancellationToken); await _accessors.Reports.DeleteAsync(turnContext, cancellationToken : cancellationToken); await _accessors.UserState.SaveChangesAsync(turnContext, cancellationToken : cancellationToken); //If Get Suspended/Tracked Instances operation was run, delete the blobs in the storage account if (reports.Count() > 0) { BlobHelper blobHelper = new BlobHelper(_configuration); foreach (string report in reports) { await blobHelper.DeleteReportBlobAsync(report); } } break; case "help": adaptiveCardData = string.Format(Constants.AdaptiveCardPath, Constants.AdaptiveCards.HelpMessage.ToString()); await turnContext.SendActivityAsync(DialogHelpers.CreateReply(turnContext, adaptiveCardData, true), cancellationToken); break; default: await dc.ContinueDialogAsync(cancellationToken); if (!turnContext.Responded) { await dc.BeginDialogAsync(Constants.RootDialogName, cancellationToken : cancellationToken); } break; } return(dc); }