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

Dialogflow es 我无法使用dialogflow和webhook的意图从odoo日历中获取数据,dialogflow-es,odoo,Dialogflow Es,Odoo,我想在dialogflow和webhook中创建的聊天机器人中列出odoo日历的事件 这是我的代码: function GetEventOdoo(agent) { let username =agent.parameters.username; var odooResult; var odoo = new Odoo({ url: 'xxxxxxxxx', port: 'xxxxxxxxxx', db: 'xxxxxxxxx

我想在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调用失败。错误:超过了最后期限

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)
编辑:

  • 我只是像这样上传了我的代码*

       function findeventlist(username) {
        return new Promise((resolve, reject) => {
            const odoo = new Odoo({
                url: 'http://sssss',
                port: '80',
                db: 'ssss',
                username: 'sssssssss',
                password: 'sssssssss'
            });
            //odooResult = JSON.stringify(odoo);
            odoo.connect(function (err) {
                if (err) {
                    return console.log(err);
                }
                console.log('findeventlist Connected to Odoo server.');
                const params = [];
    
                params.push([]);
                params.push(['name']);
                params.push(0);
                params.push(5);
                params.push([params]);
                odoo.execute_kw('calendar.event', 'search_read', params, function (err, value) {
                    if (err) {
                        return console.log(err);
                    }
                    console.log('Result: ', value);
                    resolve.send(JSON.stringify(value));
    
    
                })
                    .catch(error => {
                        console.log(error);
                        reject(error);
                    });
            });
        });
    }
    
    
    function GetEventOdoo(agent) {
    
        let username = agent.parameters.username;
        console.log("GetEventOdoo");
        return findeventlist().then(() => {
            agent.add(`Event: ${username}, You are mixing up how you use Promises with other methods. This is certainly not returning what you expect, likely causing the response to not be sent back, and could be causing other issues such as memory leaks.

    For example, in a few places in your code, inside the Promise, you have

            if (err) {
                return console.log(err);
            }
    
    函数findeventlist(用户名){
    返回新承诺((解决、拒绝)=>{
    康斯特奥多=新奥多({
    网址:'http://sssss',
    端口:'80',
    db:‘ssss’,
    用户名:“SSS”,
    密码:“sssss”
    });
    //odooResult=JSON.stringify(odoo);
    odoo.connect(功能(错误){
    如果(错误){
    返回console.log(err);
    }
    log('findeventlist连接到Odoo服务器');
    常量参数=[];
    参数推送([]);
    参数推送(['name']);
    参数推送(0);
    参数推送(5);
    参数推送([params]);
    odoo.execute_kw('calendar.event','search_read',参数,函数(err,value){
    如果(错误){
    返回console.log(err);
    }
    log('Result:',value);
    send(JSON.stringify(value));
    })
    .catch(错误=>{
    console.log(错误);
    拒绝(错误);
    });
    });
    });
    }
    函数GetEventOdoo(代理){
    让username=agent.parameters.username;
    console.log(“GetEventOdoo”);
    返回findeventlist()。然后(()=>{
    
    agent.add(`Event:${username},您将如何使用承诺与其他方法混为一谈。这肯定不会返回您期望的结果,可能会导致响应无法发回,并可能导致其他问题,如内存泄漏

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

            if (err) {
                reject( err );
            }
    
    所有这一切都是从承诺中退出,而不调用
    resolve()
    reject()
    ,但它已将该承诺返回给意图分派器,该分派器正在等待它解决或拒绝,而这从未发生过

    要解决此问题,在这些情况下,您应该显式调用
    reject()
    ,而不是返回控制台日志(?)

    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` );
          });
    };
    
    这非常复杂,因为您自己正在承诺中包装对odoo的调用。我不知道您正在使用哪个库,但您可能希望使用一个与承诺本机兼容的库。例如,该库允许您编写以下内容:

    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` );
    }
    
    无需自己创建或管理Promise。使用此库甚至可以让您在较新版本的node中使用async/await,因此这甚至可以写成(未测试)


    您是否可以更新您的问题,以表明您是在Firebase或其他地方使用内置的实现编辑器执行此操作?还不清楚
    GetEventOdoo()
    是否是意图处理者,或者如果不是,您如何调用它。(其中有些行没有意义-您在
    JSON.stringify()上调用
    .then()
    ,这是不可启用的。我使用的是webhook javascript,GetEventOdoo是意图名称和函数名称…我是新手,需要帮助修复代码。请更新您的问题以显示如何调用或注册
    GetEventOdoo()
    。在dialogflow中由意图调用,此意图在webhook中调用相同的函数