在 MS BOT 框架中启用 Directline

Enable Directline in MS BOT Framework

1) 我为我的客户端应用程序创建了一个 REST API 并在 API 管理中注册(用于获取用户特定数据)

2) 我使用 LUIS 在 Azure 门户中创建了一个 BOT WEB APP,它工作正常(我添加了示例 Intents/Utterance)

3) 在 LUIS 应用程序中使用 REST API 作为 Intent 条件之一 还在 BOT 模拟器和 Azure 门户中测试了以上内容。 (在调用函数中硬编码用户信息)

现在我想在我的 MVC 客户端应用程序中配置 BOT,并根据登录的用户信息传递用户特定信息。我阅读了以下文章以启用直线 API。仍在寻找更好的资源。

Connect BOT using Directline API

DirectLine Auth

所以基本上你的问题是关于在网络应用程序中实现机器人界面。一种选择是使用网络聊天作为渠道:https://github.com/Microsoft/BotFramework-WebChat.

开源 Web 聊天控件使用 Direct Line API 与您的 bot 通信,这允许在客户端和 bot 之间来回发送消息。您只需添加文档中提到的 <iframe> 标签即可将其嵌入到您的网络应用程序中。也可以在此处查看更多信息:https://docs.microsoft.com/en-us/bot-framework/bot-service-design-pattern-embed-web-site

否则如您所说,使用直线 API 并在您的 MVC 客户端应用程序中为此 API 实现一个网络层。这将负责构建消息并将其发送到机器人 API,并接收它们并将其用于相应的 UI 需求。我个人建议您使用 WebSockets 协议,以便在您的机器人之间建立双向通信并避免进行 HTTP 长轮询。在这里查看:https://docs.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-direct-line-3-0-concepts

Now I want to configure the BOT in my MVC client application and pass the user specific info based on the logged in user info.

我正在使用以下代码示例在我的网站中嵌入 bot 并将用户特定信息传递给 bot,这对我有用,您可以参考。

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Test</title>
    <link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
    <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
</head>
<body>
    <div> 
        <div id="mybot"/>
    </div>
</body>
</html>
<script>
    BotChat.App({
        directLine: { secret: '{your_directline_secret}' },
        //you can dynamically retrieve the logged in user info in your mvc View
        //and pass thoes info to your bot
        user: { id: '1234', firstname: '{your_fname}', lastname: '{your_lname}'},
        bot: { id: '{your_botid}' },
        resize: 'detect'
    }, document.getElementById("mybot"))
</script>

测试结果:

使用以下代码片段从机器人应用程序的 Activity 对象中提取用户信息。

if (activity.From.Properties["firstname"] != null)
{
    var fname = activity.From.Properties["firstname"].ToString();
}