database - 使用任何服务器数据库进行谷歌助理操作
问题描述
我正在使用谷歌助手来创建自己的操作,我是新手。我想使用自己的数据库并将用户响应保存到数据库。有人可以帮我吗?
解决方案
早上好,高塔姆!您的确切履行代码将根据您选择的数据库和云环境而有所不同。就我而言,我为 Google Assistant 构建了一个操作,该操作在 GCP Cloud Firestore NoSQL 数据库中创建了一个条目。
此示例代码在我的数据库中创建一个条目:
app.intent('write to the wall', (conv) => {
console.log(conv);
console.log(conv.input.raw);
var userReply = conv.input.raw;
function writeToDb(userReply){
const dialogflowAgentRef = db.collection('dialogflow').doc('agent');
return db.runTransaction(t => {
t.set(dialogflowAgentRef, {entry: userReply});
conv.ask('The wall now reads, ' + userReply + '\n\n');
conv.close("Thanks for visiting!");
return Promise.resolve('Write complete');
}).then(doc => {
console.log(`Wrote "${userReply}" to the Firestore database.`);
}).catch(err => {
console.log(`Error writing to Firestore: ${err}`);
// console.log(`Failed to write "${userReply}" to the Firestore database.`);
});
}
return writeToDb(userReply);
});
您的数据库create
功能可能看起来略有不同,但希望能帮助您入门……前提是您选择使用Actions on Google 代码实验室中介绍的技术堆栈:Node.js、Dialogflow 和 Firebase
推荐阅读
- c - CS50 凯撒在非数字输入后不退出
- python - 如何让这个 SVM 在 python 中运行得更快
- haskell - 从动态作用域更改为静态作用域/词法作用域
- java - 跨多个 Maven 存储库传递地解析工件的下载 URL
- html - 如何固定移动视图的按钮大小
- html - 在 Shopify 主题首次亮相中使用 JQuery 平滑滚动不起作用
- java - 如何在玩家切换到游戏结束屏幕 X 次后展示插页式广告?
- asp.net - 成功 SAML 响应后,AuthenticateResult 正在返回 false
- matlab - Matlab 单元测试在通过和失败之间交替(通过“奇数”运行,“偶数”失败)
- go - 为什么所有 BitTorrent 跟踪器都给我相同的响应?