在多个意图之间传递参数会触发Dialogflow的实现

时间:2018-09-03 17:47:24

标签: javascript firebase firebase-realtime-database dialogflow chatbot

我有一个Dialogflow代理,该代理已通过Web钩子进行了设置,该钩子从Firebase数据库中提取信息。我试图让不同的意图在数据库上启动不同的查询。座席从“欢迎意图”中请求一个与数据库匹配的名称(例如,您好,很高兴认识您?您要寻找的名称是什么?)。用户从那里得到一个名称,该名称是一个响应,它触发另一个称为“名称”的意图。该意图具有一个名为“ agent.parameters.defaultName”的参数,该参数传递到实现中并用于查询数据库。以下是Webhook的以下脚本启动:

});
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, 
response) => {

const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + 
JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

//function to request bio info on the db
function handleData(agent) {
const congressName = agent.parameters.congressName;
return admin.database().ref().once("value").then((snapshot) => {
var nameInfo = snapshot.child('Name/' + congressName + '/profile').val(); 
agent.add(nameInfo + "\n  \n Tell me the first and last name of the next 
person you'd like to learn about. Or you can say Twitter to get this 
individual's Twitter info.");
});
 }

//Function to return the name's tweet info
function handleTweet(agent) {
const congressName = agent.parameters.congressName;
return admin.database().ref().once("value").then((snapshot) => {
  var nameTweet = snapshot.child('Name/' + congressName + '/twitter_handle').val(); 
  agent.add(nameTweet);
});
}
// Run the proper function handler based on the matched Dialogflow intent 
name
let intentMap = new Map();
intentMap.set('name', handleData);
intentMap.set('name - custom', handleTweet);
agent.handleRequest(intentMap);

});

这将返回简历,并提示用户说出另一个名字或说Twitter来提取Twitter信息。

如果用户说Twitter,我想触发另一个意图。这个Intent也将具有称为DB的实现,但是这次它将拉动Twitter信息。我遇到问题的地方是我无法激发实现的意图。我想知道我的参数是否在正确的部分,或者是否需要弄清楚如何将其传递给Twitter意图。我不确定我要去哪里。

以下是意图:

//Name intent
{
  "id": "0c7bd173-e7fe-4bb4-9b87-7b94624ceb4e",
  "name": "name",
  "auto": true,
  "contexts": [],
  "responses": [{
    "resetContexts": false,
    "action": "congressName",
    "affectedContexts": [{
      "name": "Name",
      "parameters": {},
      "lifespan": 5
    }],
    "parameters": [{
      "id": "a79559d6-d3db-4b37-b681-174fce8bc58c",
      "required": true,
      "dataType": "@sys.any",
      "name": "congressName",
      "value": "$congressName",
      "prompts": [{
        "lang": "en",
        "value": "What is the proper first and last name of the person you 
  are looking for info on?"
      }],
      "isList": false
    }],
    "messages": [{
      "type": 0,
      "lang": "en",
      "speech": []
    }],
    "defaultResponsePlatforms": {},
    "speech": []
  }],
  "priority": 500000,
  "webhookUsed": true,
  "webhookForSlotFilling": false,
  "lastUpdate": 1535995990,
  "fallbackIntent": false,
  "events": []
 }
 [{
    "id": "a14768b0-c64d-4a63-9ccb-d9452b74ed21",
    "data": [{
      "text": "tammy duckworth",
      "alias": "congressName",
      "meta": "@sys.any",
      "userDefined": false
    }],
    "isTemplate": false,
    "count": 0,
    "updated": 1535223341
  },
  {
    "id": "520acfc8-102b-4e14-9342-54678e9f6940",
    "data": [{
      "text": "tom cotton",
      "alias": "congressName",
      "meta": "@sys.any",
      "userDefined": false
    }],
    "isTemplate": false,
    "count": 0,
    "updated": 1535223341
  }
]
//Twitter intent

"id": "78330811-d692-4c70-adb2-3130b608d46f",
"name": "twitter",
"auto": true,
"contexts": [],
"responses": [{
  "resetContexts": false,
  "action": "",
  "affectedContexts": [],
  "parameters": [{
    "id": "7acd4cb2-9cd7-4c2a-b5aa-2981ee25acf4",
    "dataType": "@congressName",
    "name": "congressName",
    "value": "$congressName",
    "isList": false
  }],
  "messages": [{
    "type": 0,
    "lang": "en",
    "speech": []
  }],
  "defaultResponsePlatforms": {},
  "speech": []
}],
"priority": 500000,
"webhookUsed": true,
"webhookForSlotFilling": false,
"lastUpdate": 1535996186,
"fallbackIntent": false,
"events": []
}
[{
    "id": "4f099a33-74c6-4832-acd1-815aca6605f2",
    "data": [{
        "text": "Susan Collins",
        "alias": "congressName",
        "meta": "@congressName",
        "userDefined": false
      },
      {
        "text": " Twitter",
        "userDefined": false
      }
    ],
    "isTemplate": false,
    "count": 0,
    "updated": 1535996186
  },
  {
    "id": "f775749a-56fd-410d-a167-174e6eb03ddf",
    "data": [{
        "text": "twitter ",
        "userDefined": false
      },
      {
        "text": "@congress",
        "alias": "congressName",
        "meta": "@congressName",
        "userDefined": true
      }
    ],
    "isTemplate": false,
    "count": 0,
    "updated": 1535238371
  }
]

0 个答案:

没有答案