I tried to create Alexa skill in Java

Environmental preparation

Install plugin to use AWS Lambda from Eclipse Please refer to this as it is introduced in the ↓. [AWS Toolkit for Eclipse --Yamamugi] (https://www.yamamanx.com/aws-toolkit-eclipse/)

Rough flow

  1. Create a skill in the Alexa Developer Portal --Determine the skill name --Select a skill model --Determine the name to call the skill --Add intents (create intent slots as needed) --Save and build the model
  2. Create a Lambda function that will be the brain of your Alexa skill --Clone sample skills from GitHub to Eclipse --Import project on Eclipse --Rewrite the source for the intent created in the Alexa developer portal --Upload Lambda function on AWS --Linking Alexa skills from Lambda
  3. Link Alexa skills to Lambda functions
  4. Test implementation

Creating Alexa skills

First, [Amazon Developer Portal] Go to (https://developer.amazon.com/en/) and go to the Alexa skill creation screen.

スクリーンショット 2018-05-31 23.40.04.png

スクリーンショット 2018-05-31 23.40.25.png スクリーンショット 2018-05-31 23.40.49.png

image.png

Decide on a skill name. Please use Japanese as the language.

image.png

This time select a custom skill.

image.png

Decide on a call name. It is the part of ** "○○" ** of "Alexa, open ** ○○ **" and "△△ with ** ○○ **".

image.png

Make an intent. Corresponds to the ** "△△" ** part of "○○ de ** △△**

image.png

For the time being, I made an intent called ** "Hello Intent" **.

d8d9499b6ff2b28c5488cf0243e66221.png

Next, we will set utterance examples for HelloIntent, I'm going to use the intent slot as well, so I set an intent slot called ** "Location" ** and I'm going to use Amazon's standard slot ** AMAZON.City **. ** {Location} ** is a common place name already registered on Amazon. Maybe there is also Osaka city. I don't know.

de046866c6b159c335d2ee183c9118d0.png

After that, entwin the intent slot you made earlier with the sample utterance, Register some utterance examples that the user is likely to say. After registering to some extent, press ** "Save Model" ** and ** "Build Model" **. Once the build is successful, work on the Alexa Admin Portal is interrupted here.

Creating a Lambda function

This time, using the AWS Toolkit for Eclipse installed first, Create a Lambda function from Eclipse.

Since we are using the Java sample project on GitHub, [here] Clone from (https://github.com/alexa/skill-samples-java) to Eclipse. After cloning, import only the helloworld project and edit HelloWorldSpeechlet.java.

HelloWorldSpeechlet.java(Line 49)



    @Override
    public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) {
        IntentRequest request = requestEnvelope.getRequest();
        log.info("onIntent requestId={}, sessionId={}", request.getRequestId(),
                requestEnvelope.getSession().getSessionId());
        //Get intent from request
        Intent intent = request.getIntent();
        String intentName = (intent != null) ? intent.getName() : null;
        //Get the slot value from the intent
        Slot slot = intent.getSlot("Location");
        String slotValue = slot.getValue();

        if ("HelloIntent".equals(intentName)) {
            //Change to pass the slot value as an argument
            return getHelloResponse(slotValue);
        } else if ("AMAZON.HelpIntent".equals(intentName)) {
            return getHelpResponse();
        } else {
            return getAskResponse("HelloWorld", "This is unsupported.  Please try something else.");
        }
    }

HelloWorldSpeechlet.java(Line 93)


 private SpeechletResponse getHelloResponse(String slotValue) {

       String speechText = null;
       if(slotValue != null && slotValue.contains("Osaka")) {
       //To the value of the slot"Osaka"If included
           speechText = "Oops, is it profitable?";
       } else {
       //Otherwise
           speechText = "Hello, how are you?";
       }
       // Create the Simple card content.
       SimpleCard card = getSimpleCard("HelloWorld", speechText);

       // Create the plain text output.
       PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText);

       return SpeechletResponse.newTellResponse(speech, card);
   }

Upload Lambda function to AWS

Right-click HelloWorldSpeechlet.java in the Eclipse Project Explorer and select ** Upload Function to AWS Lambda ** from the Amazon Web Services. (For Windows, right-click on the helloworld project to display it.) d3c3474569fca6c150038ca66131edf4.png

Select an S3 bucket or role and proceed through the screen to complete the Lambda function upload.

Associate Alexa skills from Lambda functions

0293130e647ab290557dfb07e844b017.png

In the Lambda management screen of the AWS console, select the Lambda you uploaded earlier and select Under Add Trigger, select Alexa Skills Kit. Then, at the bottom of the screen, a form for specifying the skill ID of Alexa Skill will appear.

Return to the Alexa Developer Portal screen and Copy and paste the ** Skill ID ** starting with "amzn1.ask.skill." In the endpoint menu. Finally, press "Save" on the upper right to finish.

Link Lambda functions from Alexa skills

3bbe8b050fef15a338b89bd90c5c7bb0.png

Next, on the contrary, the ARN starting with "arn: aws: lambda:" at the top right of the Lambda function management screen, Paste it into the ** Default Region ** form in the Alexa Admin Portal endpoint menu. Finally, press ** "Save Endpoint" ** and you're ready to go.

Actually run it in a test

e6206ad13a96d39351f8665750bca0b2.png

Go to the ** Test ** menu in the Alexa admin portal Try typing "Greeting Osaka with sample skills". If Alexa answers, "Oh, are you making money?", You're successful!

Thank you for your hard work!

Recommended Posts

I tried to create Alexa skill in Java
I tried to create a Clova skill in Java
I tried to implement deep learning in Java
I tried to output multiplication table in Java
I tried metaprogramming in Java
I tried to implement Firebase push notification in Java
# 2 [Note] I tried to calculate multiplication tables in Java.
I tried to make a login function in Java
I tried to implement the Euclidean algorithm in Java
~ I tried to learn functional programming in Java now ~
I tried to find out what changed in Java 9
I tried to create an Amazon echo skill that teaches scraped information in Java using the Alexa Skills Kit (ASK)
I tried to interact with Java
I tried using JWT in Java
I tried to summarize Java learning (1)
I tried to summarize Java 8 now
I tried to create a java8 development environment with Chocolatey
I tried to convert a string to a LocalDate type in Java
I tried using Dapr in Java to facilitate microservice development
I tried to make a client of RESAS-API in Java
I tried using Elasticsearch API in Java
I tried to summarize Java lambda expressions
I tried the new era in Java
I tried to create a simple map app in Android Studio
I tried setting Java beginners to use shortcut keys in eclipse
I tried to make Basic authentication with Java
I tried to implement polymorphic related in Nogizaka.
I tried to organize the session in Rails
java I tried to break a simple block
Try to create a bulletin board in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I tried to create a LINE clone app
rsync4j --I want to touch rsync in Java.
Create JSON in Java
I tried to develop an application in 2 languages
I tried to break a block with java (1)
[Rails / JavaScript / Ajax] I tried to create a like function in two ways.
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
I tried Mastodon's Toot and Streaming API in Java
I tried to organize the cases used in programming
I tried to implement TCP / IP + BIO with JAVA
[Java 11] I tried to execute Java without compiling with javac
I tried using Google Cloud Vision API in Java
[Java] I tried to solve Paiza's B rank problem
I tried to operate SQS using AWS Java SDK
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
How to create a data URI (base64) in Java
I tried to implement Stalin sort with Java Collector
[Java] I tried to implement Yahoo API product search
I tried using an extended for statement in Java
I tried passing Java Silver in 2 weeks without knowing Java
I made roulette in Java.
Create hyperlinks in Java PowerPoint
I tried Drools (Java, InputStream)
Create Azure Functions in Java
I tried using Java REPL
I tried to verify yum-cron
I tried to create a shopping site administrator function / screen with Java and Spring
I tried to explain Effective Java 3rd edition "almost all chapters" in "easy-to-read Japanese".
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]
I tried to make an application in 3 months from inexperienced