5

Can someone please tell me how to do this?

This is what i have so far and It's not adding data into my database

I tested this out without using lambda functions on a regular web application and it works

var http = require('http');
var firebase = require('firebase');

exports.handler = (event, context, callback) => {

        var config = {
            apiKey: "AIzaSyCpk23423Iy_akmUniqUJhLt234324YPBE1vD7At8Laj4",
            authDomain: "echoproject-blah.firebaseapp.com",
            databaseURL: "https://echoproject-blah.firebaseio.com",
            storageBucket: "echoproject-blah.appspot.com",
            messagingSenderId: "83962234234322"
        };


   firebase.initializeApp(config);

   firebase.datetbase().ref('/employee/').push({
      med_number: Math.floor(Math.random() * 1000),
      full_name: 'John Smith',
      date_employed: Date.now(),
      email: '23432432@yahoo.com',
      phone_number: '+123423423',
      profile_picture : 'blah.img'
   }).catch(function(err){
    console.log(err);
   });



    if (event.session.new) {
        onSessionStarted({ requestId: event.request.requestId }, event.session);
    }

    if (event.request.type === 'LaunchRequest') {
        onLaunch(event.request,
            event.session,
            (sessionAttributes, speechletResponse) => {
                callback(null, buildResponse(sessionAttributes, speechletResponse));
            });
    } else if (event.request.type === 'IntentRequest') {
        onIntent(event.request,
            event.session,
            (sessionAttributes, speechletResponse) => {
                callback(null, buildResponse(sessionAttributes, speechletResponse));
            });
    } else if (event.request.type === 'SessionEndedRequest') {
        onSessionEnded(event.request, event.session);
        callback();
    }
   } catch (err) {
    callback(err);
     }



}

I'm I missing something?

I'm trying to use firebase for my Amazon Echo. Would that be troubling it?

Is my firebase.database not getting recognize?

UPDATE

None of these solutions worked for me either

**SOLVED**

So after much frustration I decided to ditch the firebase Nodejs sdk and use the Firebase Endpoint urls

var myJSONObject = {
            med_number: Math.floor(Math.random() * 1000),
            full_name: 'John Bruh',
            date_employed: Date.now(),
            email: 'vi43544tle@yahoo.com',
            phone_number: '+345345',
            profile_picture : '34534534'
        };
request({
    url: "https://echoproject-c78fghfgh6f.firebaseio.com/rest/saving-data/users.json",
    method: "POST",
    json: true,   // <--Very important!!!
    body: myJSONObject
}, function (error, response, body){
    if(error) console.log(error);
    console.log(response);
});
Community
  • 1
  • 1
Victor Le
  • 1,758
  • 3
  • 17
  • 25
  • Are there any error messages that you could include in your question? – cartant Sep 22 '16 at 06:01
  • @cartant so I added a catch method after the push method but it's weird because it doesn't even console.log anything out. Idk if you're more familiar with the way Lambda function works but I feel like my firebase's method are getting skipped over? Since I think the way nodejs lambda works is that since it's async It ends before the firebase method are finished initializing? Let me know if I'm wrong that's just a wild guess – Victor Le Sep 22 '16 at 06:09
  • 2
    Good to hear that you found a solution. But Stack Overflow is not a regular forum, so please add your solution as an answer instead of into your question. That also removes the need to indicate in the title that your problem is solved: once you accept your own answer, the system will know that your problem was solved and mark it accordingly. – Frank van Puffelen Sep 22 '16 at 11:27

1 Answers1

1

Having database and not 'datetbase' might help:

firebase.datetbase().ref('/employee/').push({