如何在Java版Alexa SDK V2中将Input传递给handle()以及如何调用LaunchRequestHandler的handle()?

时间:2018-12-24 17:24:04

标签: alexa alexa-skills-kit alexa-skill alexa-app

我正在迁移到Java的ASK SDK v2,在SDK v2中,每个onLaunchonSessionEndedontIntent情况都被隔离到不同的处理程序中。

问题:

如何将我的输入传递到handle(HandlerInput input)的{​​{1}},以及如何从我的代码中调用LaunchRequestHandler的{​​{1}}?

此外,在V2中,handle(HandlerInput input)类已被删除,因此如何创建LaunchRequestHandler以获取SpeechletRequestEnveloperequestEnvelope的详细信息?

Request

呼叫地点:

Session

如何将public class LaunchRequestHandler implements RequestHandler { @Override public boolean canHandle(HandlerInput input) { return input.matches(Predicates.requestType(LaunchRequest.class)); } @Override public Optional<Response> handle(HandlerInput input) { String speechText = "Welcome to the Alexa Skills Kit, you can say hello"; return input.getResponseBuilder() .withSpeech(inputString) .withSimpleCard("HelloWorld", inputString) .withReprompt(inputString) .build(); } } 传递到String body = myO ject.getAdditionalProperties().get("request").toString(); byte[] myRequest = URLDecoder.decode(body, StandardCharsets.UTF_8.name()).getBytes(); 的{​​{1}}以及如何调用相同的myRequest方法?

1 个答案:

答案 0 :(得分:0)

第二个与请求和会话详细信息有关的问题

public ResponseEntity<String> handleAlexaRequest(HttpServletRequest request) {

    RequestEnvelope requestEnvelope;
    ServletRequest servletRequest;

    byte[] serializedRequestEnvelope;

    try {
        serializedRequestEnvelope = IOUtils.toByteArray(request.getInputStream());
        RequestEnvelope deserializedRequestEnvelope = this.serializer.deserialize(new String(serializedRequestEnvelope, StandardCharsets.UTF_8), RequestEnvelope.class);

        servletRequest = new ServletRequest(request,serializedRequestEnvelope,deserializedRequestEnvelope);

        requestEnvelope = verifier.verify(alexaHttpRequest);

    }


    requestEnvelope.getRequest();
    requestEnvelope.getSession()