Bot DirectLine 令牌分发问题

Bot DirectLine Token Distribute Issue

基于此Bot DirectLine Authentication

If you plan to distribute the token to clients and want them to initiate the conversation, use the Generate Token operation.

这是否意味着我们可以使用 Secret 从后端生成令牌并将令牌分发给客户端以启动对话?

为了测试它,我写了这些:

Backend: @Azure Function

  [FunctionName("XXXXX")]
    public static async Task<object> RunAsync([HttpTrigger(Route = "XXXXX")] HttpRequestMessage req, TraceWriter log)
    {
        log.Info($"Webhook was triggered!");

        var tokenResponse = await new DirectLineClient(directLineSecret).Tokens.GenerateTokenForNewConversationAsync();
        return req.CreateResponse(HttpStatusCode.OK, tokenResponse.Token);
    }

Client @UWP
// token from Backend
directLineClient = new DirectLineClient(token);
var conversation = directLineClient.Conversations.StartConversation();

奇怪的是变量 conversation 为空。

当我将后端的生成令牌代码放入客户端时,变量 conversation 是一个有效的对象。

我的问题是:我们可以将生成令牌放在后端并将令牌分发给客户吗?

my question is: can we put the Generate Token in backend and distribute token to clients?

当然,如果你不想expose/share公开直线秘密,你可以在后台服务中生成Token并将token分发给客户端,让他们发起对话。

注意:当您在 DirectLine 客户端中使用它时,请确保您的 http 触发函数生成的 Direct Line 令牌没有过期。

我使用 Direct Line Bot Sample 的 DirectLineClient 进行测试,并修改代码以接受 Direct Line 令牌。如果我提供已过期的 Direct Line 令牌,开始对话将失败。

问题是后端应该 return 标记为文本媒体类型。非常感谢您的反馈和提醒。

 return req.CreateResponse(HttpStatusCode.OK, tokenResponse.Token, "text/plain");