@Override public void onSessionEnded( final SessionEndedRequest request, final Session session) throws SpeechletException { log.info("onSessionEnded requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); } }
/** * 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); }
private Session getSessionWithIsNew() { return Session.builder() .withApplication(session.getApplication()) .withUser(session.getUser()) .withIsNew(true) .withSessionId(session.getSessionId()) .withAttributes(session.getAttributes()) .build(); }
Session session = requestEnvelope.getSession(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); String speechOutput = ""; int stage = -1; if (session.getAttributes().containsKey(SESSION_STAGE)) { stage = (Integer) session.getAttribute(SESSION_STAGE);
session.getSessionId()); Permissions permissions = session.getUser().getPermissions(); if (permissions == null) { log.info("The user hasn't authorized the skill. Sending a permissions card.");
public AlexaSession(final AlexaClient client) { this(client, Session.builder() .withApplication(client.getApplication()) .withUser(client.getUser()) .withIsNew(false) .withSessionId(generateSessionId()) .withAttributes(new LinkedHashMap<>()) .build()); log.info(String.format("\n[START] session start request with sessionId '%s' ...", this.session.getSessionId())); client.fire(new AlexaSessionStartedRequest(this)); log.info("[DONE] session start request."); }
public static void updatePlotColumns(List<String> plotCols, Session session) { try { makeSureSessionExistsInDB(session.getUser().getUserId()); Statement statement = conn.createStatement(); statement.executeUpdate("update sessions set vis='" + StringEscapeUtils.escapeJava(Joiner.on(',').join(plotCols)) + "'where id='" + cleanId(session.getUser().getUserId()) + "';"); } catch (SQLException e) { log.error(e.getMessage()); } }
ArrayList<String> events = (ArrayList<String>) session.getAttribute(SESSION_TEXT); int index = (Integer) session.getAttribute(SESSION_INDEX); String speechOutput = ""; String cardOutput = ""; cardOutputBuilder.append(" Wanna go deeper in history?"); session.setAttribute(SESSION_INDEX, index); speechOutput = speechOutputBuilder.toString(); cardOutput = cardOutputBuilder.toString();
/** * 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; }
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."; 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++;
/** * 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); }
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); }); } }
@Override public SpeechletRequestEnvelope envelope(final AlexaRequest request) { final SystemState systemState = SystemState.builder() .withUser(session.getUser()) .withDevice(client.device) .withApiEndpoint(client.apiEndpoint) .withApplication(session.getApplication()).build(); final Context context = Context.builder().addState(systemState).build(); // ensure session is ready for another request (make an exception for session ended and launch requests) Validate.isTrue(!sessionClosed || AlexaSessionEndedRequest.class.isInstance(request) || AlexaLaunchRequest.class.isInstance(request), "Session already closed and not ready for another request."); return SpeechletRequestEnvelope.builder() .withRequest(request.getSpeechletRequest()) .withSession(request instanceof AlexaSessionStartedRequest ? getSessionWithIsNew() : session) .withVersion(AlexaClient.VERSION) .withContext(context) .build(); }
Session session = requestEnvelope.getSession(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); String speechOutput = ""; int stage = -1; if (session.getAttributes().containsKey(SESSION_STAGE)) { stage = (Integer) session.getAttribute(SESSION_STAGE);
public static void updateResultData(JSONObject data, Session session) { try { makeSureSessionExistsInDB(session.getUser().getUserId()); Statement statement = conn.createStatement(); statement.executeUpdate("update sessions set result='" + StringEscapeUtils.escapeJava(data.toString()) + "'where id='" + cleanId(session.getUser().getUserId()) + "';"); } catch (SQLException e) { log.error(e.getMessage()); } }
/** * 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; }
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."; 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++;
/** * 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); }
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); }); }
@Override public void onSessionStarted( final SessionStartedRequest request, final Session session) throws SpeechletException { log.info("onSessionStarted requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); }