Subscribe rss
Blog categories
All | Backendless features
How to Build a Game Skill for Alexa Using Codeless
July 2, 2019 by Stanislaw Grin

Build Alexa Skill Game with Codeless

In a previous article (Developing a Custom Skill for an Alexa Game), we showed you how to build a custom Alexa skill using Backendless and our Amazon Alexa Skill SDK. We made a game called Guess My Number that was played using Alexa. Now, we are going to show how to make the same game using our Codeless feature – in other words – without any coding!

You can read more about what Codeless is and how it works here.

We will assume that you are already familiar with previous article, so we will not explain how the logic works but instead will focus on how to implement this logic using Codeless. Also, we assume that you have installed the Amazon Alexa SDK from the Backendless Marketplace in your app.

On the following screenshot, you can see the final look of the API service that we will build during this article.

Build Alexa Skill Game with Codeless

In the above screenshot, you can see some of the custom functions that we need to create before making service logic. Basically, in this article we are doing the same thing we did via JavaScript API Service in the previous article: first we verify the Alexa request, then check each possible intent and call the appropriate handler for it, and in the end return the response to Alexa.

So, the first function we need to create is the getResponse  function. It should accept three optional parameters — speachOutput , reprompt  and shouldEndSession . Go to the functions menu in the Codeless Browser section of Backendless Console and click “Add New”.

Codeless Browser

Let’s create the same logic as shown in the following screenshots:

// getResponse

Codeless getResponse Function

Here you can see another custom function that you don’t have yet – getSSMLSpeech . Let’s create it and use it here. Do not forget to save all logic you write by clicking on green Save button in the top right corner.

// getSSMLSpeech

Codeless getSSMLSpeech Function

Next we need to create some other handy functions. Replicate the functions below:

// getSessionId

Codeless getSessionId Function

// getSessionAttributes

Codeless getSessionAttributes Function

// getPersistentAttributes

Codeless getPersistentAttributes Function

// setSessionAttributes

(By default, “time to live” is 7200 seconds.)

Codeless setSessionAttributes Function

Note that some functions do not return anything. You can make it by clicking on the gear icon in the top left part of Function block.

// setPersistentAttributes

Codeless setPersistentAttributes Function

Now we need to create our handler checkers and handlers. Logically, it is simply a copy of the logic we implemented in the previous article using JavaScript.

// canHandleLaunchRequest

Codeless canHandleLaunchRequest Function

// canHandleExitIntent

Codeless canHandleExitIntent Function

// canHandleSessionEndedRequest

Codeless canHandleSessionEndedRequest Function

// canHandleHelpIntent

Codeless canHandleHelpIntent Function

// canHandleYesIntent

Codeless canHandleYesIntent Function

// canHandleNoIntent

Codeless canHandleNoIntent Function

// canHandleNumberGuessIntent

Codeless canHandleNumberGuessIntent Function

To make it easier to use, we suggest you wrap the Alexa Skills SDK’s verifyRequest function in our custom request. To find “verifyRequest”, use the search box at the top.

// verifyRequest

Codeless verifyRequest Function for Alexa Skill

And that’s it! We have created all necessary functions to build our API service. Let’s put it all together.

Go to Browser menu in Codeless section and click Add New under API Services menu.

Service name: GuessMyNumber
Method name: guessMyNumber
REST Operation: POST
Route: /
Method Parameters: req (type of Any Object and is required)

Now we have an empty service. The first thing we have to do is to verify request. Then, using the Alexa Skills SDK, obtain intent name and request type, then set result to default response. Next, in the try/catch block, step by step using if/else blocks, check each request with canHandle… functions and if the check passes, set the result to the result of the handle… function. Return the result in the end from the service method.

Build Alexa Skill Game with Codeless

Now you have complete service without any coding that you may deploy to Backendless and check using one of the Alexa test tools – or Test tab in the Amazon Developer Console. 

As you can see, it’s pretty easy to build your own custom skills for Alexa with Backendless.

Have fun and Happy Coding!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+