protected boolean slotsContainNumberSlotWithValue(Map<String, Slot> slots, String value) { Slot slot = slots.get(SlotNames.NUMBER_SLOT_NAME); return (slot != null) && slot.getValue().equals(value); }
public AlexaIntentRequest withSlot(final String slotName, final Object slotValue) { return withSlots(Collections.singletonList( Slot.builder() .withName(slotName) .withValue(String.valueOf(slotValue)) .build())); }
public AlexaIntentRequest withSlots(final List<Slot> slots) { slots.forEach(slot -> this.slots.putIfAbsent(slot.getName(), slot)); return this; }
protected boolean slotsContainNumberSlotWithValue(Map<String, Slot> slots, String value) { Slot slot = slots.get(SlotNames.NUMBER_SLOT_NAME); return (slot != null) && slot.getValue().equals(value); }
/** * 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)); }
/** * 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; }
public String translate(final String testPhrase, final String language) { final Map<String, Slot> slots = new HashMap<>(); slots.put("termA", Slot.builder().withName("termA").withValue(testPhrase).build()); slots.put("termB", Slot.builder().withName("termB").build()); slots.put("language", Slot.builder().withName("language").withValue(language).build()); final SpeechletRequestEnvelope envelope = givenIntentSpeechletRequestEnvelope("Translate", slots); final ObjectMapper mapper = new ObjectMapper(); String response = null; try { final AWSLambdaClient awsLambda = new AWSLambdaClient(); final InvokeRequest invokeRequest = new InvokeRequest() .withInvocationType(InvocationType.RequestResponse) .withFunctionName(lambdaName) .withPayload(mapper.writeValueAsString(envelope)); final InvokeResult invokeResult = awsLambda.invoke(invokeRequest); response = new String(invokeResult.getPayload().array()); } catch (JsonProcessingException e) { log.error(e.getMessage()); } return response; }
Slot.builder() .withValue(slotValue) .withName(slotName)
Slot.builder() .withValue(slotValue) .withName(slotName)
@Override public SpeechletResponse handle(final SkillRequestInformation skillRequestInformation) { Map<String,Slot> slots = skillRequestInformation.getSlots(); String intentName = skillRequestInformation.getIntentName(); Slot templateKindSlot = slots.get(SlotNames.TEMPLATE_KIND_SLOT_NAME); Slot numberSlot = slots.get(SlotNames.NUMBER_SLOT_NAME); TemplateNames name; if (IntentNames.INDIVIDUAL_TEMPLATE_INTENT.equals(intentName)) { name = TemplateNames.getNameFromKindAndNumber(templateKindSlot.getValue(), numberSlot.getValue()); } else if (IntentNames.SELECT_ITEM_INTENT.equals(intentName)) { name = TemplateNames.getNameFromNumber(numberSlot.getValue()); } else { throw new UnhandledRequestException(String.format("IndividualTemplateScreen could not handle intent: %s", intentName)); } return getIndividualTemplateScreenResponse(name); }
@Override public SpeechletResponse handle(final SkillRequestInformation skillRequestInformation) { Map<String,Slot> slots = skillRequestInformation.getSlots(); String intentName = skillRequestInformation.getIntentName(); Slot templateKindSlot = slots.get(SlotNames.TEMPLATE_KIND_SLOT_NAME); Slot numberSlot = slots.get(SlotNames.NUMBER_SLOT_NAME); TemplateNames name; if (IntentNames.INDIVIDUAL_TEMPLATE_INTENT.equals(intentName)) { name = TemplateNames.getNameFromKindAndNumber(templateKindSlot.getValue(), numberSlot.getValue()); } else if (IntentNames.SELECT_ITEM_INTENT.equals(intentName)) { name = TemplateNames.getNameFromNumber(numberSlot.getValue()); } else { throw new UnhandledRequestException(String.format("IndividualTemplateScreen could not handle intent: %s", intentName)); } return getIndividualTemplateScreenResponse(name); }
String favoriteColor = favoriteColorSlot.getValue(); session.setAttribute(COLOR_KEY, favoriteColor); speechText =
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()));