Created
May 28, 2020 14:00
-
-
Save davxiao/8d0d35d3c88078e5fc96114d02c8ee6b to your computer and use it in GitHub Desktop.
Google Cloud Function built for Dialogflow fulfillment
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
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs | |
// for Dialogflow fulfillment library docs, samples, and to report issues | |
'use strict'; | |
const { | |
Image, | |
MediaObject, | |
Suggestions, | |
} = require('actions-on-google'); | |
const functions = require('firebase-functions'); | |
const {WebhookClient} = require('dialogflow-fulfillment'); | |
const {Card, Suggestion} = require('dialogflow-fulfillment'); | |
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements | |
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { | |
const agent = new WebhookClient({ request, response }); | |
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers)); | |
console.log('Dialogflow Request body: ' + JSON.stringify(request.body)); | |
// Uncomment and edit to make your own Google Assistant intent handler | |
// uncomment `intentMap.set('your intent name here', googleAssistantHandler);` | |
// below to get this function to be run when a Dialogflow intent is matched | |
function googleAssistantHandler(agent) { | |
let conv = agent.conv(); // Get Actions on Google library conv instance | |
conv.ask('Happy Birthday, Olu! Simple Gifts, here you go'); | |
conv.ask(new MediaObject({ | |
name: 'Simple Gifts', | |
url: 'https://www.youtube.com/audiolibrary_download\?vid\=9558199628f83b9b', | |
description: 'A classical music', | |
icon: new Image({ | |
url: 'https://storage.googleapis.com/automotive-media/album_art.jpg', | |
alt: 'Ocean view', | |
}), | |
})); | |
conv.ask(new Suggestions('Suggestion 1')); | |
agent.add(conv); // Add Actions on Google library responses to your agent's response | |
} | |
// See https://github.com/dialogflow/fulfillment-actions-library-nodejs | |
// for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample | |
// Run the proper function handler based on the matched Dialogflow intent name | |
let intentMap = new Map(); | |
intentMap.set('cue-the-music', googleAssistantHandler); | |
agent.handleRequest(intentMap); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment