I have the following code:
public class MainDialog : ComponentDialog
{
protected readonly IConfiguration Configuration;
protected readonly ILogger Logger;
protected int counter = 0;
protected bool HaveToken = false;
protected static string Token = "";
public MainDialog(IConfiguration configuration, ILogger<MainDialog> logger)
: base(nameof(MainDialog))
{
//cache the config from appstettings.json for later usage in LUIS & QnAMaker.
Configuration = configuration;
Logger = logger;
AddDialog(new OAuthPrompt(
nameof(OAuthPrompt),
new OAuthPromptSettings
{
ConnectionName = Configuration["ConnectionName"],
Text = "Bitte melden sie sich an.",
Title = "Login",
Timeout = 3000,
}));
AddDialog(new TextPrompt(nameof(TextPrompt)));
//Adding Dialogs and giving the Dialogs the config info for the QnAMaker connection.
AddDialog(new HelpDialog(Configuration, logger));
AddDialog(new SpellingDialog(Configuration, logger));
AddDialog(new CreateTeamDialog(Configuration, logger));
AddDialog(new DIGASDialog(Configuration, logger));
AddDialog(new GreetingDialog(Configuration, logger));
AddDialog(new OnboardingDialog(Configuration, logger));
//AddDialog(new LoginDialog(Configuration, logger));
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
PromptStepAsync,
LoginStepAsync,
ProcessStepAsync,
IntroStepAsync,
ActStepAsync,
FinalStepAsync
}));
// The initial child Dialog to run.
InitialDialogId = nameof(WaterfallDialog);
}
private async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return await stepContext.BeginDialogAsync(nameof(OAuthPrompt),null, cancellationToken);
}
private async Task<DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if (HaveToken)
{
return await stepContext.NextAsync(cancellationToken);
}
if(stepContext.Result.GetType() == typeof(CancellationToken) )
{
return await stepContext.EndDialogAsync();
}
try
{
var tokenResponse = (TokenResponse)stepContext.Result;
Token = tokenResponse.Token;
HaveToken = true;
await stepContext.Context.SendActivityAsync(MessageFactory.Text("You are now logged in."), cancellationToken);
//await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Your token is: {tokenResponse.Token}"), cancellationToken);
//await OAuthhelper.ListMeAsync(stepContext.Context, tokenResponse);
return await stepContext.NextAsync(cancellationToken);
}
catch (Exception x)
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again. " + x.Message), cancellationToken);
return await stepContext.EndDialogAsync();
}
}
private async Task<DialogTurnResult> ProcessStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
if (HaveToken)
{
return await stepContext.NextAsync(cancellationToken);
}
if (stepContext.Result != null)
{
// We do not need to store the token in the bot. When we need the token we can
// send another prompt. If the token is valid the user will not need to log back in.
// The token will be available in the Result property of the task.
var tokenResponse = stepContext.Result as TokenResponse;
// If we have the token use the user is authenticated so we may use it to make API calls.
if (tokenResponse?.Token != null)
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Your token is: {tokenResponse.Token}"), cancellationToken);
}
}
else
{
await stepContext.Context.SendActivityAsync(MessageFactory.Text("We couldn't log you in. Please try again later."), cancellationToken);
}
return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
}
private async Task<DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return await stepContext.ContinueDialogAsync(cancellationToken);
}
private async Task<DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var intentDetails = new QueryDetails();
// Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.)
intentDetails = stepContext.Result != null
?
await LuisHelper.ExecuteLuisQuery(Configuration, Logger, stepContext.Context, cancellationToken)
:
new QueryDetails();
switch (intentDetails.Intent)
{
case "Hilfe":
return await stepContext.BeginDialogAsync(nameof(HelpDialog), intentDetails, cancellationToken);
case "Schreibweise_Ausdruck":
return await stepContext.BeginDialogAsync(nameof(SpellingDialog), intentDetails, cancellationToken);
case "Team_erstellen":
return await stepContext.BeginDialogAsync(nameof(CreateTeamDialog), intentDetails, cancellationToken);
case "DIGAS":
return await stepContext.BeginDialogAsync(nameof(DIGASDialog), intentDetails, cancellationToken);
case "Begrueßung":
return await stepContext.BeginDialogAsync(nameof(GreetingDialog), intentDetails, cancellationToken);
case "Onboarding":
return await stepContext.BeginDialogAsync(nameof(OnboardingDialog), intentDetails, cancellationToken);
default:
await stepContext.Context.SendActivityAsync("Das habe ich nicht verstanden.");
return await stepContext.BeginDialogAsync(nameof(HelpDialog), intentDetails, cancellationToken);
}
}
private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
//await stepContext.Context.SendActivityAsync(MessageFactory.Text("Vielen Dank."), cancellationToken);
return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
}
public static string getToken()
{
return Token;
}
}
After the Promptstep, the next step does not run until I give input. I more or less copied the AuthBot sample from Microsoft and modified it a little.
In the Promptstep the user authenticates himself, but after the prompt vanishes the Bot waits for more input instead of jumping to the next step.
The bot, where I copied the code from:
I could not test the sample, because it doesn't run on it's own. When I testet my bot in the Emulator with ngrok tunneling, the token was recieved but the bot just exits and waits for input.
Why is LoginStep not starting after the prompt?
