我无法使用 dialogflow 和 webhook 的意图从 odoo 日历中获取数据

I cant fetch data from odoo calendar using intent of dialogflow and webhook

我想在 dialogflow 中创建并使用 webhook 的聊天机器人中列出 odoo 日历的事件。

这是我的代码:

function GetEventOdoo(agent) {
    let username =agent.parameters.username;
    var odooResult;

    var odoo = new Odoo({
        url: 'xxxxxxxxx',
        port: 'xxxxxxxxxx',
        db: 'xxxxxxxxxxxx',
        username: 'xxxxxxxx@example.com',
        password: 'xxxxxxxxxxxxx'
    });

    odooResult = JSON.stringify(odoo);

    console.log('odooResult!!!:' + odooResult );

    odoo.connect(function (err) {
        if (err) {
            return console.log('connection error: '+ JSON.stringify(err)); }
        console.log('Connected to Odoo server.');
        var inParams = [];
        inParams.push([]); //where conditions
        inParams.push(['name']); //fields
        inParams.push(0); //offset
        inParams.push(5); //limit
        var params = [];
        params.push(inParams);
        odoo.execute_kw('calendar.event', 'search_read', params, function (err, value){
            if (err) { return console.log(err); }
            console.log(value);

        });
    })

    return  odooResult += JSON.stringify(value)
      // eslint-disable-next-line promise/always-return
        .then(res => {

            const launchData = res.data;

           agent.add(`Odoo event is: ${launchData[0].ID}  `);
            console.log(`Odoo event is: ${launchData[0].ID}  `);



        });

}

我无法连接 odoo 以列出数据,我尝试使用 dialogflow 并且效果很好,但在这里它不起作用,也许我必须更正功能以将此数据从 webhook 列出到 dialogflow。

Webhook 调用失败。错误:DEADLINE_EXCEEDED

Error: No handler for requested intent
    at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:327:29)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:118:9)
    at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9)
    at /worker/worker.js:783:7
    at /worker/worker.js:766:11
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

已编辑:

错误是:错误:超出内存限制。函数调用被中断。

您混淆了使用 Promises 和其他方法的方式。这肯定不会返回您所期望的,可能会导致响应未被发回,并可能导致其他问题,例如内存泄漏。

例如,在您的代码中的一些地方,在 Promise 中,您有

        if (err) {
            return console.log(err);
        }

所有这一切都是在不调用 resolve()reject() 的情况下退出 Promise,但它已将该 Promise 返回给 Intent 调度程序,Intent 调度程序正在等待它解决或拒绝,这永远不会发生。

要解决此问题,您应该在这些情况下显式调用 reject(),而不是返回控制台日志 (?)。所以你的代码可能看起来像

        if (err) {
            reject( err );
        }

之所以如此复杂,是因为您自己在 Promise 中包装了对 odoo 的调用。我不知道您使用的是哪个库,但您可能希望使用一个原生支持 Promises 的库。例如,odoo-api 库允许您编写诸如

function findeventlist(){
  return odoo
      .connect({
          database: 'unicorn',
          username: 'foo',
          password: 'bar'
      })
      .then(client => {
          return client.searchRead('product.product', [['list_price', '>', '50']], {limit: 1});
      })
      .then(products => {
          console.log(products);
          //=> [{list_price: 52, name: 'Unicorn'}]
          agent.add( `I found ${products.length} results` );
      });
};

无需自己创建或管理 Promise。使用这个库甚至可以让你在更新版本的节点中使用 async/await,所以这甚至可以写成类似 (untested)

async function findeventlist(){
  const client = await odoo.connect( connectionParameters );
  const products = await client.searchRead('product.product', [['list_price', '>', '50']], {limit: 1});
  console.log( products );
  agent.add( `I found ${products.length} results` );
}