我正在尝试向我网站的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);
});
我还没有找到如何从“履行”中提出要求的信息。 对我的Costum API进行http / https请求的方式是什么?
答案 0 :(得分:2)
如果您使用的是免费版本的Firebase,则将无法对第三方服务进行API调用。为此,您需要升级到Firebase上的付费帐户。