我正在迁移到Java的ASK SDK v2,在SDK v2中,每个onLaunch
,onSessionEnded
和ontIntent
情况都被隔离到不同的处理程序中。
如何将我的输入传递到handle(HandlerInput input)
的{{1}},以及如何从我的代码中调用LaunchRequestHandler
的{{1}}?
此外,在V2中,handle(HandlerInput input)
类已被删除,因此如何创建LaunchRequestHandler
以获取SpeechletRequestEnvelope
和requestEnvelope
的详细信息?
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
方法?
答案 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()