/** * Helper method that will get the intent name from a provided Intent object. If a name does not * exist then this method will return null. * @param intent intent object provided from a skill request. * @return intent name or null. */ private String getIntentName(Intent intent) { return (intent != null) ? intent.getName() : null; }
/** * Function to accept an intent containing a Day slot (date object) and return the Calendar * representation of that slot value. If the user provides a date, then use that, otherwise use * today. The date is in server time, not in the user's time zone. So "today" for the user may * actually be tomorrow. * * @param intent * the intent object containing the day slot * @return the Calendar representation of that date */ private Calendar getCalendar(Intent intent) { Slot daySlot = intent.getSlot(SLOT_DAY); Date date; Calendar calendar = Calendar.getInstance(); if (daySlot != null && daySlot.getValue() != null) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-d"); try { date = dateFormat.parse(daySlot.getValue()); } catch (ParseException e) { date = new Date(); } } else { date = new Date(); } calendar.setTime(date); return calendar; }
@Override public SkillRequestInformation parseRequestEnvelope(SpeechletRequestEnvelope envelope) { IntentRequest request = (IntentRequest) envelope.getRequest(); Intent intent = request.getIntent(); SkillRequestInformation skillRequestInformation = new SkillRequestInformation(); skillRequestInformation.setRequestType(SkillRequestInformation.RequestType.INTENT_REQUEST); skillRequestInformation.setIntentName(intent.getName()); skillRequestInformation.setSlots(intent.getSlots()); skillRequestInformation.setToken(getDisplayStateToken(envelope)); return skillRequestInformation; }
Map<String, Slot> slots = intent.getSlots();
private IntentRequest givenIntentRequest(final String intentName, final Map<String, Slot> slots) { Map<String, Slot> slotsForSure = slots != null ? slots : new HashMap<>(); final Intent intent = Intent.builder() .withName(intentName) .withSlots(slotsForSure) .build(); return IntentRequest.builder() .withRequestId(requestId) .withTimestamp(new Date()) .withIntent(intent) .withLocale(Locale.forLanguageTag(locale)) .build(); }
Map<String, Slot> slots = intent.getSlots();
@Override public CoreSpeechletRequest getSpeechletRequest() { final Intent intent = Intent.builder() .withName(intentName) .withSlots(slots) .build(); return IntentRequest.builder() .withLocale(session.getClient().getLocale()) .withRequestId(generateRequestId()) .withIntent(intent) .withTimestamp(session.getClient().getCurrentTimestamp()) .build(); } }
@Override public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) { IntentRequest request = requestEnvelope.getRequest(); Session session = requestEnvelope.getSession(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); initializeComponents(); Intent intent = request.getIntent(); if ("NewGameIntent".equals(intent.getName())) { return scoreKeeperManager.getNewGameIntentResponse(session, skillContext); } else if ("AddPlayerIntent".equals(intent.getName())) { return scoreKeeperManager.getAddPlayerIntentResponse(intent, session, skillContext); } else if ("AddScoreIntent".equals(intent.getName())) { return scoreKeeperManager.getAddScoreIntentResponse(intent, session, skillContext); } else if ("TellScoresIntent".equals(intent.getName())) { return scoreKeeperManager.getTellScoresIntentResponse(intent, session); } else if ("ResetPlayersIntent".equals(intent.getName())) { return scoreKeeperManager.getResetPlayersIntentResponse(intent, session); } else if ("AMAZON.HelpIntent".equals(intent.getName())) { return scoreKeeperManager.getHelpIntentResponse(intent, session, skillContext); } else if ("AMAZON.CancelIntent".equals(intent.getName())) { return scoreKeeperManager.getExitIntentResponse(intent, session, skillContext); } else if ("AMAZON.StopIntent".equals(intent.getName())) { return scoreKeeperManager.getExitIntentResponse(intent, session, skillContext); } else { throw new IllegalArgumentException("Unrecognized intent: " + intent.getName()); } }
Slot citySlot = intent.getSlot(SLOT_CITY); CityDateValues<String, String> cityObject = null;
@Override public SkillRequestInformation parseRequestEnvelope(SpeechletRequestEnvelope envelope) { IntentRequest request = (IntentRequest) envelope.getRequest(); Intent intent = request.getIntent(); SkillRequestInformation skillRequestInformation = new SkillRequestInformation(); skillRequestInformation.setRequestType(SkillRequestInformation.RequestType.INTENT_REQUEST); skillRequestInformation.setIntentName(intent.getName()); skillRequestInformation.setSlots(intent.getSlots()); skillRequestInformation.setToken(getDisplayStateToken(envelope)); return skillRequestInformation; }
@Override public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) { IntentRequest request = requestEnvelope.getRequest(); Session session = requestEnvelope.getSession(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); initializeComponents(); Intent intent = request.getIntent(); if ("NewGameIntent".equals(intent.getName())) { return scoreKeeperManager.getNewGameIntentResponse(session, skillContext); } else if ("AddPlayerIntent".equals(intent.getName())) { return scoreKeeperManager.getAddPlayerIntentResponse(intent, session, skillContext); } else if ("AddScoreIntent".equals(intent.getName())) { return scoreKeeperManager.getAddScoreIntentResponse(intent, session, skillContext); } else if ("TellScoresIntent".equals(intent.getName())) { return scoreKeeperManager.getTellScoresIntentResponse(intent, session); } else if ("ResetPlayersIntent".equals(intent.getName())) { return scoreKeeperManager.getResetPlayersIntentResponse(intent, session); } else if ("AMAZON.HelpIntent".equals(intent.getName())) { return scoreKeeperManager.getHelpIntentResponse(intent, session, skillContext); } else if ("AMAZON.CancelIntent".equals(intent.getName())) { return scoreKeeperManager.getExitIntentResponse(intent, session, skillContext); } else if ("AMAZON.StopIntent".equals(intent.getName())) { return scoreKeeperManager.getExitIntentResponse(intent, session, skillContext); } else { throw new IllegalArgumentException("Unrecognized intent: " + intent.getName()); } }
Slot citySlot = intent.getSlot(SLOT_CITY); CityDateValues<String, String> cityObject = null;
@Override public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) { IntentRequest request = requestEnvelope.getRequest(); Session session = requestEnvelope.getSession(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session); // Get intent from the request object. Intent intent = request.getIntent(); String intentName = (intent != null) ? intent.getName() : null; // Note: If the session is started with an intent, no welcome message will be rendered; // rather, the intent specific response will be returned. if ("MyColorIsIntent".equals(intentName)) { return setColorInSession(intent, session); } else if ("WhatsMyColorIntent".equals(intentName)) { return getColorFromSession(intent, session); } else { String errorSpeech = "This is unsupported. Please try something else."; return getSpeechletResponse(errorSpeech, errorSpeech, true); } }
Slot dateSlot = intent.getSlot(SLOT_DATE); CityDateValues<String, String> dateObject;
@Override public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) { IntentRequest request = requestEnvelope.getRequest(); Session session = requestEnvelope.getSession(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session); // Get intent from the request object. Intent intent = request.getIntent(); String intentName = (intent != null) ? intent.getName() : null; // Note: If the session is started with an intent, no welcome message will be rendered; // rather, the intent specific response will be returned. if ("MyColorIsIntent".equals(intentName)) { return setColorInSession(intent, session); } else if ("WhatsMyColorIntent".equals(intentName)) { return getColorFromSession(intent, session); } else { String errorSpeech = "This is unsupported. Please try something else."; return getSpeechletResponse(errorSpeech, errorSpeech, true); } }
Slot dateSlot = intent.getSlot(SLOT_DATE); CityDateValues<String, String> dateObject;
@Override public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) { IntentRequest request = requestEnvelope.getRequest(); log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), requestEnvelope.getSession().getSessionId()); Intent intent = request.getIntent(); String intentName = (intent != null) ? intent.getName() : null; if ("HelloWorldIntent".equals(intentName)) { return getHelloResponse(); } else if ("AMAZON.HelpIntent".equals(intentName)) { return getHelpResponse(); } else { return getAskResponse("HelloWorld", "This is unsupported. Please try something else."); } }
List<ColumnName> axes = new ArrayList<>(); if (intent.getSlot(SlotUtil.PLOT_COLUMN_1).getValue() != null) { axes.add(SlotUtil.parseColumnSlot( intent.getSlot(SlotUtil.PLOT_COLUMN_1).getValue())); if (intent.getSlot(SlotUtil.PLOT_COLUMN_2).getValue() != null) { axes.add(SlotUtil.parseColumnSlot( intent.getSlot(SlotUtil.PLOT_COLUMN_2).getValue()));