Botframework 如何使用AZURE服务在网站中创建聊天机器人?

Botframework 如何使用AZURE服务在网站中创建聊天机器人?,botframework,chatbot,direct-line-botframework,Botframework,Chatbot,Direct Line Botframework,对于创建一个Bot,只要登录到azure并创建一个Bot,但是而不是登录到那里,有没有一种方法可以从网站创建它,只需使用API引用传递所需参数?有两种方法可以将聊天机器人嵌入网站 用于web界面 获取cdn链接或下载webchat 使用直连令牌初始化聊天(如果您使用uze Azure Bot服务,您可以获得它) window.BotChat.App({ directLine:{secret:'DIRECT_LINE_secret'}, 用户:{id:'boost7'}, bot:{id:'

对于
创建一个Bot
,只要
登录到azure并创建一个Bot,但是
而不是登录到那里,有没有一种方法可以从
网站
创建它,只需使用
API
引用传递
所需参数

有两种方法可以将聊天机器人嵌入网站

  • 用于web界面
    • 获取cdn链接或下载webchat
    • 使用直连令牌初始化聊天(如果您使用uze Azure Bot服务,您可以获得它)
  • window.BotChat.App({
    directLine:{secret:'DIRECT_LINE_secret'},
    用户:{id:'boost7'},
    bot:{id:'boost7演示bot'},
    调整大小:“检测”
    
    },document.getElementById(“div_id”)有两种方法可以将聊天机器人嵌入网站

  • 用于web界面
    • 获取cdn链接或下载webchat
    • 使用直连令牌初始化聊天(如果您使用uze Azure Bot服务,您可以获得它)
  • window.BotChat.App({
    directLine:{secret:'DIRECT_LINE_secret'},
    用户:{id:'boost7'},
    bot:{id:'boost7演示bot'},
    调整大小:“检测”
    },document.getElementById(“div_id”)
    
    对于创建一个Bot,无论它在哪里都会登录到azure并创建一个Bot,但是有没有一种方法可以通过使用API引用传递所需的参数从网站创建它,而不是登录到那里

    如果您希望以编程方式创建而不是登录Azure portal并在门户上手动创建它,您可以尝试使用来实现它。以下用于部署资源的代码仅供参考

    DeploymentHelper.cs:

    // Requires the following Azure NuGet packages and related dependencies:
    // package id="Microsoft.Azure.Management.Authorization" version="2.0.0"
    // package id="Microsoft.Azure.Management.ResourceManager" version="1.4.0-preview"
    // package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.8-preview"
    
    using Microsoft.Azure.Management.ResourceManager;
    using Microsoft.Azure.Management.ResourceManager.Models;
    using Microsoft.Rest.Azure.Authentication;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System;
    using System.IO;
    
    namespace PortalGenerated
    {
        /// <summary>
        /// This is a helper class for deploying an Azure Resource Manager template
        /// More info about template deployments can be found here https://go.microsoft.com/fwLink/?LinkID=733371
        /// </summary>
        class DeploymentHelper
        {
            string subscriptionId = "your-subscription-id";
            string clientId = "your-service-principal-clientId";
            string clientSecret = "your-service-principal-client-secret";
            string resourceGroupName = "resource-group-name";
            string deploymentName = "deployment-name";
            string resourceGroupLocation = "resource-group-location"; // must be specified for creating a new resource group
            string pathToTemplateFile = "path-to-template.json-on-disk";
            string pathToParameterFile = "path-to-parameters.json-on-disk";
            string tenantId = "tenant-id";
    
            public async void Run()
            {
                // Try to obtain the service credentials
                var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);
    
                // Read the template and parameter file contents
                JObject templateFileContents = GetJsonFileContents(pathToTemplateFile);
                JObject parameterFileContents = GetJsonFileContents(pathToParameterFile);
    
                // Create the resource manager client
                var resourceManagementClient = new ResourceManagementClient(serviceCreds);
                resourceManagementClient.SubscriptionId = subscriptionId;
    
                // Create or check that resource group exists
                EnsureResourceGroupExists(resourceManagementClient, resourceGroupName, resourceGroupLocation);
    
                // Start a deployment
                DeployTemplate(resourceManagementClient, resourceGroupName, deploymentName, templateFileContents, parameterFileContents);
            }
    
            /// <summary>
            /// Reads a JSON file from the specified path
            /// </summary>
            /// <param name="pathToJson">The full path to the JSON file</param>
            /// <returns>The JSON file contents</returns>
            private JObject GetJsonFileContents(string pathToJson)
            {
                JObject templatefileContent = new JObject();
                using (StreamReader file = File.OpenText(pathToJson))
                {
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        templatefileContent = (JObject)JToken.ReadFrom(reader);
                        return templatefileContent;
                    }
                }
            }
    
            /// <summary>
            /// Ensures that a resource group with the specified name exists. If it does not, will attempt to create one.
            /// </summary>
            /// <param name="resourceManagementClient">The resource manager client.</param>
            /// <param name="resourceGroupName">The name of the resource group.</param>
            /// <param name="resourceGroupLocation">The resource group location. Required when creating a new resource group.</param>
            private static void EnsureResourceGroupExists(ResourceManagementClient resourceManagementClient, string resourceGroupName, string resourceGroupLocation)
            {
                if (resourceManagementClient.ResourceGroups.CheckExistence(resourceGroupName) != true)
                {
                    Console.WriteLine(string.Format("Creating resource group '{0}' in location '{1}'", resourceGroupName, resourceGroupLocation));
                    var resourceGroup = new ResourceGroup();
                    resourceGroup.Location = resourceGroupLocation;
                    resourceManagementClient.ResourceGroups.CreateOrUpdate(resourceGroupName, resourceGroup);
                }
                else
                {
                    Console.WriteLine(string.Format("Using existing resource group '{0}'", resourceGroupName));
                }
            }
    
            /// <summary>
            /// Starts a template deployment.
            /// </summary>
            /// <param name="resourceManagementClient">The resource manager client.</param>
            /// <param name="resourceGroupName">The name of the resource group.</param>
            /// <param name="deploymentName">The name of the deployment.</param>
            /// <param name="templateFileContents">The template file contents.</param>
            /// <param name="parameterFileContents">The parameter file contents.</param>
            private static void DeployTemplate(ResourceManagementClient resourceManagementClient, string resourceGroupName, string deploymentName, JObject templateFileContents, JObject parameterFileContents)
            {
                Console.WriteLine(string.Format("Starting template deployment '{0}' in resource group '{1}'", deploymentName, resourceGroupName));
                var deployment = new Deployment();
    
                deployment.Properties = new DeploymentProperties
                {
                    Mode = DeploymentMode.Incremental,
                    Template = templateFileContents,
                    Parameters = parameterFileContents["parameters"].ToObject<JObject>()
                };
    
                var deploymentResult = resourceManagementClient.Deployments.CreateOrUpdate(resourceGroupName, deploymentName, deployment);
                Console.WriteLine(string.Format("Deployment status: {0}", deploymentResult.Properties.ProvisioningState));
            }
        }
    }
    
    //需要以下Azure NuGet软件包和相关依赖项:
    //软件包id=“Microsoft.Azure.Management.Authorization”version=“2.0.0”
    //package id=“Microsoft.Azure.Management.ResourceManager”version=“1.4.0-preview”
    //package id=“Microsoft.Rest.ClientRuntime.Azure.Authentication”version=“2.2.8-preview”
    使用Microsoft.Azure.Management.ResourceManager;
    使用Microsoft.Azure.Management.ResourceManager.Models;
    使用Microsoft.Rest.Azure.Authentication;
    使用Newtonsoft.Json;
    使用Newtonsoft.Json.Linq;
    使用制度;
    使用System.IO;
    命名空间PortalGenerated
    {
    /// 
    ///这是用于部署Azure资源管理器模板的帮助器类
    ///有关模板部署的更多信息,请参见此处https://go.microsoft.com/fwLink/?LinkID=733371
    /// 
    类DeploymentHelper
    {
    string subscriptionId=“您的订阅id”;
    string clientId=“您的服务主体clientId”;
    string clientSecret=“您的服务主体客户端密码”;
    字符串resourceGroupName=“资源组名称”;
    string deploymentName=“部署名称”;
    必须指定字符串resourceGroupLocation=“resource group location”;//才能创建新的资源组
    string pathToTemplateFile=“磁盘上模板.json的路径”;
    string pathToParameterFile=“磁盘上parameters.json的路径”;
    字符串tenantId=“租户id”;
    公共异步无效运行()
    {
    //尝试获取服务凭据
    var serviceCreds=wait ApplicationTokenProvider.LoginSilentAsync(tenantId、clientId、clientSecret);
    //读取模板和参数文件内容
    JObject templateFileContents=GetJsonFileContents(pathToTemplateFile);
    JObject参数filecontents=GetJsonFileContents(pathToParameterFile);
    //创建资源管理器客户端
    var resourceManagementClient=新的resourceManagementClient(serviceCreds);
    resourceManagementClient.SubscriptionId=SubscriptionId;
    //创建或检查资源组是否存在
    确保资源组存在(resourceManagementClient、resourceGroupName、resourceGroupLocation);
    //开始部署
    DeployTemplate(resourceManagementClient、resourceGroupName、deploymentName、templateFileContents、parameterFileContents);
    }
    /// 
    ///从指定路径读取JSON文件
    /// 
    ///JSON文件的完整路径
    ///JSON文件的内容
    私有JObject GetJsonFileContents(字符串pathToJson)
    {
    JObject templatefileContent=新JObject();
    使用(StreamReader file=file.OpenText(pathToJson))
    {
    使用(JsonTextReader=newjsontextreader(文件))
    {
    templatefileContent=(JObject)JToken.ReadFrom(reader);
    返回templatefileContent;
    }
    }
    }
    /// 
    ///确保具有指定名称的资源组存在。如果不存在,将尝试创建一个。
    /// 
    ///资源管理器客户端。
    ///资源组的名称。
    ///资源组位置。创建新资源组时必需。
    私有静态void确保资源组存在(ResourceManagementClient ResourceManagementClient,string resourceGroupName,string resourceGroupLocation)
    {
    if(resourceManagementClient.ResourceGroups.CheckExistence(resourceGroupName)!=true)
    {
    WriteLine(string.Format(“在位置“{1}”中创建资源组“{0}”,resourceGroupName,resourceGroupLocation));
    var resourceGroup=new resourceGroup();
    resourceGroup.Location=resourceGroupLocation;
    resourceManagementClient.ResourceGroups.CreateOrUpdate(resourceGroupName,resourceGroup);
    }
    其他的
    {
    WriteLine(string.Format(“使用现有资源组“{0}”,resourceGroupName));