public AlexaIntentRequest withSlot(final String slotName, final Object slotValue) { return withSlots(Collections.singletonList( Slot.builder() .withName(slotName) .withValue(String.valueOf(slotValue)) .build())); }
/** * 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)); }
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)