Skip to content

Instantly share code, notes, and snippets.

@matthewess
Last active July 25, 2016 00:04
Show Gist options
  • Save matthewess/edea64b058c6a6c71072fa040f9f297c to your computer and use it in GitHub Desktop.
Save matthewess/edea64b058c6a6c71072fa040f9f297c to your computer and use it in GitHub Desktop.
Sadbot Firebase Documentation

Connection

Firebase details need to be set in your .env, including a reference to a .json file with the service account credentials and the URL for the firebase DB.

Usage

Modules that want to access firebase should require('../firebase.js'). Example:

Example

var firebase = require('../firebase.js');
...
firebase(function(db) {
  var threadReference = db.ref(threadID);
  var moduleReference = threadReference.child('/moduleName');
  var resourceReference = moduleReference.child('/resource');
  resourceReference.once('value', function(snapshot) {
    console.log(snapshot.val());
  });
  resourceReference.update({
    key: 'value'
  });
}

Schema

All interactions with the database should be done by /threadID/moduleName/, and modules should generally only access their given thread ID/module name namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment