[9/3 @ Sapporo] LINE BOOT AWARDS --Clova Skill Hands-on co-sponsored by Java user group Hokkaido (Java Do) is also attended by slapstick participants. It was a great success. Thank you to everyone who cooperated in the event.
I used node.js for hands-on, but since JUG co-sponsored it, I listened to hands-on and did almost the same content Clova CEK SDK Java. It was implemented with -sdk-java).
I'll leave this implementation note for this article.
Here, the following configuration is realized.
[You] ----- [Clova] ----- [EchoHandler class on Spring Boot]
Mr. Nobisuke's How to start skill development with Clova CEK ~ Start development with Node.js ~ used as a hands-on text / #% E4% BD% BF% E3% 81% 84% E5% A7% 8B% E3% 82% 81% E3% 81% AE% E7% 94% B3% E8% AB% 8B)
3.Application to start using
4.Creating an interaction model
Intents and slots
slot
Intent
5.Build interaction model
Proceed in the same way.
Make a note of the intent name CurreySearchIntent
created here, as it is important.
In Nobisuke's document, the Clova skill is implemented in node.js, but here it is implemented using Java (Spring Boot).
Access Spring Initializr and set the following items.
--Spring Boot version: 2.0.4
clova_handson
--Search for dependencies: Web
, Devtools
(add one by one) Download clova.zip with the Generate Project
button.
Extract clova.zip and open it as a Maven project in an IDE (IntelliJ, Eclipse, Netbeans, etc.).
Add the Clova CEK SDK Java dependency between <dependencies>
~ </ dependencies>
in pom.xml,
pom.xml
<dependencies>
(Omitted)
<dependency>
<groupId>com.linecorp.clova</groupId>
<artifactId>clova-extension-boot-web</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
application.properties
Set the file path of the server that accepts requests from Clova.
application.properties
cek.api-path=/clova
This will configure https: // xxxx ... / clova
to accept POST requests from Clova.
(You can also set cek.client.default-locale
etc. if needed)
Create a request handler class to handle POST requests from Clova.
This class is based on [Clova CEK SDK Java Implementation Example](https://github.com/line/clova-cek-sdk-java/blob/master/samples/echo/src/main/java/com/linecorp/ It is made by referring to clova / extension / sample / hello / EchoHandler.java).
EchoHandler.java
package com.example.clova;
import com.linecorp.clova.extension.boot.handler.annotation.*;
import com.linecorp.clova.extension.boot.message.response.CEKResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Optional;
import static com.linecorp.clova.extension.boot.message.speech.OutputSpeech.text;
@CEKRequestHandler
public class EchoHandler {
private static final Logger log = LoggerFactory.getLogger(EchoHandler.class);
@LaunchMapping
CEKResponse handleLaunch() {
return CEKResponse.builder()
.outputSpeech(text("Find a curry shop."))
.shouldEndSession(false)
.build();
}
@IntentMapping("CurreySearchIntent")
CEKResponse handleRepeatIntent(@SlotValue Optional<String> area) {
String outputSpeechText = area
.map(this::callbackShop)
.orElse("I couldn't hear it.");
return CEKResponse.builder()
.outputSpeech(text(outputSpeechText))
.shouldEndSession(false)
.build();
}
private String callbackShop(String inArea) {
switch (inArea) {
case "Akihabara":
return inArea + "The recommended curry shop is Fujiyama Dragon Curry.";
case "Kanda":
return inArea + "The recommended curry shop is Kyoeidou.";
default:
return "I'm sorry, I didn't understand.";
}
}
@IntentMapping("Clova.CancelIntent")
CEKResponse handleCancelIntent() {
return CEKResponse.builder()
.outputSpeech(text("The search for curry shop will end."))
.shouldEndSession(true)
.build();
}
@SessionEndedMapping
CEKResponse handleSessionEnded() {
log.info("The curry shop search skill has ended.");
return CEKResponse.empty();
}
}
I will explain some important points.
@IntentMapping
is the process (method) corresponding to the custom intent name / built-in intent name. ) Is an annotation.
In this example, the method handleCancelIntent ()
with @IntentMapping (Clova.CancelIntent)
corresponds to the built-in intent Clova.CancelIntent
when the skill is canceled (finished).
In addition, the method handleRepeatIntent (@SlotValue ...)
with@IntentMapping (CurreySearchIntent)
corresponds to the question" Tell me the curry shop in Akihabara (area) "created in the preparation. To do.
The argument @SlotValue
indicates that the value of the slot is the argument passed. In this example, the value of the ʻarea` slot of "Tell me the curry shop in Akihabara (area)" is passed.
The CEKResponse
class set in the return value represents Clova's response. Instantiate with builder.
ʻOutputSpeechis the string to reply to.
shouldEndSession` indicates whether the skill should be terminated with true / false.
@LaunchMapping
is an annotation given to the corresponding method when the skill is started.
@SessionEndedMapping
is an annotation given to the corresponding method at the end of the skill.
Run the Spring Boot ClovaApplication class.
Nobisuke's [How to start skill development with Clova CEK ~ Start development with Node.js ~](https://dotstud.io/blog/clova-cek-nodejs-tutorial/#%E4%BD%BF % E3% 81% 84% E5% A7% 8B% E3% 82% 81% E3% 81% AE% E7% 94% B3% E8% AB% 8B)
7.Confirm communication without hosting with ngrok
10.Actual machine test
Proceed in the same way (ngrok can be downloaded and executed from the home site without using npm, or homebrew for macOS. Is also good).
--You: "Hey Clover" --Clova: "Pon (LED glows green)" --You: "Launch curry information" --Clova: "Find a curry shop." (← written in Java) --Clova: "Pon (LED glows green)" --You: "Tell me about the curry shop in Akihabara" --Clova: "The recommended curry shop in Akihabara is Fujiyama Dragon Curry." (← Described in Java)
If you can communicate like this, you are successful.
Just like line-bot-sdk-java, which creates a Bot (Messaging API), Clova also has Clova CEK SDK Java It seems that you can easily create Clova skills in Java.
The corresponding slot (Sapporo, Chitose) and the response message are different, but the equivalent source code is placed in gishi-yama / ClovaSample. There is.
I would like to continue to challenge how to cooperate with Bot.
** Promotion **
Hands-on material for making LINE Bot in Java is now available!
Recommended Posts