javascript - Alexa 技能不会将数据发送到 firebase (Cloud Firestore)
问题描述
我正在alexa开发者控制台中做我的项目,我正在尝试将数据发送到firebase(Firestore),但显然它并没有离开我。代码db.collection ('notes').add ({...});
它实际上对控制台是不可见的。
- 我授权了firebase中的读写规则。
- 我将 firebase-admin 依赖项放在 package-json 中
const admin = require('firebase-admin');
const serviceAccount = require('./key-firebase.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://notes-alexa.firebaseio.com"
});
const db = admin.firestore();
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent';
},
handle(handlerInput) {
// ----- This code sends the data to firebase. But apparently it doesn't run ----
db.collection('notes').add({name: "Finn", country: "US"});
let speakOutput = `Hello world`;
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
解决方案
我刚刚将您的代码与我的成功进行了比较。我看到的差异在下面以粗体显示:
异步句柄(handlerInput){....
等待db.collection('notes').add....
希望能帮助到你!
推荐阅读
- python - Pip 不安装 setup.py 中声明的依赖项 install_requires
- javascript - 来自“throw”语句的意外“未定义”输出
- c# - 调整对象上指定类型的所有属性
- python - 如何在 HTML 中获取脚本标签内的文本
- c# - 无法将文本从一种编码解码为另一种编码
- java - 如何修复 hikaripool 和 springboot-jpa 中的连接泄漏错误
- javascript - Node 中 indexOf 是如何实现的?
- javascript - jQuery [data-anchor] 似乎出现故障
- bash - Shell 脚本的行为因我 SSH 来自的 PC 而异
- puppet - Tagmail-如何在 master 中设置我们的 smtp 服务器