/ F @ DE @D@ 3C @D C DC 9 @F 1 D@ E 9 @E @F D C @ 99 4 / 020 # #
A E ) ) ( )(
) (
• 1 .1 1 ) - - • 1 1 3 (- - 3 ( • 1 -2 1 )
( ) ) ) dependencies { implementation "org.jetbrains.kotlin:kotlin-script-util:$kotlinVersion" implementation "org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion" implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion” } Add the dependencies
( ) ) ) org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory add a file javax.script.ScriptEngineFactory in “resources/META-INF/services/”
( ) ) ) private val scriptEngine: ScriptEngine = ScriptEngineManager().getEngineByExtension("kts")!! Get the ScriptEngine
)( ( ( ( val x = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 """) x=?x=null
)( ( ( ( val y = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 val y = x(2) """) y=?y=null
)( ( ( ( val x = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 x(2) """) x=?x=5
)( ( ( ( val value = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 val x = x(2) var y = x x y = x(7) """) value=?value=null
)( ( ( ( val value = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 var x = x(2) var y = x x = 10 x y + 1 """) value=?value=6
• , ( , ) (
/ . - . . -
val client: ClovaClient = clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() //SDK only supports Jackson now launchHandler { request, session -> simpleResponse(message = " ") } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
val client: ClovaClient = clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() launchHandler { request, session -> simpleResponse(message = “ ”) // Helper function } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
val client: ClovaClient = clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() launchHandler { request, session -> simpleResponse(message = " ") } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
val client: ClovaClient = clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() launchHandler { request, session -> simpleResponse(message = " ") } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
@Dsl fun ClovaClient.launchHandler(handler: RequestHandler<LaunchRequest>) { launchHandler = handler } @Dsl fun ClovaClient.intentHandler(handler: RequestHandler<IntentRequest>) { intentHandler = handler } @Dsl fun ClovaClient.sessionEndedHandler(handler: RequestHandler<SessionEndedRequest>) { sessionEndedHandler = handler }
typealias RequestHandler<T> = suspend (T, Session) -> ClovaExtensionResponse launchHandler { request, session -> simpleResponse(message = “ ”) ! // return ClovaExtensionResponse }
//requestBody and response are json strings val response = client.handleClovaRequest(requestBody, request.headers().asHttpHeaders())
• • • - -
Is it possible to use Kotlin script to create ClovaClient??
val clovaClient = scriptEngine.eval(""" clovaClient(applicationId = "APPLICATION_ID") { launchHandler { ... } intentHandler { ... } sessionEndedHandler { ... } } """)
val clovaClient = scriptEngine.eval(""" import com.linecorp.clova.extension.client.* import com.linecorp.clova.extension.model.util.* import com.linecorp.clova.extension.model.response.* import com.linecorp.clova.extension.converter.jackson.JacksonObjectMapper clovaClient(applicationId = "YOUR APPLICATION ID") { launchHandler { ...} intentHandler { ... } sessionEndedHandler { ... } } """)
val clovaClient = scriptEngine.eval( """ import … clovaClient(applicationId = "APPLICATION_ID") { … } """) … val response = client.handleClovaRequest(requestBody, request.headers().asHttpHeaders())
val clovaClient = scriptEngine.eval( """ import … clovaClient(applicationId = "APPLICATION_ID") { … } """) … val response = client.handleClovaRequest(requestBody, request.headers().asHttpHeaders()) ! Input the script from web
/ .
• : . • -
!

Use Kotlin scripts and Clova SDK to build your Clova extension

  • 1.
    / F @DE @D@ 3C @D C DC 9 @F 1 D@ E 9 @E @F D C @ 99 4 / 020 # #
  • 2.
  • 3.
  • 5.
    • 1 .11 ) - - • 1 1 3 (- - 3 ( • 1 -2 1 )
  • 6.
    ( ) )) dependencies { implementation "org.jetbrains.kotlin:kotlin-script-util:$kotlinVersion" implementation "org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion" implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion” } Add the dependencies
  • 7.
    ( ) )) org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory add a file javax.script.ScriptEngineFactory in “resources/META-INF/services/”
  • 8.
    ( ) )) private val scriptEngine: ScriptEngine = ScriptEngineManager().getEngineByExtension("kts")!! Get the ScriptEngine
  • 9.
    )( ( ( ( valx = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 """) x=?x=null
  • 10.
    )( ( ( ( valy = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 val y = x(2) """) y=?y=null
  • 11.
    )( ( ( ( valx = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 x(2) """) x=?x=5
  • 12.
    )( ( ( ( valvalue = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 val x = x(2) var y = x x y = x(7) """) value=?value=null
  • 13.
    )( ( ( ( valvalue = scriptEngine.eval( """ fun x(input: Int): Int = input + 3 var x = x(2) var y = x x = 10 x y + 1 """) value=?value=6
  • 14.
    • , (, ) (
  • 16.
    / . -. . -
  • 17.
    val client: ClovaClient= clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() //SDK only supports Jackson now launchHandler { request, session -> simpleResponse(message = " ") } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
  • 18.
    val client: ClovaClient= clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() launchHandler { request, session -> simpleResponse(message = “ ”) // Helper function } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
  • 19.
    val client: ClovaClient= clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() launchHandler { request, session -> simpleResponse(message = " ") } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
  • 20.
    val client: ClovaClient= clovaClient(applicationId = "YOUR APPLICATION ID") { objectMapper = JacksonObjectMapper() launchHandler { request, session -> simpleResponse(message = " ") } intentHandler { request, session -> val value = request.intent.slots["number"]?.value simpleResponseWithReprompt( message = " ${value} ", repromptMessage = " ” ) } sessionEndedHandler { request, session -> simpleResponse(message = " ") } }
  • 21.
    @Dsl fun ClovaClient.launchHandler(handler: RequestHandler<LaunchRequest>){ launchHandler = handler } @Dsl fun ClovaClient.intentHandler(handler: RequestHandler<IntentRequest>) { intentHandler = handler } @Dsl fun ClovaClient.sessionEndedHandler(handler: RequestHandler<SessionEndedRequest>) { sessionEndedHandler = handler }
  • 22.
    typealias RequestHandler<T> =suspend (T, Session) -> ClovaExtensionResponse launchHandler { request, session -> simpleResponse(message = “ ”) ! // return ClovaExtensionResponse }
  • 23.
    //requestBody and responseare json strings val response = client.handleClovaRequest(requestBody, request.headers().asHttpHeaders())
  • 24.
  • 25.
    Is it possibleto use Kotlin script to create ClovaClient??
  • 27.
    val clovaClient =scriptEngine.eval(""" clovaClient(applicationId = "APPLICATION_ID") { launchHandler { ... } intentHandler { ... } sessionEndedHandler { ... } } """)
  • 28.
    val clovaClient =scriptEngine.eval(""" import com.linecorp.clova.extension.client.* import com.linecorp.clova.extension.model.util.* import com.linecorp.clova.extension.model.response.* import com.linecorp.clova.extension.converter.jackson.JacksonObjectMapper clovaClient(applicationId = "YOUR APPLICATION ID") { launchHandler { ...} intentHandler { ... } sessionEndedHandler { ... } } """)
  • 29.
    val clovaClient =scriptEngine.eval( """ import … clovaClient(applicationId = "APPLICATION_ID") { … } """) … val response = client.handleClovaRequest(requestBody, request.headers().asHttpHeaders())
  • 30.
    val clovaClient =scriptEngine.eval( """ import … clovaClient(applicationId = "APPLICATION_ID") { … } """) … val response = client.handleClovaRequest(requestBody, request.headers().asHttpHeaders()) ! Input the script from web
  • 31.
  • 32.
  • 33.