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: '[email protected]',
      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: '[email protected]',
            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);
});
3
  • Are there any error messages that you could include in your question? Commented Sep 22, 2016 at 6: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 Commented Sep 22, 2016 at 6: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. Commented Sep 22, 2016 at 11:27

1 Answer 1

1

Having database and not 'datetbase' might help:

firebase.datetbase().ref('/employee/').push({
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry that was just a typo. Still having problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.