Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating an Alexa Skill w/ the newest Alexa Skill Kit for Java

1e2ead439777ff94d9b2dd11a0607e01?s=47 Wolf Paulus
October 06, 2018

Creating an Alexa Skill w/ the newest Alexa Skill Kit for Java

A short two years ago, I talked about "Bots, Amazon Echo, language user interfaces in general" the slides are still available and the code is of course still in GitHub. However, much has changed and fortunately for the better!

I still belief that Java is a very suitable language to build Alexa Skills and even if you are eventually going to host your skill in EC2 or as an AWS Lambda function, during development, Tomcat is your friend. Running and debugging your skill right on your laptop offers tremendous advantages during the development process. So lets talk about how to develop an Alexa Skill using Java and the latest Alexa Skill Kit for Java. We wil be using Java/Tomcat installed on a Laptop as our hosting platform, quickly put an SLL Cert in place, and develop an Alexa Skill.

1e2ead439777ff94d9b2dd11a0607e01?s=128

Wolf Paulus

October 06, 2018
Tweet

More Decks by Wolf Paulus

Other Decks in Programming

Transcript

  1. https://wolfpaulus.com Wolf Pauus Desert Code Camp - 2018 Creating an

    Alexa Skill with the newest 
 Alexa Skill Kit for Wolf Paulus https://wolfpaulus.com
  2. https://wolfpaulus.com •Prerequisites •Declaring an Alexa Skill •Setting up Tomcat •Setting

    up the Project (Java Web App) ASK SDK for Java
  3. https://wolfpaulus.com • Domain Name 
 (e.g. techcasita.com) • Access to

    the the domain's custom resource records 
 (e.g. via https://domains.google.com/registrar) • SSL Private Key and Certificate
 (e.g. from https://sslmate.com) Prerequisites • AWS Developer Account
 https://developer.amazon.com/ • Java 1.8.0 (or later) • Java IDE (e.g. IntelliJ ) • Tomcat 9.0.12 (or later)
  4. https://wolfpaulus.com Two options: With a default Tomcat installation, use openssl

    to create a JavaKeystore and keytool, to import the private key and certificate into the KeyStore. Reference the KeyStore-location and password in Tomcat's ./conf/server.xml file. - or - With a Tomcat-native installation, simply reference the key and cert location in Tomcat's ./conf/server.xml file. Installing an SSL Certificate https://wolfpaulus.com/java/tomcat-ssl/ https://wolfpaulus.com/java/tomcat-multiple-ssl-certificates/
  5. https://wolfpaulus.com Installing an SSL Certificate cd <location where the key

    and cert are stored> openssl pkcs12 -keypbe PBE-SHA1-3DES -certpbe PBE-SHA1-3DES -inkey alpha.techcasita.com.key -in alpha.techcasita.com.chained.crt -export -out alpha.techcasita.com.pkcs12 -name tomcat keytool -importkeystore -destkeystore tomcat.jks -srckeystore alpha.techcasita.com.pkcs12 -srcstoretype PKCS12 -alias tomcat
  6. https://wolfpaulus.com <Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443"/> <Connector port="443"

    protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" sslEnabledProtocols="TLSv1+TLSv1.1+TLSv1.2" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keyAlias="tomcat" keystoreFile="/etc/sslmate/tomcat.jks" keystorePass="myStrongPassword"/> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b"/> </Host> </Engine> </Service> ${catalina.home}/conf/server.xml
  7. https://wolfpaulus.com Installing an SSL Certificate • Install the native libraries

    (e.g.: apt-get install libtcnative-1 or brew install libtcnative) • Reference the library location in ${catalina.home}/bin/setenv.sh • Configure the certificate and key location in the server.xml document.
  8. https://wolfpaulus.com <?xml version="1.0" encoding="UTF-8"?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener"/> <Listener

    className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/> <Service name="Catalina"> <Connector port="443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" minSpareThreads="25" SSLEnabled="true" sslEnabledProtocols="TLSv1+TLSv1.1+TLSv1.2" scheme="https" secure="true" enableLookups="false" disableUploadTimeout="true" acceptCount="400" URIEncoding="UTF-8" defaultSSLHostConfigName="home_name1.domain_name1.com" SSLCertificateFile="${catalina.base}/conf/home_name1.pem" SSLCertificateKeyFile="${catalina.base}/conf/home_name1.key"> <SSLHostConfig hostName="home_name1.domain_name1.com" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,SSL_RSA_WITH_RC4_128_SHA" certificateFile="${catalina.base}/conf/home_name1.pem" certificateKeyFile="$ {catalina.base}/conf/home_name1.key"> </SSLHostConfig> </Connector> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b"/> </Host> </Engine> </Service> </Server> ${catalina.home}/conf/server.xml
  9. https://wolfpaulus.com Tomcat in Browser

  10. https://wolfpaulus.com ngrok exposes local servers behind NATs and firewalls to

    the public internet over secure tunnels. In case you cannot open a server port (a.k.a listening port) on your local network https://wolfpaulus.com/java/debugging-alexa-skills
  11. https://wolfpaulus.com https://developer.amazon.com/alexa

  12. https://wolfpaulus.com

  13. https://wolfpaulus.com

  14. https://wolfpaulus.com intention / purpose …

  15. https://wolfpaulus.com to find out what a prime number is. fo

    find out if X is a prime number intention / purpose …
  16. https://wolfpaulus.com Slot name: Definition name: IsPrime type: NUMBER Find out

    what a prime numbers Find out if X is a prime number intention / purpose …
  17. https://wolfpaulus.com intention or purpose … Sample Utterances to find out

    what a prime number is name: Definition
  18. https://wolfpaulus.com Is X a prime number Slot name: IsPrime type:

    AMAZON.NUMBER name: number Sample Utterances … {slot.name} …
  19. https://wolfpaulus.com

  20. https://wolfpaulus.com AMAZON.FallbackIntent Provides a fallback for user utterances that do

    not match any of the skill's intents. AMAZON.NavigateHomeIntent Navigate user to the device home screen. The skill session will end. intent is handled on the skills' behalf do not need to be handled in the skill’s service AMAZON.CancelIntent •cancel •never mind •forget it AMAZON.HelpIntent AMAZON.StopIntent •help •help me •can you help me •stop •off •shut up
  21. https://wolfpaulus.com { "interactionModel": { "languageModel": { "invocationName": "prime tester", "intents":

    [ { "name": "AMAZON.FallbackIntent", "samples": [] }, { "name": "AMAZON.CancelIntent", "samples": [] }, { "name": "AMAZON.HelpIntent", "samples": [] }, { "name": "AMAZON.StopIntent", "samples": [] }, { "name": "AMAZON.NavigateHomeIntent", "samples": [] }, built-in
  22. https://wolfpaulus.com { "name": "Definition", "slots": [], "samples": [ "How can

    you tell if a number is prime or composite", "How do you find out what a prime number is", "Can prime numbers be negative", "Do we have negative prime numbers", "Are negative numbers prime numbers as well", "Can a negative number be a prime number", "What does it mean to be a prime number", "What's a prime number", "What is a prime number" ] }, { "name": "IsPrime", "slots": [ { "name": "number", "type": "AMAZON.NUMBER" } ], "samples": [ "How about {number}", "What about {number}", "What is {number}", "is {number} prime", "is {number} a prime number" ] } ], "types": [] } } } custom
  23. https://wolfpaulus.com

  24. https://wolfpaulus.com

  25. https://wolfpaulus.com 108x108 and 512x512 Skill ID

  26. https://wolfpaulus.com https://github.com/alexa/alexa- skills-kit-sdk-for-java ASK SDK for Java

  27. https://wolfpaulus.com Body Templates

  28. https://wolfpaulus.com Code and Demo

  29. https://wolfpaulus.com Alexa Skill : PrimeMinister https://github.com/wolfpaulus/PrimeMinister

  30. https://wolfpaulus.com plugins { id 'java' id 'war' } group 'com.techcasita.ask'

    version '1.0' war.archiveName = 'pm.war' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { providedCompile 'javax.servlet:javax.servlet-api:3.1.0' compile group: 'com.amazon.alexa', name: 'ask-sdk-core', version: '2.6.0' compile group: 'com.amazon.alexa', name: 'ask-sdk-servlet-support', version: '2.6.0' // Logger compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1' compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1' // testing testCompile group: 'junit', name: 'junit', version: '4.12' }
  31. https://wolfpaulus.com Thanks for coming .. more at https://wolfpaulus.com