您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure 机器人服务创建机器人Create a bot with Azure Bot Service

适用范围:yesSDK v4 noSDK v3 APPLIES TO: yesSDK v4 no SDK v3

Azure 机器人服务提供了用于创建机器人的核心组件,包括用于开发机器人的 Bot Framework SDK 以及用于将机器人连接到通道的机器人服务。Azure Bot Service provides the core components for creating bots, including the Bot Framework SDK for developing bots and the bot service for connecting bots to channels. 在本主题中,还可以选择 .NET 或 Node.js 模板,以便使用 Bot Framework SDK v4 创建机器人。In the topic, you'll be able to choose either .NET or Node.js template to create a bot using the Bot Framework SDK v4.

备注

所创建的机器人会自动注册到 Azure 机器人服务。The bot you create is automatically registered with the Azure Bot Service. 如果已在其他位置托管了机器人,而你希望将它注册,请参阅文章:使用 Azure 机器人服务注册机器人If you already have a bot hosted elsewhere and you want to register it, see the article: Register a bot with Azure Bot Service.

通过 Azure 机器人服务创建机器人和在本地创建机器人是创建机器人时使用的两种独立的并行方式。Creating a bot with Azure Bot Service and creating a bot locally are independent, parallel ways to create a bot.

先决条件Prerequisites

创建新的机器人服务Create a new bot service

  1. 登录到 Azure 门户Log in to the Azure portal.
  2. 在 Azure 门户左上角单击“创建新资源”链接,然后选择“AI + 机器学习” > “Web 应用机器人”。 Click Create new resource link found on the upper left-hand corner of the Azure portal, then select AI + Machine Learning > Web App bot.

创建机器人

  1. 此时会打开一个新的边栏选项卡,其中包含有关 Web 应用机器人的信息。 A new blade will open with information about the Web App Bot.

  2. 在“机器人服务”边栏选项卡中,提供有关机器人的请求信息,如图片下方的表中所示 。In the Bot Service blade, provide the requested information about your bot as specified in the table below the image.
    “创建 Web 应用机器人”边栏选项卡Create Web App Bot blade

设置Setting 建议的值Suggested value 说明Description
机器人名称Bot name 机器人的显示名称Your bot's display name 通道和目录中显示的机器人的显示名称。The display name for the bot that appears in channels and directories. 此名称可随时更改。This name can be changed at anytime.
订阅Subscription 订阅Your subscription 选择要使用的 Azure 订阅。Select the Azure subscription you want to use.
资源组Resource Group myResourceGroupmyResourceGroup 可创建新的资源组或从现有资源组中选择。You can create a new resource group or choose from an existing one.
位置Location 默认位置The default location 选择资源组的地理位置。Select the geographic location for your resource group. 选择的位置可以是列出的任何位置,但通常情况下,最好选择最靠近客户的位置。Your location choice can be any location listed, though it's often best to choose a location closest to your customer. 创建机器人后无法更改位置。The location cannot be changed once the bot is created.
定价层Pricing tier F0F0 选择定价层。Select a pricing tier. 可随时更新定价层。You may update the pricing tier at any time. 有关详细信息,请参阅机器人服务定价For more information, see Bot Service pricing.
应用名称App name 唯一的名称A unique name 机器人的唯一 URL 名称。The unique URL name of the bot. 例如,如果将机器人命名为 myawesomebot,则机器人的 URL 为 http://myawesomebot.azurewebsites.netFor example, if you name your bot myawesomebot, then your bot's URL will be http://myawesomebot.azurewebsites.net. 名称只能使用字母数字和下划线字符。The name must use alphanumeric and underscore characters only. 此字段的限制为 35 个字符。There is a 35 character limit to this field. 创建机器人后无法更改应用名称。The App name cannot be changed once the bot is created.
机器人模板Bot template 回显机器人Echo bot 选择“SDK v4”。 Choose SDK v4. 为本快速入门选择 C# 或 Node.js,然后单击“选择”。 Select either C# or Node.js for this quickstart, then click Select.
应用服务计划/位置App service plan/Location 你的应用服务计划Your app service plan 选择应用服务计划位置。Select an app service plan location. 选择的位置可以是列出的任何位置,但通常情况下,最好选择机器人服务所在的位置。Your location choice can be any location listed, though it's often best to choose the same location as the bot service.
LUIS 帐户仅适用于“基本机器人”模板 LUIS Accounts Only available for Basic Bot template LUIS Azure 资源名称LUIS Azure Resource Name 将 LUIS 资源迁移到 Azure 资源以后,请输入 Azure 资源名称,以便将此 LUIS 应用程序与该 Azure 资源相关联。After migrating LUIS Resources over to an Azure Resource, input the Azure Resource name to associate this LUIS Application with that Azure Resource.
Application InsightsApplication Insights 启用On 决定要启用还是关闭 Application InsightsDecide if you want to turn Application Insights On or Off. 如果选择“启用”,还必须指定区域位置 。If you select On, you must also specify a regional location. 选择的位置可以是列出的任何位置,但通常情况下,最好选择机器人服务所在的位置。Your location choice can be any location listed, though it's often best to choose the same location as the bot service.
Microsoft 应用 ID 和密码Microsoft App ID and password 自动创建应用 ID 和密码Auto create App ID and password 如果需要手动输入 Microsoft 应用 ID 和密码,请使用此选项。Use this option if you need to manually enter a Microsoft App ID and password. 否则,在机器人创建过程中系统会为你创建新的 Microsoft 应用 ID 和密码。Otherwise, a new Microsoft App ID and password will be created for you in the bot creation process. 为机器人服务手动创建应用注册时,请确保将支持的帐户类型设置为“任何组织目录中的帐户”或“任何组织目录中的帐户和个人 Microsoft 帐户(例如,Outlook.com、Xbox 等)”When creating an app registration manually for the Bot Service, please ensure that the supported account types is set to ‘Accounts in any organizational directory’ or ‘Accounts in any organizational directory and personal Microsoft accounts (e.g. Outlook.com, Xbox, etc.)’
  1. 单击“创建”创建服务并将机器人部署到云。 Click Create to create the service and deploy the bot to the cloud. 此过程可能需要数分钟。This process may take several minutes.

查看“通知”,确认已部署机器人 。Confirm that the bot has been deployed by checking the Notifications. 通知将从“正在进行部署...”更改为“部署已成功” 。The notifications will change from Deployment in progress... to Deployment succeeded. 单击“转到资源”按钮,打开机器人的资源边栏选项卡 。Click Go to resource button to open the bot's resources blade.

创建机器人后,即可通过网上聊天测试它。Now that your bot is created, test it in Web Chat.

测试机器人Test the bot

在“机器人管理”部分中,单击“通过网上聊天执行测试” 。In the Bot Management section, click Test in Web Chat. Azure 机器人服务将加载网上聊天控件,并连接到机器人。Azure Bot Service will load the Web Chat control and connect to your bot.

Azure 网上聊天测试

输入一条信息,机器人就会响应。Enter a message and your bot should respond.

手动应用注册Manual app registration

对于下面这样的情况,需手动注册:A manual registration is necessary for situations like:

  • 你无法在组织中注册,需要另一方为你正在构建的机器人创建应用 ID。You are unable to make the registrations in your organization and need another party to create the App ID for the bot you're building.
  • 你需要手动创建自己的应用 ID(和密码)。You need to manually create your own app ID (and password).

请参阅常见问题解答 - 应用注册See FAQ - App Registration.

下载代码Download code

可以下载代码以在本地进行处理。You can download the code to work on it locally.

  1. 在“机器人管理”部分中,单击“生成” 。In the Bot Management section, click Build.
  2. 单击右窗格中的“下载机器人源代码” 链接。Click on Download Bot source code link in the right-pane.
  3. 按照提示下载代码,然后解压缩该文件夹。Follow the prompts to download the code, and then unzip the folder.
    1. 下载机器人时,可以选择为下载的机器人提供设置(包含密钥和机密),这可能是机器人正常工作所必需的。When downloading your bot, you will be given the option to include the settings (containing the keys and secrets) for your bot in your download, which may be necessary for your bot to work. 如果选择“是”, 则 appsettings.json.env 文件会包含密钥。If you choose Yes, the appsettings.json or .env file will have the keys.

后续步骤Next steps

下载代码后,可以继续在本地计算机上开发机器人。After you download the code, you can continue to develop the bot locally on your machine. 测试了机器人并已准备好将机器人代码上传到 Azure 门户后,请按照设置持续部署主题下列出的说明执行操作,在进行更改后自动更新代码。Once you test your bot and are ready to upload the bot code to the Azure portal, follow the instructions listed under set up continous deployment topic to automatically update code after you make changes.