alexa_plug v0.2.0 AlexaPlug.Plugs

A collection of plugs for extracting data from Alexa Skills Kit requests.

The plugs fetch specific data from Alexa Skills Kit requests and places that data in conn.assigns.

Usage

import AlexaPlug.Plugs

Example

When the following request is received (fields omitted for brevity):

{
  ...
  "session": {
    ...
    "attributes": {
      "supportedHoroscopePeriods": {
        "daily": true,
        "weekly": false,
        "monthly": false
      }
    },
    "user": {
      "userId": "amzn1.account.AM3B00000000000000000000000"
    },
    ...
  },
  "request": {
    "type": "IntentRequest",
    ...
    "intent": {
      "name": "GetZodiacHoroscopeIntent",
      "slots": {
        "ZodiacSign": {
          "name": "ZodiacSign",
          "value": "virgo"
        }
      }
    }
  }
}

and the following plugs are being used:

plug :fetch_echo_session_attributes
plug :fetch_echo_user_id
plug :fetch_echo_request_type
plug :fetch_echo_intent_type
plug :fetch_echo_slots

# or use all plugs with

plug :fetch_echo_request_data

then conn.assigns will contain:

%{
  ask_request: %{
    session_attributes: %{
      "supportedHoroscopePeriods" => %{
        "daily" => true,
        "weekly" => false,
        "monthly" => false
      }
    },
    user_id: "amzn1.account.AM3B00000000000000000000000",
    request_type: "IntentRequest",
    intent_type: "GetZodiacHoroscopeIntent",
    slots: %{"ZodiacSign" => "virgo"}
  }
}

To see more info on all request types see the ASK Interface Reference for details.

Summary

Functions

Fetch the intent type from an Alexa Skills Kit request

Fetch the session attributes, request type, intent type, and slots from an Alexa Skills Kit request

Fetch the request type from an Alexa Skills Kit request

Fetch the session attributes from an Alexa Skills Kit request

Fetch the slots from an Alexa Skills Kit request

Fetch the user ID from an Alexa Skills Kit request

Functions

fetch_echo_intent_type(conn, opts \\ nil)

Fetch the intent type from an Alexa Skills Kit request.

Assigns conn.assigns[:ask_request][:intent_type] the value for the request field request.intent.name or nil.

fetch_echo_request_data(conn, opts \\ nil)

Fetch the session attributes, request type, intent type, and slots from an Alexa Skills Kit request.

Calls all the other plugs on defined in this module.

fetch_echo_request_type(conn, opts \\ nil)

Fetch the request type from an Alexa Skills Kit request.

Assigns conn.assigns[:ask_request][:request_type] the value for the request field request.type or nil.

fetch_echo_session_attributes(conn, opts \\ nil)

Fetch the session attributes from an Alexa Skills Kit request.

Assigns conn.assigns[:ask_request][:session_attributes] the value for the request field session.attributes or nil.

fetch_echo_slots(conn, opts \\ nil)

Fetch the slots from an Alexa Skills Kit request.

For the given slots:

"slots": {
  "(key)": {
    "name": "ZodiacSign",
    "value": "virgo"
  }
}

A slots map is created using the slot key (not the slot name) and the slot value as key-value pairs.

Assigns conn.assigns[:ask_request][:slots] the value for the request field request.intent.slots or nil.

fetch_echo_user_id(conn, opts \\ nil)

Fetch the user ID from an Alexa Skills Kit request.

Assigns conn.assigns[:ask_request][:user_id] the value for the request field session.user.userId or nil.