Created
June 7, 2020 12:39
-
-
Save nidhinkumar06/9b82b89aad94440bf2afc7a0e09e48d1 to your computer and use it in GitHub Desktop.
Musical mojo
This file contains 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
const functions = require('firebase-functions'); | |
const lodash = require('lodash'); | |
const { | |
dialogflow, | |
HtmlResponse | |
} = require('actions-on-google'); | |
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG); | |
const introBGM = require('./prompts/audio'); | |
const categories = require('./data/categories'); | |
const app = dialogflow({ | |
debug: true | |
}); | |
app.intent('Default Welcome Intent', (conv) => { | |
const randomNumber = Math.floor(Math.random() * 10); | |
const introMusic = lodash.shuffle(introBGM)[randomNumber]; | |
const isExistingUser = conv.user.last.seen; | |
if (conv.user.last.seen) { | |
conv.ask(`<speak>${introMusic} Welcome back to Musical Mojo</speak>`); | |
} else { | |
conv.ask(`<speak>${introMusic} Welcome to Musical Mojo you can select a language where you can listen to the music and answer the question.Listen as much as you can</speak>`); | |
} | |
conv.ask(new HtmlResponse({ | |
url: `https://${firebaseConfig.projectId}.firebaseapp.com/`, | |
data: { | |
scene: 'WELCOME', | |
categories, | |
isExistingUser | |
} | |
})); | |
}); | |
exports.fulfillment = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment