您最后的猜测是正确的-问题是您没有使用Promises。
app.intent()``userInfo如果使用异步调用,则期望处理程序函数(在您的情况下)返回Promise。(如果不是,则可以不返回任何内容。)
正常的 *** 作过程是使用返回Promise的东西。但是,这对于您而言是棘手的,因为尚未将地理代码库更新为使用Promises,并且
userInfo函数中的其他代码未返回任何内容。
在这种情况下,重写可能看起来像这样(但是,我还没有测试代码)。在其中,我将两个条件
userInfo分解为另外两个函数,以便一个可以返回Promise。
function userInfonotFound( conv, params, granted ){ // Note: Currently, precise locaton only returns lat/lng coordinates on phones and lat/lng coordinates // and a geopred address on voice-activated speakers. // Coarse location only works on voice-activated speakers. conv.ask(new SimpleResponse({ speech:'Sorry, I could not find you', text: 'Sorry, I could not find you' })) conv.ask(new Suggestions(['Locate Me', 'Back to Menu',' Quit']))}function userInfoFound( conv, params, granted ){ const permission = conv.arguments.get('PERMISSION'); // also retrievable with explicit arguments.get console.log('User: ' + conv.user) console.log('PERMISSION: ' + permission) const location = conv.device.location.coordinates console.log('Location ' + JSON.stringify(location)) return new Promise( function( resolve, reject ){ // Reverse Geocoding geoprer.reverseGeopre(location.latitude,location.longitude,(err,data) => { if (err) { console.log(err) reject( err ); } else { // console.log('geopred: ' + JSON.stringify(data)) console.log('geopred: ' + JSON.stringify(data.results[0].formatted_address)) conv.ask(new SimpleResponse({ speech:'You currently at ' + data.results[0].formatted_address + '. What would you like to do now?', text: 'You currently at ' + data.results[0].formatted_address + '.' })) conv.ask(new Suggestions(['Back to Menu', 'Learn More', 'Quit'])) resolve() } }) });}function userInfo ( conv, params, granted) { if (conv.arguments.get('PERMISSION')) { return userInfoFound( conv, params, granted ); } else { return userInfonotFound( conv, params, granted ); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)