Created
December 24, 2018 07:04
-
-
Save onimenotsuki/906d78cc4da1f2c654aab51e5a5259e9 to your computer and use it in GitHub Desktop.
Fulfilment for musixmatch chatbot
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 functions = require('firebase-functions'); | |
const { WebhookClient } = require('dialogflow-fulfillment'); | |
const axios = require('axios'); | |
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements | |
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { | |
const agent = new WebhookClient({ request, response }); | |
function callApi(url, body) { | |
return axios({ | |
method: 'post', | |
url: url, | |
data: body, | |
}); | |
} | |
function fetchLyric(agent) { | |
const apiUrl = 'url-de-tu-endpoint'; | |
const song = agent.parameters.song; | |
const artist = agent.parameters.artist; | |
return callApi(apiUrl, { song: song, artist: artist }) | |
.then(res => agent.add('La letra de la canción es: ' + String(res.data['lyrics_body']))); | |
} | |
let intentMap = new Map(); | |
intentMap.set('get-lyric', fetchLyric); | |
agent.handleRequest(intentMap); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment