/** * 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); }
/** * Creates a {@code SpeechletResponse} for the intent and get the user's favorite color from the * Session. * * @param intent * intent for the request * @return SpeechletResponse spoken and visual response for the intent */ private SpeechletResponse getColorFromSession(final Intent intent, final Session session) { String speechText; boolean isAskResponse = false; // Get the user's favorite color from the session. String favoriteColor = (String) session.getAttribute(COLOR_KEY); // Check to make sure user's favorite color is set in the session. if (StringUtils.isNotEmpty(favoriteColor)) { speechText = String.format("Your favorite color is %s. Goodbye.", favoriteColor); } else { // Since the user's favorite color is not set render an error message. speechText = "I'm not sure what your favorite color is. You can say, my favorite color is " + "red"; isAskResponse = true; } return getSpeechletResponse(speechText, speechText, isAskResponse); }
/** * 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); }
/** * Creates a {@code SpeechletResponse} for the intent and get the user's favorite color from the * Session. * * @param intent * intent for the request * @return SpeechletResponse spoken and visual response for the intent */ private SpeechletResponse getColorFromSession(final Intent intent, final Session session) { String speechText; boolean isAskResponse = false; // Get the user's favorite color from the session. String favoriteColor = (String) session.getAttribute(COLOR_KEY); // Check to make sure user's favorite color is set in the session. if (StringUtils.isNotEmpty(favoriteColor)) { speechText = String.format("Your favorite color is %s. Goodbye.", favoriteColor); } else { // Since the user's favorite color is not set render an error message. speechText = "I'm not sure what your favorite color is. You can say, my favorite color is " + "red"; isAskResponse = true; } return getSpeechletResponse(speechText, speechText, isAskResponse); }
/** * 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); } }
@Override public SpeechletResponse respond(Intent intent, Session session) { try { return queryHandler.respond( refine(intent, (QueryRequest) Serializer.deserialize( (String) session.getAttribute(SessionUtil.REQUEST_ATTRIBUTE))), session); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); return Response.unexpectedError(session); } }
/** * 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); } }
ArrayList<String> events = (ArrayList<String>) session.getAttribute(SESSION_TEXT); int index = (Integer) session.getAttribute(SESSION_INDEX); String speechOutput = ""; String cardOutput = "";
int currentIndex = (Integer) session.getAttribute(SESSION_CURRENT_INDEX); int currentItemNumberInList = currentIndex + 1; StringBuilder speechOutput = new StringBuilder(); (String) session.getAttribute(Integer.toString(currentIndex)); if (currentString != null) { if (currentItemNumberInList < MAX_ITEMS) { + "</say-as> top seller is. " + currentString + ". Those were the 10 top sellers in Amazon's " + session.getAttribute(SESSION_CURRENT_CATEGORY) + " department");
/** * Exposed for testing purposes - SpeechletResponse is impossible to inspect. */ public String getResponseInEnglish(Intent intent, Session session) { QueryRequest previousRequest; try { previousRequest = (QueryRequest) Serializer.deserialize( (String) session.getAttribute(SessionUtil.REQUEST_ATTRIBUTE)); return querier.execute(refine(intent, previousRequest)).getMessage(); } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); return "There was an error generating the response in English"; } }
int currentIndex = (Integer) session.getAttribute(SESSION_CURRENT_INDEX); int currentItemNumberInList = currentIndex + 1; StringBuilder speechOutput = new StringBuilder(); (String) session.getAttribute(Integer.toString(currentIndex)); if (currentString != null) { if (currentItemNumberInList < MAX_ITEMS) { + "</say-as> top seller is. " + currentString + ". Those were the 10 top sellers in Amazon's " + session.getAttribute(SESSION_CURRENT_CATEGORY) + " department");
try { request = (QueryRequest) Serializer.deserialize( (String) session.getAttribute(SessionUtil.REQUEST_ATTRIBUTE)); } catch (ClassNotFoundException | IOException e) { e.printStackTrace();
String displayDate = (String) session.getAttribute(SESSION_DATE_DISPLAY); String requestDateParam = (String) session.getAttribute(SESSION_DATE_REQUEST); CityDateValues<String, String> dateObject = new CityDateValues<String, String>(displayDate, requestDateParam);
String displayDate = (String) session.getAttribute(SESSION_DATE_DISPLAY); String requestDateParam = (String) session.getAttribute(SESSION_DATE_REQUEST); CityDateValues<String, String> dateObject = new CityDateValues<String, String>(displayDate, requestDateParam);
int stage = -1; if (session.getAttributes().containsKey(SESSION_STAGE)) { stage = (Integer) session.getAttribute(SESSION_STAGE);
int stage = -1; if (session.getAttributes().containsKey(SESSION_STAGE)) { stage = (Integer) session.getAttribute(SESSION_STAGE);
if ((Integer) session.getAttribute(SESSION_STAGE) == SETUP_STAGE) { int jokeID = (Integer) session.getAttribute(SESSION_JOKE_ID); speechOutput = JOKE_LIST.get(jokeID).speechPunchline; card.setContent(JOKE_LIST.get(jokeID).cardPunchline);
if ((Integer) session.getAttribute(SESSION_STAGE) == SETUP_STAGE) { int jokeID = (Integer) session.getAttribute(SESSION_JOKE_ID); speechOutput = JOKE_LIST.get(jokeID).speechPunchline; card.setContent(JOKE_LIST.get(jokeID).cardPunchline);