我正在开发一个应用程序,以从 Dialogflow 聊天中检索图书馆目录中的数据。我没有收到任何错误,并且我有一个附加到该服务的帐单帐户。意图代码在这里:
const {WebhookClient} = require('dialogflow-fulfillment');
const function = require('firebase-functions');
const agent = new WebhookClient({ request: request, response: response });
const catalogSearch = require("rss-to-json");
exports.libraryChat = functions.https.onRequest(request, response) => {
function catalog_search(agent) {
var itemSubject = agent.parameters["item-subject"] ? "+" + agent.parameters["item-subject"] : "";
var itemTitle = agent.parameters["item-title"] ? "+" + agent.parameters["item-title"] : "";
var chatResponse = "";
var itemList = new Array();
if (agent.parameters["author-name"]) {
var authorName = agent.parameters["author-name"]["name"] ? "+" + agent.parameters["author-name"]["name"] + " " + agent.parameters["author-name"]["last-name"] : "+" + agent.parameters["author-name"]["last-name"];
}
var searchString = "";
if (itemSubject.length > 0) { searchString = searchString + itemSubject; }
if (itemTitle.length > 0 ) { searchString = searchString + itemTitle; }
if (authorName.length > 0) { searchString = searchString + authorName; }
var url = "https://gapines.org/opac/extras/opensearch/1.1/-/rss2-full?searchTerms=site(GCHR-CCO)" + searchString + "&searchClass=keyword";
console.log(url);
catalogSearch.load(url, (err, jsonResponse) => {
if (!err) {
itemList = jsonResponse.items;
chatResponse = "The first ten items returned for your search are: ";
}
else {
chatResponse = "I'm sorry! I've encountered an error while retrieving that data!";
}
});
itemList.forEach( (title, index) => {
chatResponse = chatResponse + (index + 1).toString() + title.title;
});
agent.add(chatResponse);
}
let intentMap = new Map();
intentMap.set("Catalog Search", catalog_search);
}
来自意图的 JSON 响应是:
{
"responseId": "958f0d66-13ba-4bf5-bed8-83480da4c37e",
"queryResult": {
"queryText": "Do you have any books about goats?",
"parameters": {
"item-subject": "goats",
"item-title": "",
"author-name": ""
},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"intent": {
"name": "projects/library-chatbot/agent/intents/a5f8ad9b-ff73-49f7-a8c0-351da3bf4802",
"displayName": "Catalog Search"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 3591
},
"languageCode": "en"
},
"webhookStatus": {
"message": "Webhook execution successful"
}
}
我已经通过一个单独的函数验证了 Opensearch 调用是否有效并生成了一个标题列表,但是当通过 Dialogflow 意图访问时,没有任何返回。我认为这可能是由于免费帐户限制,但在添加账单信息和升级后错误仍然存在。
或者,更确切地说,没有产生任何响应的错误。我在这里缺少什么吗?