let intent = [{
id: 1,
intentName: "Quick Reply",
functionName: "QuickReply"},{
id: 2,
intentName: "Hello",
functionName: "welcome"}]
如何运行对话框流程
intent.forEach(element => {
intentMap.set(element.intentName, element.functionName);
});//forech intent
我该如何解决?
答案 0 :(得分:0)
将functionName
替换为实函数。
您可以参考以下代码:
var quickReply = (agent)=> {
agent.add("some message");
}
var welcome = (agent)=> {
agent.add("welcome message");
}
let intents = [
{
id: 1,
intentName: "Quick Reply",
functionName: quickReply
},
{
id: 2,
intentName: "Hello",
functionName: welcome
}];
let intentMap = new Map();
intents.forEach(intent=>{
console.log(intent);
intentMap.set(intent.name,intent.function);
});
console.log(intentMap);
agent.handleRequest(intentMap);
`