API.ai 机器人使用与用户相同的措辞

API.ai bot using same wordings as user

我是 api.ai 的新手,正在尝试让机器人适应用户的词汇。例如,如果一开始机器人询问用户是否想说话,用户会说 yes/yep/okay/ok 等,我想稍后再次使用该答案给用户。我可以这样做吗?谢谢!

  1. 创建 yesaffirmative API.AI entity。在实体中包括所有同义词值(如您描述的 yes/yep/okay/ok)。
  2. 创建一个包含所有用户查询示例的意图,用户可能会先说这个(您可能需要在多个意图中包含 yes 实体)。
  3. 创建一个 webhook (fulfillment getting started guide here). In the webhook check for the yes parameter in the webhook request and if it is present record the value, in a database along with a user identifier (provided by the platform you choose, like Google Assistant or Slack) 以便稍后在对用户的响应中检索。

下面是一些使用 Cloud Functions for Firebase for fulfillment of an API.AI agent and the Firebase Realtime Database 存储用户数据的非工作代码,这将是您实现的良好起点:

const functions = require('firebase-functions');
const admin = require("firebase-admin");
const db = admin.database();
const ref = db.ref("your/firebase/database/here");

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const parameters = request.body.result.parameters;
  if (parameters['yes']){
    var usersRef = ref.child("users");
    usersRef.set({
      userId: {
        yes: parameters['yes']
      }
    });
  }
});