All Projects β†’ mulev β†’ alexa-ruby

mulev / alexa-ruby

Licence: MIT license
Ruby toolkit for Amazon Alexa service

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to alexa-ruby

cookiecutter-flask-ask
Cookiecutter template for Alexa skills based on the fantastic Flask-Ask framework πŸΎπŸ—£β“
Stars: ✭ 51 (+200%)
Mutual labels:  alexa, amazon-alexa-skill, amazon-echo, alexa-skills-kit, alexa-skill, amazon-alexa
Chatskills
Run and debug Alexa skills on the command-line. Create bots. Run them in Slack. Run them anywhere!
Stars: ✭ 171 (+905.88%)
Mutual labels:  alexa, amazon, amazon-echo, alexa-skill, amazon-alexa
Alexa Skill Kit
Library for effortless Alexa Skill development with AWS Lambda
Stars: ✭ 278 (+1535.29%)
Mutual labels:  alexa, amazon, amazon-echo, alexa-skills-kit, alexa-skill
Alexa Skills Kit Sdk For Java
The Alexa Skills Kit SDK for Java helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Stars: ✭ 758 (+4358.82%)
Mutual labels:  alexa, amazon, amazon-echo, alexa-skills-kit, amazon-alexa
Awesome Amazon Alexa
πŸ—£Curated list of awesome resources for the Amazon Alexa platform.
Stars: ✭ 458 (+2594.12%)
Mutual labels:  alexa, amazon-echo, alexa-skills-kit, alexa-skill, amazon-alexa
Amazon Alexa Php
Php library for amazon echo (alexa) skill development.
Stars: ✭ 93 (+447.06%)
Mutual labels:  alexa, amazon, amazon-echo, alexa-skill
Alexa Voice Service.js
Library for interacting with Alexa Voice Service (AVS) in the browser.
Stars: ✭ 123 (+623.53%)
Mutual labels:  alexa, amazon, alexa-skills-kit, amazon-alexa
Azure4Alexa
Create and Host Alexa Custom Skills using .NET and Azure
Stars: ✭ 48 (+182.35%)
Mutual labels:  alexa, alexa-skills-kit, alexa-skill, alexa-custom-skill
alexa-skill-test-framework
Framework for easy offline black-box testing of Alexa skills.
Stars: ✭ 64 (+276.47%)
Mutual labels:  alexa, alexa-skills-kit, alexa-skill, alexa-sdk
go-avs
A simple package for communicating with Amazon’s HTTP/2 API for AVS.
Stars: ✭ 25 (+47.06%)
Mutual labels:  alexa, amazon, amazon-echo, alexa-voice-service
alexa-tesla
Alexa Skills Kit (ASK) project - Tesla monitoring and control for Amazon Echo devices
Stars: ✭ 23 (+35.29%)
Mutual labels:  amazon-alexa-skill, amazon-echo, alexa-skills-kit, alexa-skill
alexa-skill-boilerplate
An easy to use Amazon Alexa Skill Boilerplate for fast skill creation
Stars: ✭ 54 (+217.65%)
Mutual labels:  alexa, amazon-alexa-skill, amazon-echo, alexa-skill
Voicewp
Create Alexa Skills through WordPress
Stars: ✭ 132 (+676.47%)
Mutual labels:  alexa, amazon, alexa-skill, amazon-alexa
Assistantcomputercontrol
Control your computer with your Google Home or Amazon Alexa assistant!
Stars: ✭ 554 (+3158.82%)
Mutual labels:  alexa, amazon-echo, amazon-alexa
Alexa Skills Kit Sdk For Python
The Alexa Skills Kit SDK for Python helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Stars: ✭ 678 (+3888.24%)
Mutual labels:  alexa, alexa-skills-kit, alexa-skill
Alexaskillskit
Swift library to develop custom Alexa Skills
Stars: ✭ 160 (+841.18%)
Mutual labels:  alexa, alexa-skills-kit, alexa-skill
Bst
πŸ”§ Bespoken Tools - Tools for making voice apps faster and better
Stars: ✭ 193 (+1035.29%)
Mutual labels:  alexa, amazon-echo, alexa-skills-kit
Jovo Framework
πŸ”ˆ The Open Source Voice Layer: Build Voice Experiences for Alexa, Google Assistant, Samsung Bixby, Web Apps, and much more
Stars: ✭ 1,320 (+7664.71%)
Mutual labels:  alexa, alexa-skill, amazon-alexa
Home Assistant
Home-Assistant-Config
Stars: ✭ 182 (+970.59%)
Mutual labels:  alexa, amazon, amazon-echo
Go Alexa
A collection of Amazon Echo / Alexa tools for Go development.
Stars: ✭ 245 (+1341.18%)
Mutual labels:  alexa, amazon, amazon-echo

AlexaRuby

Gem Version Build Status CircleCI Code Climate Coverage Status


Since I have now some spare time, I plan to completely revise this project and make it at least up to date with the latest Alexa custom skills API.
Maybe even more.


Originally forked from damianFC's AlexaRubykit, this gem implements a convenient back-end service for interaction with Amazon Alexa API.

Installation

To install and use gem in your project just add this to your Gemfile:

gem 'alexa_ruby'

And bundle it with:

$ bundle install

Or install it as a separate gem:

$ gem install alexa_ruby

Docs

Resource URL
Amazon Alexa Skill Kit docs https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference
Rubydoc http://www.rubydoc.info/gems/alexa_ruby
Source https://github.com/mulev/alexa-ruby
Bugs https://github.com/mulev/alexa-ruby/issues

Usage

Gem provides a possibility to easily handle requests from Amazon Alexa service and build responses to given requests.

Getting started

AlexaRuby usage is quite simple, to start you need to require gem in your ruby file and pass it JSON request from Amazon Alexa service.
Here and below all examples will be based on Roda routing tree framework, but you can use any other -- AlexaRuby is a framework independent gem.

require 'roda'
require 'alexa_ruby'

class App < Roda
  route do |r|
    r.post do
      r.on 'alexa' do
        alexa = AlexaRuby.new(r.body.read)
      end
    end
  end
end

Request structure validations can be disabled:

AlexaRuby.new(request, disable_validations: true)

If needed, you can validate request signature and Amazon SSL certificates chain. To do so specify several parameters:

AlexaRuby.new(
  request,
  certificates_chain_url: url,
  request_signature: signature
)

After initializing new AlexaRuby instance you will have a possibility to access all parameters of the received request.

General request parameters

Access path Description
alexa.request.json given JSON request
alexa.request.version request version, typically "1.0"
alexa.request.type request type, can be :launch, :intent, :session_ended or :audio_player
alexa.request.id request ID
alexa.request.timestamp request timestamp
alexa.request.locale request locale

Session parameters

Notice that user data exists in two scopes -- session and context.

Access path Description
alexa.request.session.id session ID
alexa.request.session.attributes array with all session attributes
alexa.request.session.end_reason session end reason, can be :user_quit, :processing_error or :user_idle
alexa.request.session.error hash with session error info
alexa.request.session.state current session state, can be :new, :old or :ended
alexa.request.session.user.id skill user ID
alexa.request.session.user.access_token user access token if account linking is enabled and user is authenticated
alexa.request.session.user.permissions_token user permissions token

Context parameters

Notice that user data exists in two scopes -- session and context.

Access path Description
alexa.request.context.app_id Alexa application ID
alexa.request.context.api_endpoint Alexa API endpoint
alexa.request.context.user.id skill user ID
alexa.request.context.user.access_token user access token if account linking is enabled and user is authenticated
alexa.request.context.user.permissions_token user permissions token
alexa.request.context.device.id user device ID
alexa.request.context.device.interfaces interfaces, supported by user device

Intent request parameters

Access path Description
alexa.request.intent_name given intent name
alexa.request.dialog_state state of dialog with user, can be :started, :in_progress or :completed
alexa.request.confirmation_status user confirmation status, can be :unknown, :confirmed or :denied
alexa.request.slots array with all slots from intent

Audio player request parameters

Access path Description
alexa.request.playback_state current playback state
alexa.request.playback_offset current playback offset in milliseconds
alexa.request.error_type playback error type
alexa.request.error_message playback error message explaining error
alexa.request.error_playback_token audio player token of failed playback
alexa.request.error_player_activity audio player activity in moment of failure

Building response

To build a response take your freshly initialized alexa and start using alexa.response methods.

Add session attributes

It is possible to add one attribute to session scope:

alexa.response.add_session_attribute('key', 'value')

Exception will be raised if attribute already exists in the session scope.
If you want to overwrite it, call:

alexa.response.add_session_attribute('key', 'value_2', true)

You can also add a pack of attributes. To overwrite all existing ones call:

alexa.response.add_session_attributes(key: 'value', key_2: 'value_2')

To add new attributes and save existing ones call:

alexa.response.merge_session_attributes(key: 'value', key_2: 'value_2')

Add card

Supported card types are: Simple, Standard and LinkAccount.

card = {
  type: 'Standard', title: 'Test', content: 'test',
  small_image_url: 'https://test.ru/example_small.jpg',
  large_image_url: 'https://test.ru/example_large.jpg'
}
alexa.response.add_card(card)

Add audio player directive

Supported directives:

  • AudioPlayer.Play
  • AudioPlayer.ClearQueue
  • AudioPlayer.Stop

To start the whole new playback call:

params = { url: 'https://my-site.com/my-stream', token: 'test', offset: 0 }
alexa.response.add_audio_player_directive(:start, params)

To enqueue new audio file call:

params = { url: 'https://my-site.com/my-stream', token: 'test', offset: 0, play_behavior: :enqueue }
alexa.response.add_audio_player_directive(:start, params)

To replace all previously enqueued audio files call:

params = { url: 'https://my-site.com/my-stream', token: 'test', offset: 0, play_behavior: :replace_enqueued }
alexa.response.add_audio_player_directive(:start, params)

To clear all:

alexa.response.add_audio_player_directive(:clear)

To clear only enqueued tracks and keep the playing one:

alexa.response.add_audio_player_directive(
  :clear,
  clear_behavior: :clear_queue
)

To stop playback call:

alexa.response.add_audio_player_directive(:stop)

Get current state of response encoded in JSON

alexa.response.json

Add output speech to response

Ask user a question and wait for response (session will remain open):

question = 'What can I do for you?'

alexa.response.ask(question)                  # will add outputSpeech node
alexa.response.ask(question, question)        # outputSpeech node and reprompt node
alexa.response.ask(question, question, true)  # outputSpeech node, reprompt node and both will be converted into SSML

alexa.response.ask!(question)                 # will add outputSpeech node and return JSON encoded response object

Tell something to user and end conversation (session will be closed):

speech = 'You are awesome!'

alexa.response.tell(speech)               # will add outputSpeech node
alexa.response.tell(speech, speech)       # outputSpeech node and reprompt node
alexa.response.tell(speech, speech, true) # outputSpeech node, reprompt node and both will be converted into SSML

alexa.response.tell!(speech)              # will add outputSpeech node and return JSON encoded response object

Testing

Run all tests with:

$ rake test

Please, feel free to open an issue in case of any bugs.

Contributing

You are always welcome to open an issue with some feature request or bug report. Also you can add new features by yourself. To do so, please, follow that steps:

  1. Fork master branch of this repo
  2. Add a new feature branch in your forked repo and write code
  3. Write tests
  4. Add pull request from your branch to alexa_ruby develop branch

All development is made only in develop branch before being merged to master.

License

AlexaRuby is released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].