--- title: "1:手动创建 Lex 机器人" date: 2019-09-05T23:06:51+08:00 draft: false chapter: false hidden: true --- ## 手动创建一个 Intent 1. 登录[AWS Lex 控制台](https://us-east-1.console.aws.amazon.com/lex) 1. 点击Get Started,选择Custom bot。 1. 设置bot name为“PersonalBanker”,选择你喜欢的“Output Voice”,“Session timeout”为5 分钟,Children’s Online Privacy Protection Act (COPPA) question选择“No”,点击Create。 ![](/images/ask/create-lex-bot.png) 1. 接下来,我们要来创建Intent,每个Intent都代表用户下达的一个指令。在本实验中,我们会创建三个 Intents, Get Account Details, Get Loan Details, Get Loan Products。 点击 **Create Intent** 按钮, 点击**Create new intent** 。 ![](/images/ask/add-intent.png) 1. 在弹框中输入名字 ``GetAccountDetail``,点击 **Add** 。 ![](/images/ask/create-intent.png) 1. 我们现在想要提供用户输入或说出来执行此操作的示例(即激活Intent)。在Sample utterances下,输入以下短语后单击蓝色“+”按钮。 {AccountType} 代表一个 ‘slot’ ,我们利用 slot 的信息来去获取用户的输入。先阶段,请直接这么输入。下一步中,我们将会定义 ‘AccountType’ slot 并且列出所有允许的可被解析的值。 当此步骤完成时,用户可以通过这样的方式 “What is my checking balance” 去 Alexa 去做交互。 > 确保您没有在短语的末尾添加问号,这会导致问题。 - ``What is my {AccountType} balance`` - ``{AccountType} account balance`` ![](/images/ask/personal-banker.png) 1. 接下来我们来定义 slot 的值,和用户输入指令后的一些提示语。点击左侧导航栏中 **Slot types** 旁边的蓝色+,点击 **Create slot type**。 1. 在 **Slot type name** 输入 `AccountType` ,描述可选。 1. 在 Value 中分别输入 ``checking`` 和 ``saving``, 分别点击 + ,然后点击 **Add slot to intent** 。 ![](/images/ask/add-slot-type.png) 1. 将 **Name** 改为 `AccountType` 。在 **Prompt** 栏中,输入 `What type of account?`,这会在用户问题不够明确时弹出。 ![](/images/ask/get-account-detail.png) 1. 翻到页面最下方,点击 **Save Intent** 1. 点击右上方灰色的 **Build** 按钮, 点击 **Build**。build 过程会持续大概一分钟。一旦完成,您可以测试。比如在聊天框中输入 `what is my checking balance?`现阶段我们没有增加后端处理逻,因此返回会提示 ready for fulfillment。 ![](/images/ask/ready-for-fulfillment.png) 1. 接下按着同样的步骤,创建两个新的Intent:“GetLoanDetail”和“GetLoanProducts”。 1. 点击左侧导航栏Intent旁边的+,选择Create Intent,输入名字:GetLoanDetail,点击Add。 1. 在Sample etterances下,输入以下短语后单击蓝色“+”按钮。 确保您没有在短语的末尾添加问号,因为这会在以后导致构建问题。 ``Get my {LoanType} loan balance`` 1. 接下来我们来定义 slot 的值,和用户输入指令后的一些提示语。点击左侧导航栏中 Slot types 旁边的蓝色+,点击 **Create slot type** 。 1. 在Slot type name中输入 ``LoanType`` ,在Value中输入 ``car`` 和 ``home`` 分别点击+,然后点击 **Add slot to intent** 。 1. 把 Name 从 slotOne 改成 LoanType ,并在 Prompt(提示语)中填入 **Which loan account ?** 。 1. 请确保您已经选中了 **Required** 这一栏 ![](/images/ask/get-loan-product.png) 1. 在最下端点击Save Intent。 1. 点击左侧导航栏Intent旁边的+,选择Create Intent,输入名字:GetLoanProducts,点击Add。 1. 在Sample utterances下,输入以下短语后单击蓝色“+”按钮。 确保您没有在短语的末尾添加问号,因为这会在以后导致构建问题。 - `What is the rate on the {LoanType} loan` - `More loan info` 1. 接下来,不用重新创建slot types,在slot直接输入: - Required: 勾选 - Name: `LoanType` - Slot Type: `LoanType` (从下拉菜单中选择) - Prompt: `Which loan type?` 1. 在最下端点击Save Intent。