/** * 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; }
protected boolean slotsContainNumberSlotWithValue(Map<String, Slot> slots, String value) { Slot slot = slots.get(SlotNames.NUMBER_SLOT_NAME); return (slot != null) && slot.getValue().equals(value); }
/** * 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; }
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(); }
public AlexaIntentRequest withSlots(final List<Slot> slots) { slots.forEach(slot -> this.slots.putIfAbsent(slot.getName(), slot)); return this; }
/** * Fires an intent with zero to many slots * @param intentName name of the intent * @param slots collection of slots * @return skill's response */ public AlexaResponse intent(final String intentName, final Map<String, Object> slots) { final Map<String, Slot> slots2 = new HashMap<>(); slots.forEach((k,v) -> { slots2.putIfAbsent(k, v instanceof Slot ? (Slot)v : Slot.builder().withName(k).withValue(v.toString()).build()); }); return intent(new AlexaIntentRequest(this, intentName).withSlots(slots2)); }
@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; }
protected boolean slotsContainNumberSlotWithValue(Map<String, Slot> slots, String value) { Slot slot = slots.get(SlotNames.NUMBER_SLOT_NAME); return (slot != null) && slot.getValue().equals(value); }
@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(); } }