首页 文章

连接到Firebase功能的Google Action无法调用外部API?

提问于
浏览
0

目前,我使用带有NodeJS的ActionSDK构建了一个google动作,其中履行托管在Firebase Cloud 功能上 . 我现在想做的就是将谷歌动作的输入传递给外部api,但似乎它无法通过它发送?

'use strict';

const {actionssdk} = require('actions-on-google');
const functions = require('firebase-functions');
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;

const app = actionssdk({debug: true});


app.intent('actions.intent.MAIN', (conv) => {
  conv.ask('Hello, this is Patrick.');
});

app.intent('actions.intent.TEXT', (conv, input) => {

  var xhr = new XMLHttpRequest();
  xhr.open("GET", "https://www.googleapis.com/customsearch/v1?key={apikey}&cx={searchID}&q=" + input, true);
  xhr.send();

  xhr.onreadystatechange = function () {
    conv.ask(this.readyState.toString());
  }


exports.myFunction = functions.https.onRequest(app);

但这总是给我的回应:

我的测试应用程序现在没有响应 . 请尽快重试 .

并在错误选项卡中显示:

{“error”:“没有设置响应 . 这是否在异步调用中使用,而未作为对intent处理程序的承诺返回?” }

我不知道为什么会这样,因为我对这整件事情都很陌生 . 任何帮助表示赞赏!

1 回答

  • 0

    如果您使用的是免费的firebase层,则不允许使用外部API . 您需要启用计费并升级到付费层才能访问 .

    UPDATE 您可能需要使用Promise发送回复 . 查看this问题 .

相关问题