简体   繁体   English

如何使用 node.js 在对话流中创建参数

[英]How to create parameters in dialogflow using node.js

I want to create a parameter in node js that stays in the same intent for a life spam of 2. It should ask for the first value then validates it, then second value and so on我想在节点 js 中创建一个参数,该参数对于 2 的生活垃圾邮件保持相同的意图。它应该要求第一个值然后验证它,然后是第二个值等等

在此处输入图片说明

what I have done我做了什么

function test(agent) {
      var first = agent.parameters.first;
      var second = agent.parameters.second;
      
      agent.context.set({
        name: 'test',
        lifespan: 2,
        parameters: {
          'first': first,
          'second': second
        },
      });
     agent.add("first parameter then second parameter");
}

Should I create the parameters in dialogflow as follows and implement it in node js or it should be done all in node js.我应该按如下方式在 dialogflow 中创建参数并在 node js 中实现它,还是应该在 node js 中完成。 If so how can I do it?如果是这样,我该怎么做?

在此处输入图片说明

appreciate your help感谢你的帮助

I would say that in general the best option is to set all the intent's parameters via Dialogflow and then interact via Node.js client library.我想说一般来说最好的选择是通过 Dialogflow 设置所有意图的参数,然后通过 Node.js 客户端库进行交互。 Actually it would be also possible to do everything with Node.js, but in case you are using (or may use in the future) one of the integration options using fulfillment to manage agent's responses you should set awebhook service and manage responses via API .实际上,也可以使用 Node.js 做所有事情,但是如果您正在使用(或将来可能会使用)使用执行来管理代理响应的集成选项之一,您应该设置webhook 服务并通过API管理响应. Therefore, I think setting the parameters in Dialogflow before interacting with Node.js would be the simplest and straightforward approach for any use case.因此,我认为在与 Node.js 交互之前在 Dialogflow 中设置参数对于任何用例来说都是最简单直接的方法。

代码工作正常,以防任何人面临相同的问题,发送的请求必须具有相同的会话 ID 以避免覆盖值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM