Giter VIP home page Giter VIP logo

alexa's Introduction

Alexa

Provides support for implementing an Amazon Alexa Skill.

Installation

The package can be installed as:

  1. Add alexa to your list of dependencies in mix.exs:

    def deps do [{:alexa, "~> 0.1.6"}] end

  2. Add alexa to your list of applications in mix.exs:

    def application do [applications: [:logger, :alexa]] end

Usage

Creating a new Alexa skill is easy.

defmodule MyAwesomeSkill do
  use Alexa.Skill, app_id: "<alexa_skill_app_id>"      

  def handle_intent("SayHello", request, response) do
    response |> say("Hello World!")
  end
end

Alexa.Skill implements Elixir's Application behaviour, so you need to start a worker process for your skill. Add something like this to your application's supervision tree.

worker(MyAwesomeSkill, [])

You can also optionally pass the app_id at this point as well.

worker(MyAwesomeSkill, [[app_id: Application.get_env(:my_awesome_skill, :alexa_app_id)]])

When your application starts, this will register your skill with the Alexa module. It will be used to handle any incoming requests with the matching app_id.

Then create an app that exposes an endpoint so that you can receive incoming Alexa requests.

Here's an example plug implementation:

defmodule Router do
  use Plug.Router

  plug :match
  plug :dispatch

  post "/command" do
    {:ok, body, conn} = read_body(conn)
    request = Poison.decode!(body, as: %Alexa.Request{})
    response = Alexa.handle_request(request)
    conn = send_resp(conn, 200, Poison.encode!(response))
    conn = %{conn | resp_headers: [{"content-type", "application/json"}]}
    conn
  end
end

Here's an example Phoenix Boilerplate project for bootstrapping your Alexa skill: SDITools/alexa_hello_world

alexa's People

Contributors

anthonator avatar axelclark avatar col avatar elkelk avatar jeremyjh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.