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
| var fallbackMessages = [ | |
| 'Sorry, not sure what you just said.', | |
| 'Uh oh! Try again.', | |
| 'Hm... Sorry I\'m not that smart yet. Try again!' | |
| ]; | |
| var message = messages[Math.floor(Math.random() * messages.length)]; | |
| bot.say(message); |
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
| let store = { | |
| ... | |
| getState: function(hash) { | |
| if (!this._users[hash]) return this._initializeUser(hash) | |
| return this._users[hash] | |
| }, | |
| clearState: function(hash) { |
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
| let store = { | |
| ... | |
| update: function(hash, data) { | |
| if (!this._users[hash]) this._initializeUserState(hash) | |
| console.log('🌑 => PREVIOUS STATE') | |
| console.log(this.getState(hash)) | |
| this._users[hash] = _.merge(this._users[hash], data) |
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
| class Messenger { | |
| ... | |
| handleText(msg) { | |
| const message = new Message(Message.mapMessage(msg)) | |
| const text = message.text | |
| if (inputParser.isAskingForGenreList(text)) | |
| return handlers.music.getGenreList(message, this.bot) |
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
| let store = { | |
| _users: {}, | |
| // creates state tree | |
| _initializeUserState: function(hash) { | |
| this._users[hash] = { | |
| command: '', | |
| spotify: { | |
| genre: '', | |
| numberOfRecs: 0 |
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
| (function(module) { | |
| function getRecommendation(selectedGenre, limit) { | |
| ... | |
| return Promise.resolve() | |
| .then(getSpotifyAccessToken) | |
| .then(getRecommendation) | |
| function getRecommendation() { |
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
| class Music { | |
| ... | |
| getRecommendation(message, bot) { | |
| store.update(message.from, { | |
| command: commands.GET_RECOMMENDATION, | |
| spotify: { | |
| numberOfRecs: message.text | |
| } | |
| }) |
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
| class Music { | |
| getGenreList(message, bot) { | |
| // clears store for new command tree | |
| store.clearState(message.from) | |
| store.update(message.from, { command: commands.GET_GENRE_LIST }) | |
| bot.sendMessage(message.from, 'Choose a genre you would like a recommendation for 🎵', { | |
| reply_markup: { | |
| keyboard: genresJSON.genres, | |
| one_time_keyboard: true |
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
| class InputParser { | |
| isAskingForGenreList(text) { | |
| const pattern = /music|recommendation/i | |
| return text.match(pattern) | |
| } | |
| isAskingForNumberOfRec(text, prevCommand) { | |
| return prevCommand === commands.GET_GENRE_LIST | |
| } |
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
| 'use strict' | |
| const Messenger = require('./lib/messenger') | |
| const messenger = new Messenger() | |
| messenger.listen() | |
| .then(() => { | |
| console.log('🤖 Listening to incoming messages') | |
| }) |