简体   繁体   English

无法在DialogFlow和Google动作中发出API请求。 尚未设定回应

[英]Can't make a API request in DialogFlow and actions-on-google. No response has been set

I'm trying to make a API request using actions-on-google and dialogflow, but after the call has been resolved, the conv.ask does not count as a final response i guess. 我正在尝试使用Google上的动作和dialogflow发出API请求,但是在调用解决之后,conv.ask不会算作最终响应。

My code: 我的代码:

 const functions = require('firebase-functions'); const {dialogflow,Permission} = require('actions-on-google'); const request = require('request'); const rp = require('request-promise-native'); const fetch = require('node-fetch'); const app = dialogflow(); const API_URL = "https://pokeapi.co/api/v2/pokemon/1/"; app.intent('CriarLista - produtos - yes', (conv) => { conv.data.requestedPermission = 'DEVICE_PRECISE_LOCATION'; return conv.ask(new Permission({ context: 'Para te localizar', permissions: conv.data.requestedPermission, })); }); app.intent('CriarLista - location_permission', (conv, params, permissionGranted) => { if (permissionGranted) { const {requestedPermission} = conv.data; if (requestedPermission === 'DEVICE_PRECISE_LOCATION') { const {coordinates} = conv.device.location; if (coordinates) { let lat = coordinates.latitude; let long = coordinates.longitude; fetch(API_URL).then(function(res) { let data = res.json(); }).then(function(data) { conv.ask('Test'); }).catch(function(err) { console.log(err); }); } else { return conv.close('Sorry, I could not figure out where you are.'); } } } else { return conv.close('Sorry, permission denied.'); } }); exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app); 

Errors: actions-on-google response: 错误:谷歌行动响应:

{
  "responseMetadata": {
    "status": {
      "code": 10,
      "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
      "details": [
        {
          "@type": "type.googleapis.com/google.protobuf.Value",
          "value": "{\"id\":\"74f26d40-869c-4ccb-9d75-1473f42e9aee\",\"timestamp\":\"2018-10-06T15:33:01.004Z\",\"lang\":\"pt-br\",\"result\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: 500 Internal Server Error\"},\"sessionId\":\"ABwppHEUqmeurK1aqRe3QRDCo2BrPyZOu4cI447He8ZgA882v72AICpeqPCyzHEA6QCKTeo4cn4CzIZ9ACozv15L\"}"
        }
      ]
    }
  }
}

Firebase console: Firebase控制台:

FetchError: request to https://pokeapi.co/api/v2/pokemon/1/ failed, reason: getaddrinfo EAI_AGAIN pokeapi.co:443

Error: No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?

Says that i need to return a promise, i guess a "resolve" method, but i tried even making my promise and it does not work, the "then" from the fetch method is already a resolve method returned from a promise. 说我需要返回一个承诺,我猜想是一个“解决”方法,但是我什至试图做出我的承诺,但它不起作用,fetch方法中的“那么”已经是一个从承诺中返回的解决方法。 I tried node-fetch, request, request-promise-native.. 我尝试了节点获取,请求,请求承诺本机..

Running only the conv.ask outside the fetch block works normally after deploying to firebase. 部署到Firebase后,仅在提取块外部运行conv.ask即可正常工作。

There is a right way of doing external requests in DialogFlow/actions-on-google environment? 在DialogFlow / Google行动上的环境中,有正确的方式处理外部请求吗?

You need to return the promise object so the webhook knows to wait until the promise is completed. 您需要return promise对象,以便webhook知道要等到promise完成。

Since fetch() already returns a Promise (as do all the .then() calls after it, since that's how one typically uses a Promise), you just need to return that promise. 由于fetch()已经返回了Promise(它之后的所有.then()调用也是如此,因为这通常是使用Promise的方式),因此您只需要返回该Promise。 So you can change the line to 因此您可以将行更改为

            return fetch(API_URL).then(function(res) {
                let data = res.json();
            }).then(function(data) {
                conv.ask('Test');
            }).catch(function(err) {
                console.log(err);
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Async上的操作问题:错误:未设置响应 - Actions On Google Async Issue: Error: No response has been set 在 dialogflow webhook 中设置了响应,但它返回未设置响应 - Response is set in dialogflow webhook but it returns that no response has been set 错误:未设置响应。 Cloud Functions for Actions on Google Assistant - Error: No response has been set. Cloud Functions for Actions on Google Assistant 通过 Dialogflow 实现在 Google Actions 上设置上下文 - Set context on Google Actions through Dialogflow fulfillment Dialogflow / Google上的操作:提供动态响应数据以提供链接建议 - Dialogflow / Actions on Google: Provide dynamic response data for link out suggestions 使用 Nodejs 向 Google API Dialogflow 请求时出现错误 ENOTFOUND - Error ENOTFOUND on request to Google API Dialogflow with Nodejs Google上的操作不起作用,但它们在dialogflow中起作用 - actions on google not working but they does in dialogflow Heroku Node.js上的Google Actions API Webhook响应 - Google Actions API webhook response on Heroku nodejs 错误:发送后无法设置标题 - Error : Can't set header after it has been sent 关于dialogflow的意图不会在Google的操作上更新 - Intents on dialogflow not updating on actions on google
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM