private void applySessionAttributes(final Map<String, Object> attributes) { // reset attributes first this.session.getAttributes().clear(); if (attributes != null) { // apply attributes one by one attributes.forEach(this.session::setAttribute); // if debug flag is set add it to the session attributes this.getClient().getDebugFlagSessionAttributeName().ifPresent(name -> { attributes.putIfAbsent(name, true); }); } }
public AlexaSession(final AlexaClient client, final Session session) { super(client); this.sessionClosed = false; this.session = session; // if debug flag is set add it to the session attributes this.getClient().getDebugFlagSessionAttributeName().ifPresent(name -> { this.session.getAttributes().putIfAbsent(name, true); }); }
/** * Fires a launch request * @return skill's response */ public AlexaResponse launch() { // reset attributes first this.session.getAttributes().clear(); log.info("\n[START] launch request ..."); final AlexaResponse response = client.fire(new AlexaLaunchRequest(this)).orElseThrow(() -> new RuntimeException("[ERROR] launch request did not receive a response.") ); log.info(String.format("[DONE] launch request in %1$s ms.", getClient().getLastExecutionMillis())); return response; }
/** * Handle no slots, or slot(s) with no values. In the case of a dialog based skill with multiple * slots, when passed a slot with no value, we cannot have confidence it is is the correct slot * type so we rely on session state to determine the next turn in the dialog, and reprompt. */ private SpeechletResponse handleNoSlotDialogRequest(final Intent intent, final Session session) { if (session.getAttributes().containsKey(SESSION_CITY)) { // get date re-prompt String speechOutput = "Please try again saying a day of the week, for example, Saturday"; // repromptText is the speechOutput return newAskResponse(speechOutput, speechOutput); } else { // get city re-prompt return handleSupportedCitiesRequest(intent, session); } }
/** * Handle no slots, or slot(s) with no values. In the case of a dialog based skill with multiple * slots, when passed a slot with no value, we cannot have confidence it is is the correct slot * type so we rely on session state to determine the next turn in the dialog, and reprompt. */ private SpeechletResponse handleNoSlotDialogRequest(final Intent intent, final Session session) { if (session.getAttributes().containsKey(SESSION_CITY)) { // get date re-prompt String speechOutput = "Please try again saying a day of the week, for example, Saturday"; // repromptText is the speechOutput return newAskResponse(speechOutput, speechOutput); } else { // get city re-prompt return handleSupportedCitiesRequest(intent, session); } }
/** * 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); }
if (session.getAttributes().containsKey(SESSION_CURRENT_INDEX)) { int currentIndex = (Integer) session.getAttribute(SESSION_CURRENT_INDEX); int currentItemNumberInList = currentIndex + 1;
if (session.getAttributes().containsKey(SESSION_CURRENT_INDEX)) { int currentIndex = (Integer) session.getAttribute(SESSION_CURRENT_INDEX); int currentItemNumberInList = currentIndex + 1;
if (session.getAttributes().containsKey(SESSION_CURRENT_INDEX)) { String speechOutput = "Would you like to hear more?"; repromptText = "Would you like to hear more top sellers? Please say yes or no.";
if (session.getAttributes().containsKey(SESSION_CURRENT_INDEX)) { String speechOutput = "Would you like to hear more?"; repromptText = "Would you like to hear more top sellers? Please say yes or no.";
/** * 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); } }
/** * 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); } }
String speechOutput = ""; int stage = -1; if (session.getAttributes().containsKey(SESSION_STAGE)) { stage = (Integer) session.getAttribute(SESSION_STAGE);
String speechOutput = ""; int stage = -1; if (session.getAttributes().containsKey(SESSION_STAGE)) { stage = (Integer) session.getAttribute(SESSION_STAGE);
private Session getSessionWithIsNew() { return Session.builder() .withApplication(session.getApplication()) .withUser(session.getUser()) .withIsNew(true) .withSessionId(session.getSessionId()) .withAttributes(session.getAttributes()) .build(); }
if (session.getAttributes().containsKey(SESSION_DATE_DISPLAY)) { String displayDate = (String) session.getAttribute(SESSION_DATE_DISPLAY); String requestDateParam = (String) session.getAttribute(SESSION_DATE_REQUEST);
if (session.getAttributes().containsKey(SESSION_DATE_DISPLAY)) { String displayDate = (String) session.getAttribute(SESSION_DATE_DISPLAY); String requestDateParam = (String) session.getAttribute(SESSION_DATE_REQUEST);
card.setTitle("Wise Guy"); if (session.getAttributes().containsKey(SESSION_STAGE)) { if ((Integer) session.getAttribute(SESSION_STAGE) == SETUP_STAGE) { int jokeID = (Integer) session.getAttribute(SESSION_JOKE_ID);
card.setTitle("Wise Guy"); if (session.getAttributes().containsKey(SESSION_STAGE)) { if ((Integer) session.getAttribute(SESSION_STAGE) == SETUP_STAGE) { int jokeID = (Integer) session.getAttribute(SESSION_JOKE_ID);