Alexa技能不会将数据发送到Firebase(Cloud Firestore)

时间:2019-10-15 20:24:45

标签: javascript firebase alexa alexa-skill alexa-voice-service

我正在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(); 
    }
};

1 个答案:

答案 0 :(得分:0)

我刚刚将您的代码与成功运行的代码进行了比较。我看到的区别在下面的粗体中:

异步句柄(handlerInput){....

等待 db.collection('notes')。add...。

希望有帮助!