Last active
January 16, 2019 19:00
-
-
Save mandnyc/403647f187b265f9ae02b7ed8ce6799f to your computer and use it in GitHub Desktop.
Planet Glossary Part 1.js
This file contains hidden or 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
| //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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add this line
db.settings({timestampsInSnapshots: true});after
const db = admin.firestore();