首页 > 解决方案 > Alexa 技能不会将数据发送到 firebase (Cloud Firestore)

问题描述

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

标签: javascriptfirebasealexaalexa-skillalexa-voice-service

解决方案


我刚刚将您的代码与我的成功进行了比较。我看到的差异在下面以粗体显示

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

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

希望能帮助到你!


推荐阅读