[英]Use of any server database for google assistant actions
I am using google assistant for creating my own actions and i am new to it. 我正在使用Google Assistant创建自己的操作,因此我是新手。 I want to use my own database and save user response to database.Can anyone help me on this please?
我想使用自己的数据库并保存用户对数据库的响应。有人可以帮我吗?
Good morning, Gautam! 早上好,乔塔姆! Your exact fulfillment code will vary depending on which database and cloud environment you choose.
您的确切实现代码将取决于您选择的数据库和云环境。 In my case, I built an action for the Google Assistant that creates an entry in a GCP Cloud Firestore NoSQL database.
就我而言,我为Google助手构建了一个动作 ,该动作在GCP Cloud Firestore NoSQL数据库中创建了一个条目。
This sample code creates an entry in my database: 此示例代码在我的数据库中创建一个条目:
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);
});
Your database create
function might look slightly different, but hopefully that helps you get started... provided you choose to use the tech stack introduced in Actions on Google's codelabs : Node.js, Dialogflow, and Firebase 您的数据库
create
功能可能看起来略有不同,但是希望可以帮助您入门...只要您选择使用Google的代码实验室Actions中引入的技术堆栈:Node.js,Dialogflow和Firebase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.