Security Best Practices

In our demo, we attach the AmazonDynamoDBFullAccess policy to both the Lambda function and the Cognito Identity Pool. In a full deployment of a game, we should restrict this to only allow specific access to resources in AWS. Instead of adding AmazonDynamoDBFullAccess, follow the steps below to create policies for your Lambda Function and Cognito Identity Pool.

Cognito Identity Pool Policy

  1. Navigate to the Policies section in IAM.

  2. Click Create Policy

  3. Click JSON

  4. Copy and paste the following:

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "SpecificTable",
                "Effect": "Allow",
                "Action": [
                    "dynamodb:GetItem",
                    "dynamodb:UpdateItem",
                    "dynamodb:PutItem"
                ],
                "Resource": "arn:aws:dynamodb:*:*:table/AlexaPlusUnityTest"
            }
        ]
    }
    

Note

Replace AlexaPlusUnityTest with the name of your table.

  1. Click Review Policy
  2. Give the Policy a name and click Create Policy

Attach this policy to the UnAuth IAM Role instead of the AmazonDynamoDBFullAccess policy.

Lambda Policy

  1. Navigate to the Policies section in IAM.

  2. Click Create Policy

  3. Click JSON

  4. Copy and paste the following:

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "SpecificTable",
                "Effect": "Allow",
                "Action": [
                    "dynamodb:CreateTable",
                    "dynamodb:GetItem",
                    "dynamodb:UpdateItem",
                    "dynamodb:PutItem"
                ],
                "Resource": "arn:aws:dynamodb:*:*:table/AlexaPlusUnityTest"
            }
        ]
    }
    

Note

Replace AlexaPlusUnityTest with the name of your table.

  1. Click Review Policy
  2. Give the Policy a name and click Create Policy

Attach this policy to thr Alexa Skill’s Lambda IAM Role instead of the AmazonDynamoDBFullAccess policy.

Frequently Asked Questions

On ask deploy: [Warn]: Please make sure you are in the root directory of the project.

If you get this error, please try the following:

  • Make sure the skill.json file is in the same folder where you are running the ask deploy command.
  • Make sure you are using the ASK CLI v1.

Note

The npm command to install the ASK CLI v1: npm i -g ask-cli@1

GetSessionAttributes: The service returned an error with HTTP Body: Cannot resolve destination host

If you get this error, please try the following:

  • Make sure you are connected to the internet and the Unity Project can access the internet.
  • Make sure the DynamoDB table name matches in both the Alexa Skill and Unity Project.
  • Run the Alexa Skill and make sure the DynamoDB table was created.

Configuration

AWS Configuration

For Games SDK for Alexa to fuction, we need to configure AWS to allow the Unity project to communicate to DynamoDB (The Alexa Skill’s persistant attributes).

Prerequisites

Obtain an Identity Pool ID using Amazon Cognito

  1. Log in to the Amazon Cognito Console and click Create new identity pool.
  2. Enter a name for your Identity Pool and check the checkbox to enable access to unauthenticated identities. Click Create Pool to create your identity pool.
  3. Click Allow to create the two default roles associated with your identity pool–one for unauthenticated users and one for authenticated users. These default roles provide your identity pool access to Cognito Sync and Mobile Analytics.

The next page displays code. Take note of the displayed Identity Pool ID and the Region you set up the Identity Pool in as you will need them when setting up Games SDK for Alexa.

Attach Polices to the Identity Pool default roles in AWS IAM

  1. Log in to the AWS IAM Console and click Roles in the left navigation bar.
  2. Find and click your Unauthenticated Identity Pool role. It should look similar to Cognito_[YOUR IDENTITY POOL]Unauth_Role.
  3. Click Attach Policies.
  4. Find and check the AmazonDynamoDBFullAccess policy.
  5. Click Attach Policy.

Your Identity Pool is now configured to use the required AWS services for Games SDK for Alexa to function.

Pubnub Configuration

For Games SDK for Alexa to fuction, we need to configure Pubnub to allow the Unity project to communicate with the Alexa Skill.

Prerequisites

Create a New App on Pubnub

  1. Log in to the Pubnub Admin Console and click Create new app.
  2. Enter a name for your new app. Click Create to create your new app.
  3. Click on your new app in the admin console.

The next page displays your keysets. You can create as many as you keysets as you wish, but for our purposes, we can just use the Demo Keyset.

  1. Click the Demo Keyset.
  2. Make note of both the publish and subscribe keys as you will need them when setting up Games SDK for Alexa.
  3. Enable the Stream Controller and the Storage and Playback Application add-ons.

Your Pubnub App is now configured for Games SDK for Alexa.

Setup for Unity

Let’s setup the Games SDK for Alexa for Unity!

Prerequisites

Integrating the Games SDK for Alexa into your Unity project

  1. Download Games SDK for Alexa from the Unity Asset Store.
  2. Add the asset package to your Unity project.
  3. Make sure everything is checked and click Import.

That’s it! However, in order to handle the communication to and from Alexa, you need to create your own script to initalize the manager. See a Tutorial for a more in-depth implementation.

Setup for Alexa Skills

Now that we have configured our Unity workspace, it’s time to set up the Alexa Skill!

Prerequisites

  • A suitable Node.js development environment. The ASK SDK v1 for Node.js requires Node 4.3.2 or above.

Integrating the Games SDK for Alexa into your Alexa Skill

  1. Navigate to your skill fuction in an command prompt or terminal

  2. Install the AlexaPlusUnity package into yor skill’s function: npm install alexaplusunity

  3. Include the package in your skill with:

    var alexaPlusUnityClass = require('alexaplusunity');
    
  4. Create an instance of the class with:

    var alexaPlusUnity = new alexaPlusUnityClass("<YOUR_PUBNUB_PUB_KEY>", "<YOUR_PUBNUB_SUB_KEY>", true); //Third parameter enables verbose logging
    

That’s it! However, in order to handle the communication to and from your game, you need to use the script’s methods. See a Tutorial or the package page for more in-depth information.

Introduction

Looking to learn how to use the the Games SDK for Alexa with an in-depth example? You’ve come to the right place!

In this tutorial, we will walk through the steps to create a basic game in which we’ll be able to manipulate a light with both our keyboard and voice, all while having Alexa remain aware of the game’s state.



Creating the Unity Project

Let’s setup the Unity Project!

If you get lost or want to see the final project, the light control demo scene is located in Games SDK for Alexa\Examples. You will need to create a project and add the Games SDK for Alexa asset package from the Unity Asset Store to gain access to this folder.

Prerequisites

Creating the project

  1. Open Unity.
  2. Create a new 3D project.
  3. Add a cube to the SampleScene (GameObject -> 3D Object -> Cube).
  4. Add a Rididbody Component to the newly created cube (With the cube selected in the hierarchy, Component -> Add -> Rididbody. Uncheck Use Gravity)
  5. Click on the Main Camera and change the Y position transform value to 0.

Integrating the Games SDK for Alexa Package

  1. Download Games SDK for Alexa from the Unity Asset Store.
  2. Add the asset package to your Unity project.
  3. Make sure everything is checked and click Import.

You should now see a new folder in you Assets folder, Games SDK for Alexa.

Adding the LightControl script into the Unity project

  1. With your project open, create a new script (Assets -> Create -> C# Script) and name it LightControl.

  2. Open your LightControl script by double-clicking it.

  3. Delete everything in the script.

  4. Copy and paste the code below into your LightControl script:

    using Amazon;
    using Amazon.DynamoDBv2.Model;
    using AmazonsAlexa.Unity.AlexaCommunicationModule;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class LightControl : MonoBehaviour
    {
        //Step 5: Add variables below
    
    
        // Use this for initialization
        void Start () {
            //Step 6: Add Games SDK for Alexa initialization
    
        }
    
        public void ConfirmSetup(GetSessionAttributesEventData eventData)
        {
            //Step 7: Notify the skill that setup has completed by updating the skills persistant attributes (in DynamoDB)
    
        }
    
        void Update() {
            //Step 8: Add Keyboard event listener (For "gameplay")
    
        }
    
        public void HandleSpacePress()
        {
            //Step 9: Handle the keyboard input
    
        }
    
        //Callback for when a message is recieved
        public void OnAlexaMessage(HandleMessageEventData eventData)
        {
            //Step 10: Listen for new messages from the Alexa skill
    
        }
    
        private void GetObjectInDirection(string type, string message)
        {
            //Step 11: Get the object in a specific direction (Note: For this demo, there is only one object, the cube)
    
        }
    
        public void UpdateLight(string type, string value, GetSessionAttributesEventData eventData)
        {
            //Step 12: Update the light based on the incoming message, then save the state of the light through the skill's session attributes
    
        }
    
        public void SetAttributesCallback(SetSessionAttributesEventData eventData)
        {
            //Step 13: Callback for when session attributes have been updated
    
        }
    
    
        public void OnMessageSent(MessageSentEventData eventData)
        {
            //Step 14: Callback for when a message is sent
    
        }
    }
    

The above code is our skeleton for our script. We will fill this skeleton step by step. The steps below corrospond to the step numbers in the skeleton. Place the code for each of the below steps under their step number in the skeleton.

Note

There may be IDE errors as we continue, but those will be resolved at the end when the skeleton is complete.

  1. Define the class variables:

    public string publishKey;
    public string subscribeKey;
    public string channel;
    public string tableName;
    public string identityPoolId;
    public string AWSRegion = RegionEndpoint.USEast1.SystemName;
    public bool debug = false;
    public GameObject lightCube;
    public GameObject camera;
    
    private Dictionary<string, AttributeValue> attributes;
    private AmazonAlexaManager alexaManager;
    

These variables are necessary to preform initialization and enable reusablity of the Alexa Manager within our LightControl script.

  1. Initialize the Alexa Manager:

    UnityInitializer.AttachToGameObject(gameObject);
    AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
    alexaManager = new AmazonAlexaManager(publishKey, subscribeKey, channel, tableName, identityPoolId, AWSRegion, this.gameObject, OnAlexaMessage, null, debug); //Initialize the Alexa Manager
    
  2. Tell the skill that the game has completed setup and is ready to play:

    attributes = eventData.Values;
    attributes["SETUP_STATE"] = new AttributeValue { S = "COMPLETED" }; //Set SETUP_STATE attribute to a string, COMPLETED
    alexaManager.SetSessionAttributes(attributes, SetAttributesCallback);
    
  3. Listen for a spacebar keypress:

    if (Input.GetKeyDown(KeyCode.Space))
    {
        Debug.Log("Space pressed");
        HandleSpacePress();
    }
    
  4. Update the light to blue when the spacebar is pressed:

    if (!PlayerPrefs.HasKey("alexaUserDynamoKey")) //If the AlexaUserId has not been recieved from Alexa (If the user has not opened the skill)
    {
        Debug.LogError("'alexaUserDynamoKey' not found in PlayerPrefs. We must establish connection from Alexa to set this. Please open the skill to set the 'AlexaUserId' PlayerPref.");
    } else {
        alexaManager.GetSessionAttributes((result) =>
        {
            if (result.IsError)
                Debug.LogError(result.Exception.Message);
            UpdateLight("Color", "blue", result);
        });
    }
    
  5. Listen for new messages from the Alexa skill:

    Debug.Log("OnAlexaMessage");
    
    Dictionary<string, object> message = eventData.Message;
    
    //Get Session Attributes with in-line defined callback
    switch (message["type"] as string)
    {
        case "AlexaUserId":
            Debug.Log("AlexaUserId: " + message["message"]);
            alexaManager.alexaUserDynamoKey = message["message"] as string;
            break;
    }
    
    alexaManager.GetSessionAttributes((result) =>
    {
        if (result.IsError)
            Debug.LogError(eventData.Exception.Message);
    
        switch (message["type"] as string)
        {
            case "AlexaUserId":
                ConfirmSetup(result);
                break;
            case "Color":
                Debug.Log("Requested Light Color: " + message["message"]);
                UpdateLight(message["type"] as string, message["message"] as string, result);
                break;
            case "State":
                Debug.Log("Requested Light State: " + message["message"]);
                UpdateLight(message["type"] as string, message["message"] as string, result);
                break;
            case "GetObject":
                Debug.Log("Requested object direction: " + message["message"]);
                GetObjectInDirection(message["type"] as string, message["message"] as string);
                break;
            default:
                break;
        }
    });
    
  6. Get object in a direction:

    RaycastHit hit;
    Dictionary<string, string> messageToAlexa = new Dictionary<string, string>();
    Vector3 forward = camera.transform.forward * 10;
    Vector3 backward = camera.transform.forward * -10;
    Vector3 right = camera.transform.right * 10;
    Vector3 left = camera.transform.right * -10;
            Vector3 up = camera.transform.up * 10;
            Vector3 down = camera.transform.up * -10;
    
            Vector3 direction = forward;
    
            switch(message) {
                    case "forward":
                            direction = forward;
                            break;
                    case "backward":
                            direction = backward;
                            break;
                    case "right":
                            direction = right;
                            break;
                    case "left":
                            direction = left;
                            break;
                    case "up":
                            direction = up;
                            break;
                    case "down":
                            direction = down;
                            break;
            }
    
    messageToAlexa.Add("object", "nothing");
    
    if (Physics.Raycast(camera.transform.position, direction, out hit, (float)15.0))
    {
        if (hit.rigidbody)
        {
            messageToAlexa.Remove("object");
            messageToAlexa.Add("object", hit.rigidbody.name);
        }
    }
    
    alexaManager.SendToAlexaSkill(messageToAlexa, OnMessageSent);
    
  7. Update the light:

    attributes = eventData.Values;
    if (type == "Color")
    {
        attributes["color"] = new AttributeValue { S = value }; //Set color attribute to a string value
    }
    else if (type == "State")
    {
        attributes["state"] = new AttributeValue { S = value }; //Set state attribute to a string value
    }
    
    switch (value)
    {
        case "white":
            lightCube.GetComponent<Renderer>().material.color = Color.white;
            break;
        case "red":
            lightCube.GetComponent<Renderer>().material.color = Color.red;
            break;
        case "green":
            lightCube.GetComponent<Renderer>().material.color = Color.green;
            break;
        case "yellow":
            lightCube.GetComponent<Renderer>().material.color = Color.yellow;
            break;
        case "blue":
            lightCube.GetComponent<Renderer>().material.color = Color.blue;
            break;
        case "on":
            lightCube.GetComponent<Renderer>().enabled = true;
            break;
        case "off":
            lightCube.GetComponent<Renderer>().enabled = false;
            break;
    }
    alexaManager.SetSessionAttributes(attributes, SetAttributesCallback);  //Save Attributes for Alexa to use
    
  8. Let’s be notified when there is a error setting the attributes:

    Debug.Log("OnSetAttributes");
    if (eventData.IsError)
        Debug.LogError(eventData.Exception.Message);
    
  9. Let’s be notified when there is a error sending a message:

    Debug.Log("OnMessageSent");
    if (eventData.IsError)
        Debug.LogError(eventData.Exception.Message);
    
  10. Be sure to save this file!

Adding the Alexa Manager GameObject in Unity

  1. Create a new Empty GameObject (GameObject -> Create Empty) and name it Amazon Alexa.
  2. With your new GameObject selected, click Add Component, type LightControl and select the LightControl script.
  3. Fill the Publish Key with the Pubnub publish key you made note of during configuration.
  4. Fill the Subscribe Key with the Pubnub subscribe key you made note of during configuration.
  5. Fill the Channel with the code sent from the Alexa skill when it launches.

Note

You will have to fill this in later, as we have not set up the Alexa skill yet.

  1. Fill the Table Name with AlexaPlusUnityTest.
  2. Fill the Identity Pool Id with the one you created during configuration.
  3. Fill the AWS Region with the one you made note of during configuration.
  4. Check the box next to Debug to enable detailed logging.
  5. Drag the Cube from the hierarchy into the box next to Light Cube.
  6. Drag the Main Camera from the hierarchy into the box next to Camera.

Wrapping Up

Aside from a few minor updates, we have finished the Unity project! Next Step: The Alexa Skill!

Creating the Alexa Skill

Let’s setup the Alexa Skill!

If you get lost, stuck, or just want a working demo right now, you can clone the complete sample project from here.

Prerequisites

Note

The npm command to install the ASK CLI v1: npm i -g ask-cli@1

Creating the Skill

  1. Clone the example skill templete: git clone https://github.com/AustinMathuw/AlexaPlusUnityExampleSkillTemplate.git
  2. Open the template in a editor such as Visual Studio code
  3. Open a command prompt or terminal and navigate to <Template Location>/lambda/custom/
  4. In the command prompt or terminal, run npm install

Example Skill Template Overview

Our Example Skill has the following Intents:

  • FlipSwitchIntent

    • Handles turning our light on and off
  • ChangeColorIntent

    • Handles changing the color of our light
  • GetColorIntent

    • Returns our lights current color
  • AMAZON.HelpIntent

    • Returns help message to guide the user
  • AMAZON.CancelIntent

    • Closes the skill
  • AMAZON.StopIntent

    • Closes the skill

Adding Games SDK for Alexa to the Skill

The steps below corrospond to the step numbers in the skeleton. Place the code for each of the below steps under their step number in the templete code.

Note

There may be IDE errors as we continue, but those will be resolved at the end when the skeleton is complete.

  1. Our cloned templete already has the alexaplusunity node module, but we still need to include it. Open index.js under lambda/custom/ and add the following:

    var alexaPlusUnityClass = require('alexaplusunity');
    var alexaPlusUnity = new alexaPlusUnityClass("<YOUR_PUBNUB_PUB_KEY>", "<YOUR_PUBNUB_SUB_KEY>", true); //Third parameter enables verbose logging
    
  2. In our example skill, we will use state management to confirm that the user has connected to our game. Insert the code below inside of the LaunchRequestHandler:

    if(attributes.SETUP_STATE == "STARTED") {
        var launchSetUpResult = await launchSetUp(speechText, reprompt, handlerInput, attributes);
        attributes = launchSetUpResult.attributes;
        response = launchSetUpResult.response;
    }
    

In the code block above, we are checking to see if we are still in the SETUP_STATE. If we are, then run the method launchSetUp() and build our response. If we are not in the SETUP_STATE, then use the response we already built.

  1. In the next steps, we will add Games SDK for Alexa to the FlipSwitchIntent (CompletetedFlipSwitchIntentHandler). We will start by creating a payload object for the intent:

    var payloadObj = {
        type: "State",
        message: state
    };
    
  2. Then we will send the payload to our game and reply with a success or error if the payload failed to send:

    var response = await alexaPlusUnity.publishMessage(payloadObj, attributes.PUBNUB_CHANNEL).then((data) => {
        return handlerInput.responseBuilder
            .speak(speechText + reprompt)
            .reprompt(reprompt)
            .getResponse();
    }).catch((err) => {
        return ErrorHandler.handle(handlerInput, err);
    });
    
  3. Now, we will add Games SDK for Alexa to the ChangeColorIntent (CompletedChangeColorIntentHandler). We will create our payload object:

    var payloadObj = {
        type: "Color",
        message: color
    };
    
  4. Send the payload to our game and reply with a success or error if the payload failed to send:

    var response = await alexaPlusUnity.publishMessage(payloadObj, attributes.PUBNUB_CHANNEL).then((data) => {
        return handlerInput.responseBuilder
            .speak(speechText + reprompt)
            .reprompt(reprompt)
            .getResponse();
    }).catch((err) => {
        return ErrorHandler.handle(handlerInput, err);
    });
    
  5. Add Games SDK for Alexa to the GetObjectInDirectionIntent (CompletedGetObjectInDirectionIntentHandler). We will create our payload object:

    var payloadObj = {
        type: "GetObject",
        message: direction_id
    };
    
  6. Send a the payload to our game and reply with a success or error if the payload failed to send:

    var response = await alexaPlusUnity.publishMessageAndListenToResponse(payloadObj, attributes.PUBNUB_CHANNEL, 4000).then((data) => {
       speechText = 'Currently, ' + data.message.object + ' is ' + direction + ' of you!';
    
       return handlerInput.responseBuilder
          .speak(speechText + reprompt)
          .reprompt(reprompt)
          .getResponse();
    }).catch((err) => {
       return ErrorHandler.handle(handlerInput, err);
    });
    
  7. Create the user’s unique channel:

    var response = await alexaPlusUnity.addChannelToGroup(attributes.PUBNUB_CHANNEL, "AlexaPlusUnityTest").then(async (data) => {
    var responseToReturn = responseBuilder
        .speak(speechText)
        .reprompt(reprompt)
        .withSimpleCard('Games SDK for Alexa', "Here is your Player ID: " + attributes.PUBNUB_CHANNEL)
        .getResponse();
    
    var userId = handlerInput.requestEnvelope.session.user.userId;
    return await sendUserId(userId, attributes, handlerInput, responseToReturn);
    }).catch((err) => {
        return ErrorHandler.handle(handlerInput, err);
    });
    
  8. Now, we need to send the game the user’s Alexa ID so we can access their persistant session attributes. Create our payload object:

    var payloadObj = {
        type: "AlexaUserId",
        message: userId
    };
    
  9. Send the payload to the game:

    return await alexaPlusUnity.publishMessage(payloadObj, attributes.PUBNUB_CHANNEL).then((data) => {
        return response;
    }).catch((err) => {
        return ErrorHandler.handle(handlerInput, err);
    });
    
  10. Lastly, we need to initialize the skills attributes

    attributes.SETUP_STATE = "STARTED";
    var newChannel = await alexaPlusUnity.uniqueQueueGenerator("AlexaPlusUnityTest");
    
    if(newChannel != null) {
        attributes.PUBNUB_CHANNEL = newChannel;
    } else {
        return null;
    }
    

Deploying the Skill

  1. Open a command prompt or terminal and navigate to <Template Location>
  2. Type ask deploy to deploy the skill.
  3. In a browser, navigate to your newly created Lambda Function
  4. Scroll down to the Execution Role and click on View the ask-lambda-Unity-Light-Control-AlexaPlusUnityTest role. This takes you to the IAM role in IAM.
  5. Click Attach Policies.
  6. Find and check the AmazonDynamoDBFullAccess policy.
  7. Click Attach Policy.

Note

This will only work if you set up the ASK CLI v1 correctly! Will not work with v2 of the ASK CLI.

Wrapping Up

At this point, you should be able to test the skill by saying, “Alexa, open unity light”.

Note

You will likely get an error the first couple of times initially opening the skill. This is because the skill needs to create the DynamoDB table and it can take a couple of minutes to do so. See this issue for more information.

We have finished the Alexa Skill!

Conclusion

Congratulations! You have completed the Games SDK for Alexa Light Control Demo!

Testing the Light Control Demo

  1. Open the skill by saying “Alexa, open unity light”.
  2. Make note of your player ID.
  3. Make sure your Unity project is open.
  4. Click on the Amazon Alexa GameObject.
  5. Fill the Channel field in the Light Control script with the player ID returned by the Alexa Skill.
  6. Press the Play Button in Unity to enter Play Mode.
  7. Once in Play Mode, re-launch your Alexa Skill.

You should notice that your skill’s welcome message changed. This means that the game is successfully communicating to your Alexa Skill. You can now say commands like “Change light to blue”, or “What is in front of me?” to interact with the game with your voice.

Unity C# Technical Docs

AlexaBaseData

Syntax

public abstract class AlexaBaseData : BaseEventData

Constructors

AlexaBaseData(EventSystem)

Declaration

public AlexaBaseData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Properties

Exception

Declaration

public Exception Exception { get; }

Property Value

Type Description
System.Exception  

IsError

Declaration

public bool IsError { get; }

Property Value

Type Description
System.Boolean  

Methods

BaseInitialize(Boolean, Exception)

Declaration

protected virtual void BaseInitialize(bool isError, Exception exception)

Parameters

Type Name Description
System.Boolean isError  
System.Exception exception  

AmazonAlexaManager

Syntax

public class AmazonAlexaManager

Constructors

AmazonAlexaManager(String, String, String, String, String, String, GameObject, Action<HandleMessageEventData>, Action<ConnectionStatusEventData>, Boolean)

AmazonAlexaManager Constructor.

Declaration

protected virtual void BaseInitialize(bool isError, Exception exception)

Parameters

Type Name Description
System.String publishKey Your Pubnub publish key.
System.String subscribeKey Your Pubnub subscribe key.
System.String channel Your player’s channel. (Should be unique to the player)
System.String tableName Name of your skill’s DynamoDB table where the persistant attributes are stored.
System.String identityPoolId Identifier of your AWS Cognito identity pool.
System.String AWSRegion The AWS Region where your DynamoDB table and Cognito identity pool are hosted.
GameObject gameObject The GameObject you are attaching this manager instance to.
System.Action<HandleMessageEventData> messageCallback The callback for when a message is recieved from your Alexa Skill.
System.Action<ConnectionStatusEventData> connectionStatusCallback  
System.Boolean debug (Optional) True to debug.

Fields

handleConnectionStatusCallback

The connection status recieved callback.

Declaration

public Action<ConnectionStatusEventData> handleConnectionStatusCallback

Field Value

Type Description
System.Action<ConnectionStatusEventData>  

handleMessageCallback

The message recieved callback.

Declaration

public Action<HandleMessageEventData> handleMessageCallback

Field Value

Type Description
System.Action<HandleMessageEventData>  

Properties

alexaUserDynamoKey

Gets or Resets the player’s DynanoDB table key.

Declaration

public string alexaUserDynamoKey { get; set; }

Property Value

Type Description
System.String The alexa user dynamo key.

channel

Resets your player’s channel. (Should be unique to the player)

Declaration

public string channel { set; }

Property Value

Type Description
System.String The channel.

Methods

GetSessionAttributes(Action<GetSessionAttributesEventData>)

Gets the Skill’s persistant session attributes from DynamoDB.

Declaration

public void GetSessionAttributes(Action<GetSessionAttributesEventData> callback)

Parameters

Type Name Description
System.Action<GetSessionAttributesEventData> callback The callback.

SendToAlexaSkill(Object, Action<MessageSentEventData>)

Sends a message to Alexa Skill. NOTE: Skill will only recieve the message if it is listening for a response.

Declaration

public void SendToAlexaSkill(object message, Action<MessageSentEventData> callback)

Parameters

Type Name Description
System.Object message The message.
System.Action<MessageSentEventData> callback The callback.

SetSessionAttributes(Dictionary<String, AttributeValue>, Action<SetSessionAttributesEventData>)

Sets the Skill’s persistant session attributes in DynamoDB.

Declaration

public void SetSessionAttributes(Dictionary<string, AttributeValue> attributes, Action<SetSessionAttributesEventData> callback)

Parameters

Type Name Description
System.Collections.Generic.Dictionary<System.String, AttributeValue> attributes The attributes to set.
System.Action<SetSessionAttributesEventData> callback The callback.

ConnectionStatusEventData

Syntax

public class ConnectionStatusEventData : AlexaBaseData

Constructors

ConnectionStatusEventData(EventSystem)

Declaration

public ConnectionStatusEventData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Properties

Category

Declaration

public PNStatusCategory Category { get; }

Property Value

Type Description
PNStatusCategory  

Methods

Initialize(Boolean, PNStatusCategory, Exception)

Declaration

public void Initialize(bool isError, PNStatusCategory category, Exception exception = null)

Parameters

Type Name Description
System.Boolean isError  
PNStatusCategory category  
System.Exception exception  

ErrorEventData

Syntax

public class ErrorEventData : AlexaBaseData

Constructors

ErrorEventData(EventSystem)

Declaration

public ErrorEventData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Methods

Initialize(Boolean, PNStatusCategory, Exception)

Declaration

public void Initialize(Exception exception, bool isError = true)

Parameters

Type Name Description
System.Exception exception  
System.Boolean isError  

GetSessionAttributesEventData

Syntax

public class GetSessionAttributesEventData : AlexaBaseData

Constructors

GetSessionAttributesEventData(EventSystem)

Declaration

public GetSessionAttributesEventData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Properties

Values

Declaration

public Dictionary<string, AttributeValue> Values { get; }

Property Value

Type Description
System.Collections.Generic.Dictionary<System.String, AttributeValue>  

Methods

Initialize(Boolean, Dictionary<String, AttributeValue>, Exception)

Declaration

public void Initialize(bool isError, Dictionary<string, AttributeValue> values, Exception exception = null)

Parameters

Type Name Description
System.Exception exception  
System.Collections.Generic.Dictionary<System.String, AttributeValue> values  
System.Boolean isError  

HandleMessageEventData

Syntax

public class HandleMessageEventData : AlexaBaseData

Constructors

HandleMessageEventData(EventSystem)

Declaration

public HandleMessageEventData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Properties

Message

Declaration

public Dictionary<string, object> Message { get; }

Property Value

Type Description
System.Collections.Generic.Dictionary<System.String, System.Object>  

Methods

Initialize(Boolean, Dictionary<String, Object>, Exception)

Declaration

public void Initialize(bool isError, Dictionary<string, object> message, Exception exception = null)

Parameters

Type Name Description
System.Boolean isError  
System.Collections.Generic.Dictionary<System.String, System.Object> message  
System.Exception exception  

MessageSentEventData

Syntax

public class MessageSentEventData : AlexaBaseData

Constructors

MessageSentEventData(EventSystem)

Declaration

public MessageSentEventData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Properties

Message

Declaration

public object Message { get; }

Property Value

Type Description
System.Object  

Methods

Initialize(Boolean, Object, Exception)

Declaration

public void Initialize(bool isError, object message, Exception exception = null)

Parameters

Type Name Description
System.Boolean isError  
System.Object message  
System.Exception exception  

SetSessionAttributesEventData

Syntax

public class SetSessionAttributesEventData : AlexaBaseData

Constructors

SetSessionAttributesEventData(EventSystem)

Declaration

public SetSessionAttributesEventData(EventSystem eventSystem)

Parameters

Type Name Description
EventSystem eventSystem  

Methods

Initialize(Boolean, Exception)

Declaration

public void Initialize(bool isError, Exception exception = null)

Parameters

Type Name Description
System.Boolean isError  
System.Exception exception  
Logo

Games SDK for Alexa

The Games SDK for Alexa was built to help with the expansion of Amazon’s Alexa into video games made with the Unity game engine, bringing a whole new layer of immersion into gaming.

Ready to get started? Follow the guides in the navigation bar to learn how to use the platform!

Support

Need help? Send us an email at games-sdk-support@tauon.tech!

The Explorer Demo