- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 Cloud Firestore 数据库,存储了 2017 年英国所有城市的居民人数。
然后我有一个 Dialogflow。每当我将城市名称告诉 Dialogflow 时,我希望它从 Firestore 获取该城市的居民人数并将其返回给 Dialogflow。
具体来说,我想通过内联编辑器实现它。
问题:我需要在下面的代码中添加哪些代码行才能实现这一点?
下面是我在 Dialogflow > Fulfillment > index.js 的内联编辑器中编写的代码:
'use strict';
const functions = require('firebase-functions');
const firebaseAdmin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const App = require('actions-on-google').DialogflowApp;
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Hello and welcome!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
最佳答案
下面是一些示例代码,展示了如何将 Firebase 的 Firestore 数据库连接到 Firebase 函数上托管的 Dialogflow fulfillment:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:*'; // enables lib debugging statements
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function writeToDb (agent) {
// Get parameter from Dialogflow with the string to add to the database
const databaseEntry = agent.parameters.databaseEntry;
// Get the database collection 'dialogflow' and document 'agent' and store
// the document {entry: "<value of database entry>"} in the 'agent' document
const dialogflowAgentRef = db.collection('dialogflow').doc('agent');
return db.runTransaction(t => {
t.set(dialogflowAgentRef, {entry: databaseEntry});
return Promise.resolve('Write complete');
}).then(doc => {
agent.add(`Wrote "${databaseEntry}" to the Firestore database.`);
}).catch(err => {
console.log(`Error writing to Firestore: ${err}`);
agent.add(`Failed to write "${databaseEntry}" to the Firestore database.`);
});
}
function readFromDb (agent) {
// Get the database collection 'dialogflow' and document 'agent'
const dialogflowAgentDoc = db.collection('dialogflow').doc('agent');
// Get the value of 'entry' in the document and send it to the user
return dialogflowAgentDoc.get()
.then(doc => {
if (!doc.exists) {
agent.add('No data found in the database!');
} else {
agent.add(doc.data().entry);
}
return Promise.resolve('Read complete');
}).catch(() => {
agent.add('Error reading entry from the Firestore database.');
agent.add('Please add a entry to the database first by saying, "Write <your phrase> to the database"');
});
}
// Map from Dialogflow intent names to functions to be run when the intent is matched
let intentMap = new Map();
intentMap.set('ReadFromFirestore', readFromDb);
intentMap.set('WriteToFirestore', writeToDb);
agent.handleRequest(intentMap);
});
这来自位于此处的 Dialogflow 的 Firestore 示例:https://github.com/dialogflow/fulfillment-firestore-nodejs
关于node.js - 如何通过 Dialogflow 中的内联编辑器将 Dialogflow 连接到 Cloud Firestore?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51692357/
自从我将 Dialogflow 升级为使用 v2 API 后,出现以下错误: Dialogflow IntentHandler not found for intent: myIntent 由于某些原
PermissionDenied:拒绝了“projects/XXXX-live/agent”上的403 IAM权限“dialogflow.sessions.detectIntent”。 创建服务时,我
基本上,我的代理人是法国人,当我输入 10h(12 小时格式为上午 10 点)时,我的 DialogFlow 代理人理解 22h(晚上 10 点),但我希望他理解上午 10 点。 (我想要 24 小时
我和我的团队正在使用 Dialogflow 为 Facebook Messenger 构建一个机器人,但由于我们的用户不会说同一种语言(西类牙语是项目中的默认语言),我们想要实现我们项目的英文版本,但
我是新来的 DialogFlow ,我开始创建代理,从smaltalk从头开始。问题是如何将更多预构建代理(例如警报和应用程序管理,以及货币转换器)附加到新创建的代理中? 谢谢你的帮助。 最佳答案 您
在 Dialogflow 中,通过扩展设置为自动化的“训练实体”的最佳方法是什么。在训练短语中添加实体和在实体屏幕中简单地添加示例值之间有什么区别吗? Dialogflow 培训是否比另一个更重视?创
我正在尝试训练 Dialogflow 机器人来识别不同的旅行请求(航类预订、酒店预订等)。我发现如果没有将时间指定为 12 小时格式(使用 AM/PM),它就不能正确解析时间。 我需要周六 08:00
我正在使用 webhook 在 dialogflow 上制作一个机器人。我收到一个错误:DEADLINE_EXCEEDED。我的 webhook 需要 5 秒多一点的时间来返回响应。有没有办法允许超过
我正在使用 Dialogflow 为银行创建一个机器人。我想保留与客户代表交谈的选择权。如果客户想与客户代表交谈,机器人应该停止,客户代表开始与客户聊天。在 Dialogflow 中如何实现。 最佳答
每当我输入 6 月 37 日作为输入时,它都不会给出错误,而是将日期视为 6 月 30 日。我想要做的是在输入 6 月 37 日时创建一个错误提示。 我在一个非常简单的意图上使用@sys.date,它
有没有办法以编程方式获取 Dialogflow 代理的对话历史记录? 我使用 Dialogflow 制作了一个聊天机器人。现在我需要以编程方式获取代理的对话历史记录。 最佳答案 That featur
我正在研究 dialogflow 跟进意图。结构是这样的。 它为每个新意图创建新上下文。 例如在重复意图中看到 每当我创建任何新意图时,它都会为其创建新上下文。正如你在图片中看到的那样。当我尝试删除这
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 4 年前。 Improve this qu
例如,如果您有 IntentA 并添加了 2 个后续意图:IntentB、IntentC,它工作正常,它应该添加一个上下文,因为它还没有输出上下文。但这就是问题所在。有时如果你添加另一个,例如 Fal
我正在使用 dialogflow 开发语音助手,我对意图的生命周期有疑问。据我了解,生命周期值为我提供了此意图中可能的交互次数。它在每次交互时递减,当等于 0 时,该值不能被识别为意图的可能值。 生命
我创建了一个聊天机器人,它会通知用户我(大)家庭成员的姓名以及他们的生活地点。我用 MySQL 创建了一个小型数据库,其中存储了这些数据,并在适当的时候使用 PHP 脚本获取它们,具体取决于用户与聊天
我想使用 dialogflow 进行注册。例如:我想让机器人问以下问题: 你叫什么名字?你的邮箱是多少? 等等。 我尝试实现此功能,但无法正确管理意图。我应该怎么做才能实现这一目标?谢谢 最佳答案 首
我希望尽可能生成动态文本而不需要创建 webhook。我知道创建动态文本的唯一方法是根据参数创建不同的路由或通过 using inline system functions像文本实现中的 $sys.f
我使用 创建了一个聊天机器人对话流 并与 集成Telegram、Facebook Messenger 和 Web . Dialogflow 的响应是通过 创建的履行用 Python 编写。 在 Tel
我使用 Dialogflow 创建了多个代理,其中许多都在生产中。但是,Dialogflow 项目突然消失了,现在我只能看到创建新代理的选项。 但是,我看到生产代理运行良好。我通过我创建的连接到 Di
我是一名优秀的程序员,十分优秀!