I want to list the event of odoo calendar in my chatbot created in dialogflow and using webhook.
This is my code :
function GetEventOdoo(agent) {
let username =agent.parameters.username;
var odooResult;
var odoo = new Odoo({
url: 'xxxxxxxxx',
port: 'xxxxxxxxxx',
db: 'xxxxxxxxxxxx',
username: '[email protected]',
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} `);
});
}
I can't connect with odoo to list data, i try out of dialogflow and works good, but here it's not working , maybe i have to correct the function to list this data from webhook to dialogflow.
Webhook call failed. Error: 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)
Edited:
I just uploaded my code like this*
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}, 😊`);
}).catch(() => {
agent.add(` 😔 `);
});
}
Error is : Error: memory limit exceeded. Function invocation was interrupted.
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);
}
All this does is quit out of the Promise without calling either resolve()
or reject()
, but it has returned that Promise to the Intent dispatcher, which is waiting for it to either resolve or reject, which never happens.
To fix this, instead of returning the console log (?), you should explicitly call reject()
in these cases. So your code might look something like
if (err) {
reject( err );
}
This is only this complicated because you are wrapping calls to odoo in the Promise yourself. I don't know which library you're using, but you may wish to use one that works with Promises natively. For example, the odoo-api library lets you write things such as
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` );
});
};
without having to create or manage the Promise yourself. Using this library would even let you use async/await in the more recent versions of node, so this could even be written as something like (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` );
}