node.js - 从上一个意图中获取后续意图中的参数

标签 node.js dialogflow-es

我跟踪一个意图,让我们说“主意图”让子意图跟随是和没有响应意图

如果是,我想从主意图中获取参数 我正在尝试使用这样的上下文来访问它:

var name = agent.context.get('saveContact.saveContact-yes').params['name'];Cannot read property 'get' of undefined

但我不知道要在 get 中放入什么 是上下文名称吗?或主意图名称或特定子意图名称? 我尝试了两者并得到 Null

我无法读取未定义的属性“get” 在日志中。

图书馆:

    "firebase-functions": "^2.0.2",
    "firebase-admin": "^5.13.1",
    "googleapis": "^27.0.0",
    "actions-on-google": "2.2.0",
    "dialogflow-fulfillment": "^0.4.1"

其余代码:

function SaveContact(agent){
 //var name = agent.parameters.name;
 var name = agent.context.get('saveContact.saveContact-yes').params['name'];
 var email = agent.context.get('saveContact.saveContact-yes').params['email'];
// var email=agent.parameters.email;
   return admin.database().ref('/contacts').push({name: name,email:email}).then((snapshot) => {
 // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
     agent.add('added sucessfully');
// console.log('database write sucessful: ' + snapshot.val());
});
}
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response }); /// Thid is to handle the communication with dialogflow
  let intentMap = new Map();
  intentMap.set('makeAppointment', makeAppointment);  // It maps the intent 'Make Appointment' to the function 'makeAppointment()'
  intentMap.set('saveContact-yes', SaveContact);
  agent.handleRequest(intentMap);

});

最佳答案

确保您使用的是最新版本的dialogflow-fulfillment 库。从您的 package.json 来看,您似乎使用的是 0.4.1 版本,该版本具有不同的处理上下文的方式。

agent.context.get() 是在 0.6.0 版本中引入的,之前的方法已被弃用。

您可以使用npm install --savedialogflow-fulfillment@latest更新到最新版本

关于node.js - 从上一个意图中获取后续意图中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55550129/

相关文章:

javascript - 队列异步功能并限制为 1 个并行执行

node.js - Angular、Electron、TypeScript 和 RobotJS

java - Dialogflow Rest API 'Service account authorization without OAuth' 失败

dialogflow-es - 是否可以在DialogFlow中创建基于实体的上下文?

google-cloud-functions - 对话流 : Posting attchment to Facebook via Fullfillment via Firebase (inline) Cloud functions

javascript - 使用nodejs/electron添加新行导致添加多行

node.js - 请求 : How to set user agent for every request?

android - 无法获取资源 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'

ios - 我们如何在 iOS 应用程序中集成 Google dialogflow v2 api?

python - 如何在 Django Python 中使用检测意图(文本)?