Created
November 3, 2020 17:49
-
-
Save rwisner/891b8ff49b2c2eb9aa0123a04d946a25 to your computer and use it in GitHub Desktop.
Random panda trivia webhook
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
const { conversation } = require('@assistant/conversation'); | |
const functions = require('firebase-functions'); | |
const app = conversation(); | |
// ************ | |
// panda trivia | |
// ************ | |
app.handle('panda_handle', conv => { | |
// create a variable to hold the response | |
var response = ""; | |
// create an array of panda trivia | |
var trivia = [ | |
"Pandas rely on spatial memory, not visual memory.", | |
"A panda’s paw has six digits - five fingers and an opposable pseudo-thumb (actually an enlarged wrist bone) it uses merely to hold bamboo while eating.", | |
"A newborn panda cub is 1/900th the size of its mother and is comparable to the length of a stick of butter.", | |
"The first panda came to the United States in 1936—a cub to a zoo in Chicago. It took another 50 years before the States would see another.", | |
"Approximately 99 percent of a panda’s diet—bamboo leaves and shoots—is void of much nutritional value. Its carnivore-adapted digestive system cannot digest cellulose well, thus it lives a low-energy, sedentary lifestyle but persists in eating some 60 species of bamboo. Pandas must eat upwards of 30 pounds of bamboo daily just to stay full." | |
]; | |
// generate a random number between 0 and 4 | |
// 5 = the number of lines in the array | |
const randomNum = Math.floor(Math.random() * 5); | |
// add the random trivia line to the response | |
response += trivia[randomNum]; | |
// add the response to the conversation | |
conv.add(response); | |
}); | |
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment