繁体   English   中英

Dialogflow webhook 实现参数无法访问

[英]Dialogflow webhook fulfillment parameter not accessible

我想在我的 webhook 实现中输入一个参数。

这是我的代码:

const bodyParser = require('body-parser')
var request = require('request-promise-native');
const { dialogflow } = require('actions-on-google');
const assistant = dialogflow({
  clientId: "30xxxxx08407-rv9kxxxxxxxxuuq8f9ul2eg.apps.googleusercontent.com"
});


module.exports = (app) => {
  const logger = console;

assistant.intent('Sales', conv => {
 const pcode = agent.parameters['PCODE'];
 console.log(pcode)

    const token = '3369708919812376';
    const serviceID = '502';
    const P_STATE_CD = 'ALL';
    const P_FO_CD = 'ALL';
    const P_DISTT_CD = 'ALL';
    const P_DATE = '16/12/2019';
    const P_PRD_GROUP = 'UREA';
    const P_PERSONAL_NO = '106296';

        var data = {"token" : token,"serviceID" : serviceID,"P_STATE_CD" : P_STATE_CD,"P_FO_CD" : P_FO_CD,"P_DISTT_CD" : P_DISTT_CD,"P_DATE" : P_DATE,"P_PRD_GROUP" : P_PRD_GROUP,"P_PERSONAL_NO" : P_PERSONAL_NO };
        var sdata = JSON.stringify(data);

                    const options = {
                        method: 'POST',
                        uri: 'http://Webservice/resources/webservice/service' ,
                        body: JSON.parse(sdata) ,
                        json: true
                    }
        return request(options)
            .then( body => {
                 var unit = body
                 console.log(body)
                 unit.intent = "Sales"
                 unit.value1 = unit.saleInfo[0].QMTD
                 unit.value2 = unit.saleInfo[0].QYTD
                 unit.value3 = unit.saleInfo[0].O_UOM
                 unit.value4 = null
                 unit.value5 = null

                 delete unit.saleInfo
                 var unit2 = JSON.stringify(unit)
                console.log(unit2)
          conv.ask(unit2);
              })
              .catch( err => {
               console.error( err );
               conv.ask('Something went wrong. What should I do now?');
                 });
  })

我尝试使用const pcode = agent.parameters.PCODE但它不起作用。 给我错误:

参考错误:agent 未在 Assistant.intent.conv (/home/dbalunge/GoogleDF/service.js:15:16) 的 Function 处定义。 (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:151:27) at Generator.next () at /home/dbalunge/GoogleDF/node_modules/actions-on- google/dist/service/dialogflow/dialogflow.js:22:71 at new Promise () at __awaiter (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:18: 12) 在 Object. (/home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/assistant.js:55:32) at Generator.next () at /home/dbalounge/GoogleDF/node_modules/actions-on-google/dist/助手.js:22:71

agent没有在您的代码中的任何地方定义,这就是为什么您会得到:

ReferenceError: agent is not defined

在任何情况下,如果您使用assistant.parameters也不会起作用。 Dialogflow 意图参数可以通过.intent回调的第二个参数访问。

assistant.intent('Sales', (conv, params) => {
     const pcode = params.PCODE;
     /* ... */
})

有关更多信息,您可以查看文档

暂无
暂无

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

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