-
Notifications
You must be signed in to change notification settings - Fork 5
CEK Request Handler
Create a Handler class in the package below the class as the entry point for starting with Spring Boot (e.g. Application.java).
@CEKRequestHandler
public class SampleHandler {
}Implement each process in this class.
All of the examples shown below should be implemented in the SampleHandler class.
Define what kind of request is handled by annotation.
The example below is a handler for LaunchRequest.
@LaunchMapping
CEKResponse handleLaunch() {
return CEKResponse.builder()
.outputSpeech(OutputSpeech.text("Launched"))
.shouldEndSession(false) // default value is true
.build();
}The return type of the handler method is always CEKResponse.
The mapping annotations are all with the following.
@SessionEndedMapping@EventMapping@IntentMapping
The parameters that can be specified in the handler method are as follows.
| type | annotation | Optional |
validation | name detection |
|---|---|---|---|---|
| Context (extends ContextProperty) |
@ContextValue(optional) |
supported | supported | supported |
| Slot |
@SlotValue(required) |
supported | not supported | supported |
| Event Payload (extends Payload) |
- | not supported | supported | - |
| Session Attribute |
@SessionValue(required) |
supported | supported (conditional) |
supported |
| Session ( CEKRequestMessage.Session) |
- | - | - | - |
SessionHolder |
- | - | - | - |
HttpServletRequest |
- | - | - | - |
EventRequest and IntentRequest have a name. You need to specify that name in annotation.
Below is a custom intent named Echo as an example.
@IntentMapping("Echo")
CEKResponse handleRepeatIntent(@SlotValue Optional<Integer> number) {
String outputSpeechText = number.map(num -> "The number is " + num + ".")
.orElse("I couldn't catch it.");
return CEKResponse.builder()
.outputSpeech(OutputSpeech.text(outputSpeechText))
.shouldEndSession(false)
.build();
}In the example above we have received a custom slot.
Custom slots can receive any type as long as Jackson ObjectMapper is convertible.
There are one of the following ways to cover patterns that can not acquire Slot.
@SlotValue Optional<Integer> numberIf the value of Slot can not be obtained, number is Optional.empty().
@SlotValue(required = false) Integer numberIf the value of Slot can not be acquired, number is null.
To occur an error if the value of Slot can not be obtained, specify it as follows.
@SlotValue Integer numberIf the value of Slot can not be acquired, MissingSlotException will occur.
The name of the Slot matches the name of the method parameter.
@SlotValue Optional<String> trackIdIn this example, the name of Slot is trackId. In addition, we support the following case format.
| Case Format | e.g. |
|---|---|
| Upper Kebab | TRACK-ID |
| Lower Kebab | track-id |
| Upper Snake | TRACK_ID |
| Lower Snake | track_id |
| Pascal | TrackId |
In any of these Case Formats, the parameter name of the handler method can be received as trackId.
If it does not match the parameter name of the handler method, specify it as follows.
@SlotValue("trackId") Optional<String> trackIdOptBelow shows handlers for events of "namespace":"AudioPlayer", "name":"PlayStarted".
@EventMapping("AudioPlayer.PlayStarted")
CEKResponse handlePlayStarted(@Valid Optional<AudioPlayerPlaybackStatePayload> payload) {
return CEKResponse.empty();
}Connect namespace and name with ..
The EventRequest payload can be received as shown in the example. The specification of Required/Optional is the same as Slots.
AudioPlayerPlaybackStatePayload inherits com.linecorp.clova.extension.boot.message.payload.Payload.
The EventRequest payload can receive whatever type it inherits Payload.
The value is mapped by Jackson ObjectMapper.
@Valid and @Validated can also be used.
Validation can be handled in the same way as Spring MVC Controller's method.
Exceptions are the same.