Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/help messages #291

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions functions/src/actions/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// const _ = require('lodash');
const mustache = require('mustache');

const constants = require('../constants');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls put requirements in order of path

const {debug} = require('../utils/logger')('ia:actions:help');
const dialog = require('../dialog');
const fsm = require('../state/fsm');
const helpStrings = require('../strings').intents.help;
const util = require('util');
/**
* handle help intent
*
* @param app
*/
function handler (app) {
debug('INSIDE HELP HANDLER: ');
const state = fsm.getState(app);
debug('STARTING STATE: ' + state);

if (state.indexOf('help') === -1) {
debug('INSIDE INTRO');
dialog.ask(app, {
speech: mustache.render(helpStrings.intro),
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you haven't break handler here, so you could have multiple dialog.ask is it on purpose?

}

debug('PARAMETER: ' + util.inspect(app.params.getByName('help'), false, null));
let command = app.params.getByName('help');

if (!command) {
debug('Inside state switch...');
switch (state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use object key-values matching instead of the switch.
The reason: with a key-value object - once we decide to add extra help we would need only add new help string in strings.js. For the switch design we would need to change handler and strings.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I'd recommend to store strings with speech field, so we would be able to alter not only speech property of answer but also suggestions with shortcut options

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//strings.js
{
  commands: {
    collection: {
      speech: 'There are two main collections to listen to. Our collection of 78s, which features a variety of genres including jazz, instrumental, and dance. Our other collection is of live concerts. These are live concert recordings that have been uploaded to the Archive. They include artists like the Grateful Dead and the Disco Biscuits.',
      suggestions: ['play jazz', 'play grateful dead'],
    },
    player: {
      speech: 'You can control the audio player by saying "pause" to stop the music and "play" to start it again. You can skip to the next song by saying "next song". You can hear the titles of songs in the player by saying "title on". You can turn off this feature by saying "title off".',
      suggestions: ['pause', 'next song'],
    },
  }
}
// ...
//handler.js
//...
dialog.ask(app, helpStrings[command] || helpString.default)
//...

Something like that

case 'playback':
debug('Hit playback ');
dialog.ask(app, {
speech: mustache.render(helpStrings.playback + helpStrings.endQuestion),
});
break;
case 'playback-is-stoped':
debug('Hit playback stopped');
dialog.ask(app, {
speech: mustache.render(helpStrings.playbackstopped + helpStrings.endQuestion),
});
break;
case 'search-music':
debug('Hit search-music');
dialog.ask(app, {
speech: mustache.render(helpStrings.search + helpStrings.endQuestion),
});
break;
default:
debug('Hit default inside state switch');
dialog.ask(app, {
speech: mustache.render(helpStrings.default),
});
}
} else {
debug('Inside else switch....');
command.toLowerCase();
debug('COMMAND = ' + command);
switch (command) {
case 'collection':
debug('Hit collections');
dialog.ask(app, {
speech: mustache.render(helpStrings.collectionsInfo),
});
break;
case 'player':
debug('Hit player');
dialog.ask(app, {
speech: mustache.render(helpStrings.playerControl),
});
break;
default:
debug('Hit second default');
dialog.ask(app, {
speech: mustache.render(helpStrings.error),
});
}
} // End of switch statement
fsm.transitionTo(app, constants.fsm.states.HELP);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need help state?

}

module.exports = {
handler,
};
1 change: 1 addition & 0 deletions functions/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
PLAYBACK: 'playback',
PLAYBACK_IS_STOPED: 'playback-is-stoped',
SEARCH_MUSIC: 'search-music',
HELP: 'help',
},
},
};
14 changes: 14 additions & 0 deletions functions/src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ module.exports = {
getFSMState: {
speech: 'State of FSM is {{state}}',
},
/**
* Help intntet
*/
help: {
collectionsInfo: 'There are two main collections to listen to. Our collection of 78s, which features a variety of genres including jazz, instrumental, and dance. Our other collection is of live concerts. These are live concert recordings that have been uploaded to the Archive. They include artists like the Grateful Dead and the Disco Biscuits.',
default: 'You are in the help interface for the Internet Archive voice app. You can ask me if you\'d like to hear more about our music collections or how the music player works. You can return to the main app at any time by saying "Talk to the Internet Archive".',
endQuestion: 'Would you like to hear more information about our collections or would you prefer to hear about how the music player can be controlled?',
error: 'I didn\'t catch that. Would you like to hear about collections or how the music player works?',
intro: 'Welcome to the help interface for the Internet Archive voice app. You can return to the main app at any time by saying "Talk to the Internet Archive".<break></break>',
playback: 'You are currently using playback. The Archive will continue to play music from the our collections. There are two main collections to listen to- our collection of 78s or our collection of live concerts.',
playerControl: 'You can control the audio player by saying "pause" to stop the music and "play" to start it again. You can skip to the next song by saying "next song". You can hear the titles of songs in the player by saying "title on". You can turn off this feature by saying "title off".',
playbackstopped: 'Playback has stopped. You are likely at the end of a playlist. To return to the main app, just say "Talk to the Internet Archive".',
search: 'You are currently using music search. You can listen to music from two of our collections - 78s or live concerts. You can also say "play" and the name of an artist.',
},

/**
* In one go actions for playback music
Expand Down