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

问题描述 投票:1回答:1

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

问题:

如何将我的输入传递到handle(HandlerInput input)LaunchRequestHandler以及如何从我的代码中调用handle(HandlerInput input)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();

如何将myRequest传递到handle()LaunchRequestHandler以及如何调用相同的handle()方法?

alexa alexa-skills-kit alexa-skill alexa-app
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()
© www.soinside.com 2019 - 2024. All rights reserved.