功能Dialogflow的Foreach建议

时间:2019-12-03 09:51:28

标签: node.js dialogflow dialogflow-fulfillment

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

我该如何解决?

1 个答案:

答案 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);

`