0

我正在尝试向我的网站的 api 发出请求,以更正谷歌助手的答案,但我没有任何东西。

'use strict';

var requestNode = require('request');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');

const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });

  function test(agent) {
    return new Promise((resolve, reject) => {
        callApi().then((output) => {
            //This method works and the Agent says "output: abc"
            agent.add(output);
            resolve();
        });
    }); 
  }

  function callApi(){
     return new Promise((resolve, reject) => {
       const options = {
         url:    'https://mysite....',
         method: 'GET',
         headers: {'Accept': 'application/json'}
       };

       requestNode(options, function(error, requestInternal, body) {
         resolve(JSON.parse(body).title);
       });

     });

  }


  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }

  let intentMap = new Map();
  intentMap.set('test', test);
  intentMap.set('Default Fallback Intent', fallback);
  agent.handleRequest(intentMap);
});

我还没有找到如何从 Fulfillment 提出请求的信息。对我的服装 api 进行 http/https 请求的方法是什么?

4

1 回答 1

2

如果您使用的是免费层的 firebase,您将无法对第三方服务进行 API 调用。为此,您需要升级到 firebase 上的付费帐户。

于 2018-08-06T16:28:53.287 回答