{"id":14955837,"url":"https://github.com/tsrivishnu/alexa-rails","last_synced_at":"2025-10-06T08:32:12.171Z","repository":{"id":59150515,"uuid":"118940148","full_name":"tsrivishnu/alexa-rails","owner":"tsrivishnu","description":"Make your Rails app serve Amazon Alexa skill requests","archived":false,"fork":false,"pushed_at":"2018-07-24T15:19:48.000Z","size":1821,"stargazers_count":14,"open_issues_count":7,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-26T16:00:06.549Z","etag":null,"topics":["alexa","alexa-gem","amazon-alexa","gem","rails","rails-engine","ruby","ruby-on-rails","rubygem","rubyonrails","slot-elicitation","sml"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tsrivishnu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-25T16:44:06.000Z","updated_at":"2024-08-05T16:58:11.000Z","dependencies_parsed_at":"2022-09-13T09:12:40.555Z","dependency_job_id":null,"html_url":"https://github.com/tsrivishnu/alexa-rails","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tsrivishnu/alexa-rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsrivishnu%2Falexa-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsrivishnu%2Falexa-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsrivishnu%2Falexa-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsrivishnu%2Falexa-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tsrivishnu","download_url":"https://codeload.github.com/tsrivishnu/alexa-rails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tsrivishnu%2Falexa-rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278579195,"owners_count":26009963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alexa","alexa-gem","amazon-alexa","gem","rails","rails-engine","ruby","ruby-on-rails","rubygem","rubyonrails","slot-elicitation","sml"],"created_at":"2024-09-24T13:11:52.987Z","updated_at":"2025-10-06T08:32:11.710Z","avatar_url":"https://github.com/tsrivishnu.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alexa-rails\n`alexa-rails` is a ruby gem which is a mountable rails engine that will add abilities to your Ruby on Rails application to handle Amazon alexa requests and responses.\n\n## Intallation/Usage\n\nDo the usual by adding the following to your `Gemfile`:\n\n```ruby\ngem 'alexa-rails'\n```\n\n### Migrations\n\nThe gem provides migrations that are needed to use few features of the gem.\nFor example: Saving or reading the user's skill usage count.\nTo generate the migrations, run the following\n\n```ruby\n$ rails generate alexa:migrations\n$ rake db:migrate\n```\n\n### Configuration\n\nAdd `config/initializers/alexa.rb` and add the following configuration\n\n```ruby\n    Alexa.configure do |config|\n      # Location permissions type\n      config.location_permission_type = :country_and_postal_code # or full_address\n\n      # Default title used on the display cards for your skill\n      config.default_card_title = \"My Alexa skill\"\n\n      # Add ID of your skills. Used for request verification\n      config.skill_ids = [\n        \"amzn1.ask.skill.xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx\"\n      ]\n    end\n```\n\nMount the engine for routes handling in your routes\n\n```ruby\n  # config/routes.rb\n\n  Rails.application.routes.draw do\n    ...\n    mount Alexa::Engine, at: \"/alexa\"\n  end\n```\n\nThis will make you Rails app accept `POST` requests from Alexa at\n```\nhttps://\u003cyour-domain\u003e/alexa/intent_handlers\n```\nThis has to be provided as the HTTPS endpoint URL for the skill.\n\n### Request handling\n\nTo handle an intent, you will have to create an intent handler class.\nFor example, if your intent is named `PlaceOrder`, you will have to create\nthe following file under you `app/lib/alexa/intent_handlers` directory.\n\n```ruby\nmodule Alexa\n  module IntentHandlers\n    class PlaceOrder \u003c Alexa::IntentHandlers::Base\n      def handle\n        ...\n        response # intent handlers should always return the +response+ object\n      end\n    end\n  end\nend\n```\n\nAll intent handlers should contain a `#handle` method that has required logic\nas to how to handle the intent request. For example, adding session variables,\nsetting response to elicit slots, delegate etc.\n\n**Note**: `#handle` method should always return the `response` object.\n`response` object in available in the scope of `#handle`.\n\nSee [Handling Amazon's Built-in Intents / Other request types] section to see\nhow to handle Amazon's built-in intent and other requests types.\n\n#### Adding session variable:\n\n```ruby\nsession.merge!(my_var: value)\n\n# Accesssing session variable\nsession[:my_var]\n```\n\n#### Slot elicitations\n\nDepending on your conditions, you can set the reponse to elicit a specific\nslot and the respecitve views are used.\n\n```ruby\nresponse.elicit_slot!(:SlotName)\n```\n\n#### Delegate response\n\n`#handle` is expected to return an instance of `Alexa::Response` or its subclasses.\nIn normal cases, the `response` object is returned.\nIn cases where the slots elicitation is delegated to alexa, an instance of\n`Alexa::Responses::Delegate` has to be returned.\n\n```ruby\n  def handle\n    ...\n    return Alexa::Responses::Delegate.new\n  end\n```\n\n### Views\n\nThe content for SSML and display cards is not set in the intent handler\nclasses.\nWe follow rails convention and expect all response content for intents to be\nin their respective `default` view files.\n\nAlso, the views are context locale dependant.\n\nGiven an intent named `PlaceOrder`, you view files would be\n\n  * SSML: `views/alexa/en_us/intent_handlers/place_order/default.ssml.erb`\n  * Card: `views/alexa/en_us/intent_handlers/place_order/default.text.erb`\n\nIn case of slot elicitations, follow a similar convention but make sure you\nname the `ssml` and `text` files with the same name as the slot that is being\nelicited. For example, in the `PlaceOrder` intent, the elicatation for `Address`\nslot would have the following views\n\n  * SSML: `views/alexa/en_us/intent_handlers/place_order/elicitations/address.ssml.erb`\n  * Card: `views/alexa/en_us/intent_handlers/place_order/elicitations/address.text.erb`\n\n##### Render custom template instead of default\n\nIf you wish to force the `response` object to take contents from a different\ntemplate file instead of `default.*.erb`, pass the custom filename with\n`Alexa::Response#with(template: )`.\n\nFor example: Instead of `default`, if you wish to render the contents of\n`no_results.ssml.erb` and `no_results.text.erb`, return the response by forcing\nthe template with the following:\n\n```ruby\n  def handle\n    ...\n    return response.with(template: :no_results)\n  end\n```\nand make sure you add your contents in the `no_results.*.erb` files in your\nintent handlers' views' directory.\n\n#### SSML\n\n##### Re-prompts\n\nBy default, there is no re-prompt SSML is added to the response.\nHowever, re-prompt SSML can be set in the ssml view of the intent response or\na slot elicitation view with a `content_for :repromt_ssml` like this:\n\n```erb\nWhat is your address?\n\n\u003c% content_for :repromt_ssml do %\u003e\n  Where would you like the pizza to be delivered?\n\u003c% end %\u003e\n```\n\n#### Cards\n\n##### Type \u0026 Title\n\nBy default, the card type is set to `Simple`.\nTo change the card type and title, use the `content_for` blocks in the `text`\nview file for the response as follows:\n\n```erb\n\u003c% content_for :card_type do %\u003e\n  Simple\n\u003c% end %\u003e\n\u003c% content_for :card_title do %\u003e\n  Get your pizza\n\u003c% end %\u003e\n\n```\n\n##### Permission cards\n\nTo render a permission card. Use `ask_for_permissions_consent` as the `card_type`\nand provide the scope in `permissions_scope` content_for block.\nFollowing is an example for Device address permission card.\n\n```erb\n\u003c% content_for :card_type do %\u003e\n  ask_for_permissions_consent\n\u003c% end %\u003e\n\n\u003c% content_for :permissions_scope do %\u003e\n  read::alexa:device:all:address\n\u003c% end %\u003e\n```\n\n*Note*: The permission card should not have any other content other than the\ncontent for `card_type` and `permissions_scope`.\n\n## Handling Amazon's Built-in Intents / Other request types\n\nRequests for Amazon's built-in intents and other request types\nare also handled with intent handlers.\nBelow is the mapping for every request type and respective\nintent handler classes.\nThese intent handlers are not included in the gem as they are a\nbut specific to the application.\nRefer to the table below and implement the intent handlers.\n\nBuilt-in Intents:\n\n| Intent name | Handler class |\n| ------------- | ------------- |\n| AMAZON.CancelIntent | `Alexa::IntentHandlers::GoodBye` |\n| AMAZON.StopIntent | `Alexa::IntentHandlers::GoodBye` |\n| AMAZON.HelpIntent | `Alexa::IntentHandlers::Help` |\n\nOther request types:\n\n| Request type | Handler class |\n| ------------- | ------------- |\n| Launch request | `Alexa::IntentHandlers::LaunchApp` |\n| Session end request | `Alexa::IntentHandlers::SessionEnd` |\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'alexa'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install alexa\n```\n\n## Contributing\nContribution directions go here.\n\n## License\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsrivishnu%2Falexa-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftsrivishnu%2Falexa-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftsrivishnu%2Falexa-rails/lists"}