Created
September 13, 2019 08:56
-
-
Save Qoyyuum/46010cb8f4fe41e464735aa177208e34 to your computer and use it in GitHub Desktop.
GDG Adoption Chatbot DialogFlow Fulfillment Script to Copy and Paste
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
| // Import necessary stuff | |
| const { | |
| dialogflow, | |
| Carousel, | |
| Image | |
| } = require('actions-on-google'); | |
| const functions = require('firebase-functions'); | |
| // Enable debugging | |
| const app = dialogflow({ | |
| debug: true | |
| }); | |
| const allCats = new Carousel({ | |
| title: 'All Cats', | |
| items: { | |
| 'Alex': { | |
| title: 'Alex', | |
| image: new Image({ | |
| url: 'https://placekitten.com/300/300', | |
| alt: 'Alex the cat' | |
| }) | |
| }, | |
| 'Comot': { | |
| title: 'Comot', | |
| image: new Image({ | |
| url: 'https://placekitten.com/400/300', | |
| alt: 'Comot the cat' | |
| }) | |
| } | |
| } | |
| }); | |
| const allDogs = new Carousel({ | |
| title: 'All Dogs', | |
| items: { | |
| 'Spike': { | |
| title: 'Spike', | |
| image: new Image({ | |
| url: 'https://www.101dogbreeds.com/wp-content/uploads/2016/07/Pin-Tzu-Photos.jpg', | |
| alt: 'Spike the dog' | |
| }) | |
| }, | |
| 'Buster': { | |
| title: 'Buster', | |
| image: new Image({ | |
| url: 'https://i.ytimg.com/vi/ppbJZ2_5yD8/hqdefault.jpg', | |
| alt: 'Buster the dog' | |
| }) | |
| } | |
| } | |
| }); | |
| app.intent('Adoption', (conv) => { | |
| conv.ask('Simple response text'); | |
| const animalType = conv.parameters.animalType; | |
| If(animalType == 'cat'){ | |
| conv.ask(allCats); | |
| }; | |
| If(animalType == 'dog'){ | |
| conv.ask(allDogs); | |
| }; | |
| }); | |
| // Export its functions upon requests | |
| exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment