Skip to content

Instantly share code, notes, and snippets.

@mandnyc
Last active January 16, 2019 19:00
Show Gist options
  • Select an option

  • Save mandnyc/403647f187b265f9ae02b7ed8ce6799f to your computer and use it in GitHub Desktop.

Select an option

Save mandnyc/403647f187b265f9ae02b7ed8ce6799f to your computer and use it in GitHub Desktop.
Planet Glossary Part 1.js
//Copyright 2018 Google LLC.SPDX-License-Identifier: Apache-2.0
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const app = dialogflow({debug: true});
admin.initializeApp();
const db = admin.firestore();
const collectionRef = db.collection('planets');
app.intent('ask_planet_intent', (conv, {planet}) => {
const term = planet.toLowerCase();
const termRef = collectionRef.doc(`${term}`);
return termRef.get()
.then((snapshot) => {
const {definition, word} = snapshot.data();
conv.ask(`Here you go, ${word}, ${definition}. ` +
`What else do you want to know?`);
}).catch((e) => {
console.log('error:', e);
conv.close('Sorry, try again and tell me another planet.');
});
});
exports.actionsOracle = functions.https.onRequest(app);
@Ramjivan
Copy link
Copy Markdown

add this line
db.settings({timestampsInSnapshots: true});

after
const db = admin.firestore();

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