Right now, our users sign in every time they want to chat with our bot. It can be very annoying for them. Here's some information about the bot:
var userId = "dl_" + new Random().Next() + new DateTime().Ticks;
Here is the code to authenticate users:
public GreetingDialog(IConfiguration configuration, IBotTelemetryClient telemetryClient)
: base(INTENTS.GREETING, configuration["ConnectionName"])
{
TelemetryClient = telemetryClient;
AddDialog(new OAuthPrompt(
nameof(OAuthPrompt),
new OAuthPromptSettings
{
ConnectionName = ConnectionName,
Text = "👋 Welcome! Please Sign In.",
Title = "Sign In",
Timeout = 30000,
})
{
TelemetryClient = telemetryClient
});
AddDialog(new WaterfallDialog(INTENTS.GREETING, new WaterfallStep[] {
PromptStepAsync,
GreetStepAsync,
})
{
TelemetryClient = telemetryClient
});
InitialDialogId = INTENTS.GREETING;
}
private async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return await stepContext.BeginDialogAsync(nameof(OAuthPrompt), null, cancellationToken);
}
private async Task<DialogTurnResult> GreetStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
{
// ...
}
The problem is that every time you generate a user Id randomly, a new conversation is created. Being a new conversation, the bot cannot find the previous session.
If you want to do a test you can assign a static ID user:
var userId = "dl_123456789";
It shouldn't ask you to log in again.
To make a complete solution, the userId
should be tied to some distinctive credentials in your application (ex: username/password)