1

我正在迁移到 ASK SDK v2 for Java,在 SDK v2 中,每个onLaunch,onSessionEndedontIntentcase 都被分离到不同的处理程序中。

问题:

如何将我的输入传递给handle(HandlerInput input)ofLaunchRequestHandler以及如何从我的代码中调用handle(HandlerInput input)of ?LaunchRequestHandler

此外,在 V2 中的SpeechletRequestEnvelope类已被删除,那么如何创建requestEnvelope获取RequestSession详细信息?

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();

如何传递myRequesthandle()ofLaunchRequestHandler以及如何调用相同的handle()方法?

4

1 回答 1

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()
于 2019-11-18T14:20:11.790 回答