Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. 3
  2. artist:
  3. "Red Hot Chili Peppers"
  4. id:
  5. "4"
  6. maxEmotion:
  7. "anger"
  8. score:
  9. "0.578864"
  10. song:
  11. "Suck My Kiss"
  12. spotifyCode:
  13. "spotify:track:0psB5QzGb4653K0uaPgEyh"
  14.  
  15. 'use strict';
  16.  
  17. const functions = require('firebase-functions');
  18. const admin = require('firebase-admin');
  19. const {WebhookClient} = require('dialogflow-fulfillment');
  20.  
  21. admin.initializeApp({
  22. credential: admin.credential.applicationDefault(),
  23. databaseURL: 'ws://mood-magic-four-ptwvjb.firebaseio.com/'
  24. });
  25.  
  26. exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  27. const agent = new WebhookClient({ request, response });
  28.  
  29.  
  30.  
  31. //4
  32. function playAngrySong (agent) {
  33. // Get the database collection 'dialogflow' and document 'agent'
  34.  
  35. return admin.database().ref((`3`) ).once('value').then((snapshot) => {
  36. const song = snapshot.child('song').val();
  37. const artist = snapshot.child('artist').val();
  38.  
  39. agent.add(`I will play ${song} by ${artist}`);
  40.  
  41. // THIS IS WHERE I NEED THE POST TO THE SPOTIFY API
  42.  
  43. });
  44. }
  45.  
  46. // Map from Dialogflow intent names to functions to be run when the intent is matched
  47. let intentMap = new Map();
  48. intentMap.set('-Angry - yes', playAngrySong);
  49. agent.handleRequest(intentMap);
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement