Skip to content

Instantly share code, notes, and snippets.

@netomarin
Last active November 11, 2018 00:44
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 netomarin/94282f86c1b04e33972ada4700783d4a to your computer and use it in GitHub Desktop.
Save netomarin/94282f86c1b04e33972ada4700783d4a to your computer and use it in GitHub Desktop.
Basic AoG fulfillment to add a donation to a Firestore collection
'use strict';
const {dialogflow} = require('actions-on-google');
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
const settings = {timestampsInSnapshots: true};
db.settings(settings);
app.intent('Donation', (conv, {Category}) => {
var donationData = {
donation: Category,
donationID: conv.id,
location: "DACHFest",
user: "netomarin"
};
// Add a new document in collection "donations"
return db.collection("donations").doc(conv.id).set(data).then(() => {
return conv.close('Thanks! I added your ' + Category + ' to our list.');
});
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment