I'm trying to return data from spreadsheet, the code is working fine, and data appears in the log, but agent.add
not working, as expected.
(我正在尝试从电子表格返回数据,代码工作正常,数据显示在日志中,但是agent.add
无法正常工作。)
I need is to make the dialogflow to response and return the data which I get from spreadsheet.
(我需要使dialogflow响应并返回从电子表格中获取的数据。)
What happen is that in one position of the code, the dialogflow agent.add
working as expected, but it's not returning the data which I get form the spreadsheet, see this part:
(发生的是,在代码的一个位置,dialogflow agent.add
按预期工作,但是它没有返回我从电子表格中获取的数据,请参阅以下部分:)
agent.add("status code inside: "+ myCode); // agent.add working, but myCode variable not is "XmXm"
In the other position of the code, agent.add
not working, even I can see the spreadsheet data in the log, (I tried with and without return
before agent.add
) see this part
(在代码的其他位置, agent.add
无法正常工作,甚至我都可以在日志中看到电子表格数据(我在agent.add
之前尝试了有无return
))
return agent.add("status code outside:" value); // function agent.add whether or not I add return before it
Note that I tried many solution which provided in stackoverflow, but I still can't fix it, below is my full code:
(请注意,我尝试了许多stackoverflow提供的解决方案,但仍然无法解决,下面是我的完整代码:)
function sheetPromiseHandelerGet(orderNum){ const jwtClient = authSheet(); let getSheetPromise = new Promise((resolve, reject) => { const mySpreadSheetId = 'SHEET_ID'; const sheetName = "SHEET_NAME"; let myCode = "XmXm"; // give myCode a string value for testing let testFirst = 0; sheets.spreadsheets.values.get( { auth: jwtClient, spreadsheetId: mySpreadSheetId, range: `${sheetName}!A:H` }, (err, res) => { if (err) { console.error(err); return; } const data = res.data.values; let i = 0; for (i = 0; i < data.length; i++) { if (orderNum == data[i][0]){ myCode = `myCode: Order details: ${data[i][1]}`; resolve(myCode); } } } ); agent.add("status code inside: "+ myCode); // agent.add working, but myCode variable not is "XmXm" }); return getSheetPromise.then(function(value) { console.log(value); // the value (which is = myCode) appears correctly in the debugger, return agent.add("status code outside:" value); // function agent.add whether or not I add return before it }); } function orderStatusHandel(agent){ const detailsNum = agent.parameters.detailsNum; sheetPromiseHandelerGet(detailsNum); } function authSheet(){ // }
I'll be greatly appreciating your help!
(我将非常感谢您的帮助!)
ask by usama sulaiman translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…