gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 01:49:11 25 4
gpt4 key购买 nike

我正在尝试向我的网站的 api 发出请求,以便更正 Google Assistant 的答案,但我什么也没有。

'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 提出请求的信息。如何向我的 Costum api 发出 http/https 请求?

最佳答案

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

关于javascript - 如何在 Dialogflow -> Fulfillment 环境中发出 http 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51702885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com