用户每次都要登录吗?

时间:2019-09-16 19:55:33

标签: botframework azure-bot-service direct-line-botframework

现在,我们的用户每次想与我们的机器人聊天时都登录。对于他们来说可能非常烦人。以下是有关该漫游器的一些信息:

  • 使用“直线”通道访问该机器人。
  • 当我在Azure中使用“在Web聊天中测试”功能时,每次都保持登录状态。所以在那里工作正常。
  • 我们在用户界面中使用BotFramework-WebChat组件。
  • 我跟随this tutorial生成了用户令牌。我生成了这样的用户ID:
    • var userId = "dl_" + new Random().Next() + new DateTime().Ticks;

以下是验证用户身份的代码:

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)
{ 
    // ...
}

1 个答案:

答案 0 :(得分:1)

问题在于,每次您随机生成用户ID时,都会创建一个新对话。该机器人是新会话,无法找到前一个会话。

如果要进行测试,可以分配一个静态ID用户:

var userId = "dl_123456789";

它不应该要求您再次登录。

要提供完整的解决方案,应将userId绑定到应用程序中的某些独特凭据(例如:用户名/密码)