@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(); }
/** * Dispatches a progressive response. * * @param requestId * the unique request identifier * @param text * the text of the progressive response to send * @param systemState * the SystemState object * @param apiEndpoint * the Alexa API endpoint */ private void dispatchProgressiveResponse(String requestId, String text, SystemState systemState, String apiEndpoint) { DirectiveEnvelopeHeader header = DirectiveEnvelopeHeader.builder().withRequestId(requestId).build(); SpeakDirective directive = SpeakDirective.builder().withSpeech(text).build(); DirectiveEnvelope directiveEnvelope = DirectiveEnvelope.builder() .withHeader(header).withDirective(directive).build(); if(systemState.getApiAccessToken() != null && !systemState.getApiAccessToken().isEmpty()) { String token = systemState.getApiAccessToken(); try { directiveService.enqueue(directiveEnvelope, apiEndpoint, token); } catch (Exception e) { log.error("Failed to dispatch a progressive response", e); } } }
Session session = requestEnvelope.getSession(); SystemState systemState = getSystemState(requestEnvelope.getContext()); String apiEndpoint = systemState.getApiEndpoint();
String apiAccessToken = systemState.getApiAccessToken(); String deviceId = systemState.getDevice().getDeviceId(); String apiEndpoint = systemState.getApiEndpoint();
public SpeechletResponse dispatchRequest(SpeechletRequestEnvelope envelope) { boolean hasDisplay = system.getDevice().getSupportedInterfaces().isInterfaceSupported(DisplayInterface.class);
public SpeechletResponse dispatchRequest(SpeechletRequestEnvelope envelope) { boolean hasDisplay = system.getDevice().getSupportedInterfaces().isInterfaceSupported(DisplayInterface.class);