我有一个特定实体的列表,如何为每个实体设置单独的响应?或特定实体的回复列表?
我想也许可以通过Google助手自定义有效负载实现(?)
你的问题有些模糊,但听起来你会在Intent中设置一个参数设置为某个值,这些值来自自定义实体类型,并且你希望每个值都有不同的响应。
您无法通过Intent的Response部分处理此问题 - 您需要使用履行webhook。
如果您正在使用actions-on-google库(您建议您可能正在使用它),并且参数名为val
,那么代码片段可能如下所示:
app.intent('choose.value', (conv, {val}) => {
switch( val ){
case 'red':
agent.add('I like red too!');
break;
case 'blue':
agent.add('Blue is pretty cool!');
break;
default:
agent.add(`Not sure what to say about ${val}.`);
}
})
如果您使用的是dialogflow-fulfillment库,它将类似于:
var chooseVal = function( agent ){
var val = agent.parameters.val;
switch( val ){
case 'red':
conv.ask('I like red too!');
break;
case 'blue':
conv.ask('Blue is pretty cool!');
break;
default:
conv.ask(`Not sure what to say about ${val}.`);
}
}
如果您使用的是multivocal,则可以添加一个构建器,根据颜色设置Outent
环境设置,并在配置中设置Outent和Intent的响应:
new Multivocal.Config.Simple({
Local: {
en: {
Response: {
"Outent.red": [
"I like red too!",
"Red is nifty."
],
"Outent.blue": [
"Blue is pretty cool!",
"I really groove blue"
],
"Intent.choose.value": [
"Not sure what to say about {{Parameter.val}}"
]
}
}
}
});
var outentBuilder = function( env ){
env.Outent = `Outent.${env.Parameter.val}`;
return Promise.resolve( env );
};
Multivocal.addBuilder( outentBuilder );
迟到的回复,但如果您不想使用履行webhook并且您只需要使用一个参数,也许有人会发现这个答案很有用。