您可以使用以下Node.js代码示例来创建AWS Lex Slot类型:
const lexModelBuildingService = new AWS.LexModelBuildingService();
const params = {
name: 'coffeeTypes', // Slot类型名称
description: 'Types of coffee', // Slot类型描述
enumerationValues: [
{
value: 'latte'
},
{
value: 'cappuccino'
},
{
value: 'americano'
}
] // 枚举值。可以动态创建或通过列表指定
};
lexModelBuildingService.putSlotType(params, (err, data) => {
if (err) console.log(err, err.stack);
// 一旦创建了Slot Type,它将对您的Bot可用
});
创建完slot类型后,您可以在Lex bot创建中使用它们。 例如,在您的Bot Intent中,您可以使用以下定义来定义一个新的Intent:
const params = {
name: 'orderCoffee',
fulfillmentActivity: { // 填充动作或继续致电另一个Bot或序列
type: 'ReturnIntent'
},
sampleUtterances: [ // 购买咖啡的样本意味着
'I want to order a {size} {type} coffee',
'Order a {type} coffee {size} please',
'Can I get a {type} coffee, {size}, please?'
],
slots: [ // 描述slots的数组,其中包含您的Dialog代码将填写的Gap
{
name: 'type',
description: 'The type of coffee to order',
slotConstraint: 'Required', // Indicates the slot is required to fulfill an intent.
slotType: 'coffeeTypes' // 声明 Slot 类型
},
{
name: 'size',
description: 'The size of coffee to order',
slotConstraint: 'Required',