alexa_plug v0.2.0 AlexaPlug.Response

A collection of functions for building responses expected by the Alexa Skills Kit.

Usage

alias AlexaPlug.Response

Example

To create a response:

response = Response.new
|> Response.add_session_attributes(%{"user" => "test"})
|> Response.add_output_speech("PlainText", "Hello!")
|> Response.add_card("Simple", "Title", "Content")
|> Response.add_reprompt("PlainText", "Can I help with anything else?")
|> Response.add_should_not_end_session

and the following response map is created:

%{
  "version" => "1.0",
  "sessionAttributes" => %{"user" => "test"},
  "response" => %{
    "outputSpeech" => %{
      "type" => "PlainText",
      "text" => "Can I help with anything else?"
    },
    "card": %{
      "type" => "Simple",
      "title" => "Title",
      "content" => "Content"
    },
    "reprompt" => %{
      "outputSpeech" => %{
        "type" => "PlainText",
        "text" => "Can I help with anything else?"
      }
    },
    "shouldEndSession" => false
  }
}

The same response can be built using convenience methods as follows:

response = Response.new
|> Response.add_session_attributes(%{"user" => "test"})
|> Response.add_plain_text_output_speech("Hello!")
|> Response.add_simple_card("Title", "Content")
|> Response.add_plain_text_reprompt("Can I help with anything else?")
|> Response.add_should_not_end_session

Summary

Functions

Add response.card field to the response

Add response.card field to the response

Convenience method to add response.card to the response with the type set to LinkAccount

Add response.outputSpeech field to the response

Convenience method to add response.outputSpeech to the response with the type set to PlainText

Convenience method to add response.reprompt to the response with the type set to PlainText

Add response.reprompt field to the response

Add sessionAttributes field to the response

Add response.shouldEndSession field to the response set to true

Add response.shouldEndSession field to the response set to false

Convenience method to add response.card to the response with the type set to Simple

Convenience method to add response.outputSpeech to the response with the type set to SSML

Convenience method to add response.reprompt to the response with the type set to SSML

Create a new map with version set to 1.0 and an empty response map

Functions

add_card(alexa_response, type)

Add response.card field to the response.

This function is meant to be used with the LinkAccount card type.

add_card(alexa_response, type, title, content)

Add response.card field to the response.

This function is meant to be used with the Simple card type.

add_output_speech(alexa_response, type, text)

Add response.outputSpeech field to the response.

add_plain_text_output_speech(response, text)

Convenience method to add response.outputSpeech to the response with the type set to PlainText.

add_plain_text_reprompt(response, text)

Convenience method to add response.reprompt to the response with the type set to PlainText.

add_reprompt(alexa_response, type, text)

Add response.reprompt field to the response.

add_session_attributes(alexa_response, session_attributes)

Add sessionAttributes field to the response.

add_should_end_session(alexa_response)

Add response.shouldEndSession field to the response set to true.

add_should_not_end_session(alexa_response)

Add response.shouldEndSession field to the response set to false.

add_simple_card(response, title, content)

Convenience method to add response.card to the response with the type set to Simple.

add_ssml_output_speech(response, text)

Convenience method to add response.outputSpeech to the response with the type set to SSML.

add_ssml_reprompt(response, text)

Convenience method to add response.reprompt to the response with the type set to SSML.

new()

Create a new map with version set to 1.0 and an empty response map.