Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3
- artist:
- "Red Hot Chili Peppers"
- id:
- "4"
- maxEmotion:
- "anger"
- score:
- "0.578864"
- song:
- "Suck My Kiss"
- spotifyCode:
- "spotify:track:0psB5QzGb4653K0uaPgEyh"
- 'use strict';
- const functions = require('firebase-functions');
- const admin = require('firebase-admin');
- const {WebhookClient} = require('dialogflow-fulfillment');
- admin.initializeApp({
- credential: admin.credential.applicationDefault(),
- databaseURL: 'ws://mood-magic-four-ptwvjb.firebaseio.com/'
- });
- exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
- const agent = new WebhookClient({ request, response });
- //4
- function playAngrySong (agent) {
- // Get the database collection 'dialogflow' and document 'agent'
- return admin.database().ref((`3`) ).once('value').then((snapshot) => {
- const song = snapshot.child('song').val();
- const artist = snapshot.child('artist').val();
- agent.add(`I will play ${song} by ${artist}`);
- // THIS IS WHERE I NEED THE POST TO THE SPOTIFY API
- });
- }
- // Map from Dialogflow intent names to functions to be run when the intent is matched
- let intentMap = new Map();
- intentMap.set('-Angry - yes', playAngrySong);
- agent.handleRequest(intentMap);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement