Last active
November 11, 2018 00:44
-
-
Save netomarin/94282f86c1b04e33972ada4700783d4a to your computer and use it in GitHub Desktop.
Basic AoG fulfillment to add a donation to a Firestore collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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