我正在alexa开发人员控制台中执行我的项目,并且试图将数据发送到firebase(Firestore),但显然它并没有离开我。代码db.collection ('notes').add ({...});
对于控制台几乎是不可见的。
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();
}
};
答案 0 :(得分:0)
我刚刚将您的代码与成功运行的代码进行了比较。我看到的区别在下面的粗体中:
异步句柄(handlerInput){....
等待 db.collection('notes')。add...。
希望有帮助!