/** * Responds to the user saying "Who's there". * * @param session * the session object * @return SpeechletResponse the speechlet response */ private SpeechletResponse handleWhosThereIntent(final Session session) { String speechOutput = "", repromptText = ""; if (session.getAttributes().containsKey(SESSION_STAGE)) { if ((Integer) session.getAttribute(SESSION_STAGE) == KNOCK_KNOCK_STAGE) { // Retrieve the joke's setup text. int jokeID = (Integer) session.getAttribute(SESSION_JOKE_ID); speechOutput = JOKE_LIST.get(jokeID).setup; // Advance the stage of the dialogue. session.setAttribute(SESSION_STAGE, SETUP_STAGE); repromptText = "You can ask, " + speechOutput + " who?"; } else { session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); speechOutput = "That's not how knock knock jokes work! <break time=\"0.3s\" /> Knock knock"; repromptText = "You can ask who's there."; } } else { // If the session attributes are not found, the joke must restart. speechOutput = "Sorry, I couldn't correctly retrieve the joke. You can say, tell me a joke."; repromptText = "You can say, tell me a joke."; } return newAskResponse("<speak>" + speechOutput + "</speak>", true, repromptText, false); }
/** * Responds to the user saying "Who's there". * * @param session * the session object * @return SpeechletResponse the speechlet response */ private SpeechletResponse handleWhosThereIntent(final Session session) { String speechOutput = "", repromptText = ""; if (session.getAttributes().containsKey(SESSION_STAGE)) { if ((Integer) session.getAttribute(SESSION_STAGE) == KNOCK_KNOCK_STAGE) { // Retrieve the joke's setup text. int jokeID = (Integer) session.getAttribute(SESSION_JOKE_ID); speechOutput = JOKE_LIST.get(jokeID).setup; // Advance the stage of the dialogue. session.setAttribute(SESSION_STAGE, SETUP_STAGE); repromptText = "You can ask, " + speechOutput + " who?"; } else { session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); speechOutput = "That's not how knock knock jokes work! <break time=\"0.3s\" /> Knock knock"; repromptText = "You can ask who's there."; } } else { // If the session attributes are not found, the joke must restart. speechOutput = "Sorry, I couldn't correctly retrieve the joke. You can say, tell me a joke."; repromptText = "You can say, tell me a joke."; } return newAskResponse("<speak>" + speechOutput + "</speak>", true, repromptText, false); }
/** * Selects a joke randomly and starts it off by saying "Knock knock". * * @param session * the session object * @return SpeechletResponse the speechlet response */ private SpeechletResponse handleTellMeAJokeIntent(final Session session) { String speechOutput = ""; // Reprompt speech will be triggered if the user doesn't respond. String repromptText = "You can ask, who's there"; // / Select a random joke and store it in the session variables int jokeID = (int) Math.floor(Math.random() * JOKE_LIST.size()); // The stage variable tracks the phase of the dialogue. // When this function completes, it will be on stage 1. session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); session.setAttribute(SESSION_JOKE_ID, jokeID); speechOutput = "Knock knock!"; // Create the Simple card content. SimpleCard card = new SimpleCard(); card.setTitle("Wise Guy"); card.setContent(speechOutput); SpeechletResponse response = newAskResponse(speechOutput, false, repromptText, false); response.setCard(card); return response; }
/** * Selects a joke randomly and starts it off by saying "Knock knock". * * @param session * the session object * @return SpeechletResponse the speechlet response */ private SpeechletResponse handleTellMeAJokeIntent(final Session session) { String speechOutput = ""; // Reprompt speech will be triggered if the user doesn't respond. String repromptText = "You can ask, who's there"; // / Select a random joke and store it in the session variables int jokeID = (int) Math.floor(Math.random() * JOKE_LIST.size()); // The stage variable tracks the phase of the dialogue. // When this function completes, it will be on stage 1. session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); session.setAttribute(SESSION_JOKE_ID, jokeID); speechOutput = "Knock knock!"; // Create the Simple card content. SimpleCard card = new SimpleCard(); card.setTitle("Wise Guy"); card.setContent(speechOutput); SpeechletResponse response = newAskResponse(speechOutput, false, repromptText, false); response.setCard(card); return response; }
session.setAttribute(COLOR_KEY, favoriteColor); speechText = String.format("I now know that your favorite color is %s. You can ask me your "
session.setAttribute(COLOR_KEY, favoriteColor); speechText = String.format("I now know that your favorite color is %s. You can ask me your "
cardOutputBuilder.append(" Wanna go deeper in history?"); session.setAttribute(SESSION_INDEX, index); speechOutput = speechOutputBuilder.toString(); cardOutput = cardOutputBuilder.toString();
/** * Handles the dialog step where the user provides a date. */ private SpeechletResponse handleDateDialogRequest(final Intent intent, final Session session) { CityDateValues<String, String> dateObject = getDateFromIntent(intent); // if we don't have a city yet, go to city. If we have a city, we perform the final request if (session.getAttributes().containsKey(SESSION_CITY)) { String city = (String) session.getAttribute(SESSION_CITY); String station = (String) session.getAttribute(SESSION_STATION); CityDateValues<String, String> cityStationMap = new CityDateValues<String, String>(city, station); return getFinalTideResponse(cityStationMap, dateObject); } else { // The user provided a date out of turn. Set date in session and prompt for city session.setAttribute(SESSION_DATE_DISPLAY, dateObject.speechValue); session.setAttribute(SESSION_DATE_REQUEST, dateObject.apiValue); String speechOutput = "For which city would you like tide information for " + dateObject.speechValue + "?"; String repromptText = "For which city?"; return newAskResponse(speechOutput, repromptText); } }
StringBuilder speechOutput = new StringBuilder(); speechOutput.append("Here are the top sellers for ").append(category).append(". "); session.setAttribute(SESSION_CURRENT_CATEGORY, category); session.setAttribute(SESSION_CURRENT_INDEX, numberInList); session.setAttribute(Integer.toString(i), item); cardOutput.append(numberInList).append(". ").append(item).append("."); i++;
/** * Handles the dialog step where the user provides a date. */ private SpeechletResponse handleDateDialogRequest(final Intent intent, final Session session) { CityDateValues<String, String> dateObject = getDateFromIntent(intent); // if we don't have a city yet, go to city. If we have a city, we perform the final request if (session.getAttributes().containsKey(SESSION_CITY)) { String city = (String) session.getAttribute(SESSION_CITY); String station = (String) session.getAttribute(SESSION_STATION); CityDateValues<String, String> cityStationMap = new CityDateValues<String, String>(city, station); return getFinalTideResponse(cityStationMap, dateObject); } else { // The user provided a date out of turn. Set date in session and prompt for city session.setAttribute(SESSION_DATE_DISPLAY, dateObject.speechValue); session.setAttribute(SESSION_DATE_REQUEST, dateObject.apiValue); String speechOutput = "For which city would you like tide information for " + dateObject.speechValue + "?"; String repromptText = "For which city?"; return newAskResponse(speechOutput, repromptText); } }
session.setAttribute(SESSION_INDEX, PAGINATION_SIZE); session.setAttribute(SESSION_TEXT, events);
session.setAttribute(SESSION_CURRENT_INDEX, currentIndex); if (currentIndex < MAX_ITEMS) { speechOutput.append(" Would you like to hear more?");
StringBuilder speechOutput = new StringBuilder(); speechOutput.append("Here are the top sellers for ").append(category).append(". "); session.setAttribute(SESSION_CURRENT_CATEGORY, category); session.setAttribute(SESSION_CURRENT_INDEX, numberInList); session.setAttribute(Integer.toString(i), item); cardOutput.append(numberInList).append(". ").append(item).append("."); i++;
session.setAttribute(SESSION_CURRENT_INDEX, currentIndex); if (currentIndex < MAX_ITEMS) { speechOutput.append(" Would you like to hear more?");
} else { session.setAttribute(SESSION_CITY, cityStation.speechValue); session.setAttribute(SESSION_STATION, cityStation.apiValue); String speechOutput = "For which date?"; String repromptText =
} else { session.setAttribute(SESSION_CITY, cityStation.speechValue); session.setAttribute(SESSION_STATION, cityStation.apiValue); String speechOutput = "For which date?"; String repromptText =
session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); speechOutput = "That's not how knock knock jokes work! <break time=\"0.3s\" /> Knock knock"; repromptText = "You can ask who's there.";
session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); speechOutput = "That's not how knock knock jokes work! <break time=\"0.3s\" /> Knock knock"; repromptText = "You can ask who's there.";
session.setAttribute( SessionUtil.REQUEST_ATTRIBUTE, Serializer.serialize(request)); } catch (IOException e) {