Skip to content

Instantly share code, notes, and snippets.

@jamesmorgan
Created May 14, 2017 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmorgan/131f81fc2d938834f610c2809488b9d2 to your computer and use it in GitHub Desktop.
Save jamesmorgan/131f81fc2d938834f610c2809488b9d2 to your computer and use it in GitHub Desktop.
Sample flow for email processing
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const functions = require('firebase-functions');
exports.emailProcessor = functions.database.ref('/email/raw/{emailId}').onWrite(event => {
if (event.data.exists()) {
let rawEmail = event.data.val();
return findMatchingEntity(rawEmail)
.then((matched) => {
if (!matched) return Promise.reject("No found", rawEmail);
return convertEmail(rawEmail, matched);
})
.then((convertedEmail) => saveConverted(convertedEmail))
.then((convertedEmail) => deleteRawEmail(convertedEmail, rawEmail))
.then((convertedEmail) => convertedEmail)
.catch((err) => console.error(err));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment