如何在 Dialogflow -> Fulfillment 环境中发出 http 请求?

How do I make a http request in the environment Dialogflow -> Fulfillment?

我正在尝试向我的站点的 api 发出请求,以便更正 google 助手的答案,但我什么都没有。

'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 发出请求的信息。 http/https 向我的服装 api 提出请求的方法是什么?

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