本文介绍了如何以编程方式获取Microsoft Bot Framework聊天机器人应用程序的DirectLine机密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Microsoft Bot Framework Azure Bot Service 自动创建和部署chatbot应用程序.

我有一个与我的服务相关的自定义模板,我只需要为要部署的每个聊天机器人自定义 Web.config 文件.我还想使用 default.htm 主持一个基本的Web聊天,该聊天使用已部署的聊天机器人的 DirectLine 机密.

我能够使用 Azure CLI 2.0 创建一个 WebApp聊天机器人应用程序,并将该聊天机器人与 DirectLine 频道集成在一起.但是,我无法使用Azure CLI 2.0获取DirectLine密钥.

我按照以下说明将通过 CLI 创建的聊天机器人与 DirectLine 频道进行了集成:

  az bot直线创建--name-资源组[--add-disabled {false,true}][--disablev1 {false,true}][--disablev3 {false,true}][--site-name] 

但是,当我使用show命令时,并没有在 default.htm 文件中获得添加到网络聊天中的秘密:

  az bot直线显示--name-资源组 

我可以使用 Azure CLI .NET SDK 实现此目的吗?我正在使用 Azure CLI 进行测试,但最后我想使用 .NET SDK ,以便创建一个可创建聊天机器人的REST Web服务(基于我的自定义模板),然后将URL返回给调用方.当呼叫者转到URL时,我希望 default.htm 托管网络聊天.

解决方案

根据我的测试,命令 az bot Directline show 将发出以下请求以检索有关Directline频道的详细信息.

 获取https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resourcegroup_name}/providers/Microsoft.BotService/botServices/{bot_id}/channels/DirectLineChannel?api-version = 2017-12-01 

但是在通过 GET 返回的响应中, key key2 始终为null.

要在az bot cli中返回/获取 key key2 ,我们可以使用create命令:

  az bot直线创建--name MyBotName --resource-group MyResourceGroup --site-name site2 

此外,要管理.NET应用程序中的botservice,您可以尝试使用

示例请求正文:

注意:

Microsoft.Azure.Management.BotService.Models.DirectLineSite ,我们可以找到: 获取主(次)键.值仅通过POST返回到操作频道列表API,否则为空 .

 ////概括://获取主键.仅通过POST返回值到操作通道列表//API,否则为空.[JsonProperty(PropertyName ="key")]公共字符串Key {get;}////概括://获取辅助密钥.仅通过POST返回值到操作通道列表//API,否则为空.[JsonProperty(PropertyName ="key2")]公共字符串Key2 {get;} 

I'm trying to automate the process of creation and deploy of chatbot applications using the Microsoft Bot Framework and the Azure Bot Service.

I have a custom template that speaks to a service of mine, and I just need to customize the Web.config file for each chatbot to be deployed. I also want to use the default.htm to host a basic web chat that uses the DirectLine secret of the deployed chatbot.

I was able to create a WebApp Chatbot application using the Azure CLI 2.0, as well as integrate that chatbot with the DirectLine channel. However I wasn't able to get the DirectLine key using the Azure CLI 2.0.

I used the following instructions to integrated the chatbot I created via CLI with the DirectLine channel:

az bot directline create --name
                         --resource-group
                         [--add-disabled {false, true}]
                         [--disablev1 {false, true}]
                         [--disablev3 {false, true}]
                         [--site-name]

However when I use the show command I don't get the secret that I need to add to the web chat in the default.htm file:

az bot directline show --name
                       --resource-group

Can I achieve this using the Azure CLI or the .NET SDK? I'm using the Azure CLI for testing, but in the end I want to go with the .NET SDK in order to create a REST web service that creates the chatbot (based on my custom template) and returns the URL to the caller. When the caller goes to the URL I want the default.htm to be hosting the webchat.

解决方案

Based on my test, the command az bot directline show would make the following request to retrieve details about directline channel.

GET https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resourcegroup_name}/providers/Microsoft.BotService/botServices
/{bot_id}/channels/DirectLineChannel?api-version=2017-12-01

But the key and key2 always be null in the returned response through GET.

To return/get the key and key2 in az bot cli, we can use create command:

az bot directline create --name MyBotName  --resource-group MyResourceGroup --site-name site2

Besides, to manage botservice in .NET application, you can try to use Microsoft Azure Management Bot Service Library.

And you can also use Azure management api in your .NET application to retrieve the directline secret keys of botservice. The following example request is for your reference.

Example request body:

Note:

In Microsoft.Azure.Management.BotService.Models.DirectLineSite, we can find: Gets primary (secondary) key. Value only returned through POST to the action Channel List API, otherwise empty.

    //
    // Summary:
    //     Gets primary key. Value only returned through POST to the action Channel List
    //     API, otherwise empty.
    [JsonProperty(PropertyName = "key")]
    public string Key { get; }
    //
    // Summary:
    //     Gets secondary key. Value only returned through POST to the action Channel List
    //     API, otherwise empty.
    [JsonProperty(PropertyName = "key2")]
    public string Key2 { get; }

这篇关于如何以编程方式获取Microsoft Bot Framework聊天机器人应用程序的DirectLine机密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:02