Aleksa

Aleksa is a small framework for writing Alexa Skills in Kotlin.

Usage

Maven

<dependency>
    <groupId>de.mkammerer.aleksa</groupId>
    <artifactId>aleksa</artifactId>
    <version>1.1</version>
</dependency>

Gradle

compile group: 'de.mkammerer.aleksa', name: 'aleksa', version: '1.1'

Features

  • Embedded Jetty server
  • Configurable via code or commandline flags
  • Supports hosting multiple skills in one application
  • Convenience functions for plaintext responses, SSML, repromts, slots, sessions and more
  • Dev mode which simplifies skill testing while development
  • TLS

Example

Speechlet implementation:

// Inherit from SpeechletV2Base, it implements SpeechletV2 and implements optional methods with empty bodies
class HelloWorldSpeechlet : SpeechletV2Base() {
    override fun onIntent(requestEnvelope: SpeechletRequestEnvelope<IntentRequest>): SpeechletResponse {
        val intent = requestEnvelope.request.intent

        return when (intent.name) {
        // use the tell function to create a tell response
            "HelloWorldIntent" -> tell("Hello world")
        // The BuiltInIntents object contains the Alexa built-in intents
            BuiltInIntents.CANCEL, BuiltInIntents.STOP -> tell("Good bye")
        // use the ask function to create an ask response
            else -> ask("What do you want to do?")
        }
    }

    override fun onLaunch(requestEnvelope: SpeechletRequestEnvelope<LaunchRequest>): SpeechletResponse {
        return ask("Hello world. What do you want to do?")
    }
}

Application:

// Start with --help to see available commandline options
fun main(args: Array<String>) {
    // Create your speechlet
    val speechlet = HelloWorldSpeechlet()
    // Add the speechlet to Aleksa
    Aleksa.addSpeechlet(path = "/helloworld", applicationId = "[Your skill id]", speechlet = speechlet)
    // Start Aleksa with the commandline parameters of your application
    Aleksa.start(args)
}

Run it with --interface 127.0.0.1 --port 8080 --dev. Now you can test the skill with curl or some other tool at the url http://127.0.0.1:8080/helloworld.

If you don’t specify any commandline arguments, it binds to all interfaces on port 8080 and without dev mode. The dev mode disables request signature checking, timestamp checking and application id verification.

For more examples see the examples directory.

Documentation

License

LGPLv3

Contributing

See contributing guidelines.

Maintainer

Moritz Kammerer (phXql)

compile "de.mkammerer.aleksa:aleksa:1.1"

Related Libraries

kxdate

Kotlin extensions for Java 8 java.time API

Last updated 3 mins ago

vavr-kotlin

Vavr integration for Kotlin

Last updated 3 mins ago

kapsule

Minimalist dependency injection library for Kotlin.

Last updated 3 mins ago

ktunits

Simple unit conversion library for Kotlin

Last updated 3 mins ago

cakeparse

Simple parser combinator library for Kotlin

Last updated 3 mins ago