alexa_ruby 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05efe37b6e97b7278bbfe995867983640c07b90d
4
- data.tar.gz: '08e039b53252f7a87961e7d21cd02a45a2917c64'
3
+ metadata.gz: f0ecb9d2206ffa52620becb38d2979af5b2d382f
4
+ data.tar.gz: 99f7d15b8f7b672d7e0e3007bcefeb5129a018de
5
5
  SHA512:
6
- metadata.gz: 75606a0692119854f7ed8492892b64be91e52554c6d271b0e8a4b3d04f545f254942b16e616144945bfccd0fba79fdd58f366a1df195e44352a49a724c67dab7
7
- data.tar.gz: 632e697b97175adfe62a22a8b1978b9bae2027d6c69fb901d1c6de4f06e4dacd0557a7faa9ea80b28eb45316bc40508876d6148bf51ac985fc9d02be6cee0722
6
+ metadata.gz: ecdf130e009bb208852f1035451348a86d9b872da7536987a4bc3f82de36801e5438c1ed488c6af7b2b135595819cfe4ee593124cfa9268030cc0f1bd4bc8f3b
7
+ data.tar.gz: 0e451beda04f13e9b50e816f0090da713fdeca3e1b6ef26580dc41904b0d3a018510ea45ba80ca57ec2633f716eb27305933a2955f607eefe80e3c46ab3f49f9
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.3.4'
3
2
 
4
3
  # Specify your gem's dependencies in alexa_rubykit.gemspec
5
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,41 +1,44 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alexa_ruby (0.0.0)
5
- bundler (~> 1.7)
4
+ alexa_ruby (0.2.0)
5
+ bundler (>= 1.6.9)
6
6
  oj (~> 3.0)
7
7
  rake
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- diff-lcs (1.3)
12
+ ansi (1.5.0)
13
+ builder (3.2.3)
14
+ codeclimate-test-reporter (1.0.8)
15
+ simplecov (<= 0.13)
16
+ docile (1.1.5)
17
+ json (2.1.0)
18
+ minitest (5.10.2)
19
+ minitest-reporters (1.1.14)
20
+ ansi
21
+ builder
22
+ minitest (>= 5.0)
23
+ ruby-progressbar
13
24
  oj (3.0.10)
14
25
  rake (12.0.0)
15
- rspec (3.6.0)
16
- rspec-core (~> 3.6.0)
17
- rspec-expectations (~> 3.6.0)
18
- rspec-mocks (~> 3.6.0)
19
- rspec-core (3.6.0)
20
- rspec-support (~> 3.6.0)
21
- rspec-expectations (3.6.0)
22
- diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.6.0)
24
- rspec-mocks (3.6.0)
25
- diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.6.0)
27
- rspec-support (3.6.0)
26
+ ruby-progressbar (1.8.1)
27
+ simplecov (0.13.0)
28
+ docile (~> 1.1.0)
29
+ json (>= 1.8, < 3)
30
+ simplecov-html (~> 0.10.0)
31
+ simplecov-html (0.10.1)
28
32
 
29
33
  PLATFORMS
30
34
  ruby
31
35
 
32
36
  DEPENDENCIES
33
37
  alexa_ruby!
34
- rspec (~> 3.2, >= 3.2.0)
35
- rspec-mocks (~> 3.2, >= 3.2.0)
36
-
37
- RUBY VERSION
38
- ruby 2.3.4p301
38
+ codeclimate-test-reporter (~> 1.0.0)
39
+ minitest (~> 5.10, >= 5.10.2)
40
+ minitest-reporters (~> 1.1, >= 1.1.14)
41
+ simplecov
39
42
 
40
43
  BUNDLED WITH
41
44
  1.15.0
data/README.md CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/alexa_ruby.svg)](https://badge.fury.io/rb/alexa_ruby)
4
4
  [![Build Status](https://travis-ci.org/mulev/alexa-ruby.svg?branch=master)](https://travis-ci.org/mulev/alexa-ruby)
5
+ [![Code Climate](https://codeclimate.com/github/mulev/alexa-ruby/badges/gpa.svg)](https://codeclimate.com/github/mulev/alexa-ruby)
6
+ [![Test Coverage](https://codeclimate.com/github/mulev/alexa-ruby/badges/coverage.svg)](https://codeclimate.com/github/mulev/alexa-ruby/coverage)
5
7
 
6
- Originally forked from [damianFC's AlexaRubykit](https://github.com/damianFC/alexa-rubykit), this gem implements a back-end service for interaction with Amazon Alexa API.
8
+ Originally forked from [damianFC's AlexaRubykit](https://github.com/damianFC/alexa-rubykit), this gem implements a convenient back-end service for interaction with Amazon Alexa API.
7
9
 
8
10
  ## Installation
9
11
 
@@ -25,39 +27,49 @@ Or install it as a separate gem:
25
27
  $ gem install alexa_ruby
26
28
  ```
27
29
 
28
- ## Usage
30
+ ## Docs
31
+
32
+ |Resource|URL|
33
+ |---|---|
34
+ |Rubydoc|[http://www.rubydoc.info/gems/alexa_ruby](http://www.rubydoc.info/gems/alexa_ruby)|
35
+ |Source|[https://github.com/mulev/alexa-ruby](https://github.com/mulev/alexa-ruby)|
36
+ |Bugs|[https://github.com/mulev/alexa-ruby/issues](https://github.com/mulev/alexa-ruby/issues)|
29
37
 
30
- Gem provides methods to handle requests from Amazon Alexa skill and to sent it a proper response.
38
+ ## Usage
31
39
 
32
- You can quickly try it with that sample code:
40
+ Gem provides a possibility to easily handle requests from Amazon Alexa service and build responses to given requests.
41
+ Usage is as easy as:
33
42
 
34
43
  ```ruby
35
44
  require 'alexa_ruby'
36
45
 
37
- response = AlexaRuby::Response.new
38
- response.add_speech('Yay, ruby is running!')
39
- response.build_response
46
+ alexa = AlexaRuby.new(request) # request is a HTTP request body
47
+ alexa.response.tell!('Ruby is awesome!')
40
48
  ```
41
49
 
42
- It will generate valid outspeech JSON:
50
+ This simple example will return a valid JSON with response to Amazon Alexa service request:
43
51
 
44
- ```JSON
52
+ ```json
45
53
  {
46
54
  "version": "1.0",
55
+ "sessionAttributes": {},
47
56
  "response": {
57
+ "shouldEndSession": true,
48
58
  "outputSpeech": {
49
59
  "type": "PlainText",
50
- "text": "Yay, ruby is running!"
51
- },
52
- "shouldEndSession": true
60
+ "text": "Ruby is awesome!"
61
+ }
53
62
  }
54
63
  }
64
+
55
65
  ```
56
66
 
67
+ Gem can be used with any framework - Rails, Sinatra, Cuba, Roda, or any other that can handle HTTP requests and responses.
68
+
57
69
  ## Testing
58
70
 
59
- Run the tests using
71
+ Run all tests with
60
72
 
61
73
  ```bash
62
- bundle exec rspec --color --format=documentation
74
+ $ rake test
63
75
  ```
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require 'rspec/core/rake_task'
1
+ require 'rake/testtask'
3
2
 
4
- RSpec::Core::RakeTask.new
3
+ ENV['env'] = 'test'
4
+ ENV['CODECLIMATE_REPO_TOKEN'] = '700b2d6bc97a4c5d504565407b412451e3d8fe2cf7967f57ca75c01ae7d92c16'
5
5
 
6
- task :default => [:spec]
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ end
@@ -0,0 +1,52 @@
1
+ module AlexaRuby
2
+ # Main processing class, parses request from Amazon Alexa and
3
+ # initialize new response object
4
+ class Alexa
5
+ attr_reader :request, :response
6
+
7
+ # Initialize new Alexa assistant
8
+ #
9
+ # @param request [Hash] request from Amazon Alexa web service
10
+ def initialize(request)
11
+ @req = request
12
+ invalid_request_exception if invalid_request?
13
+ @request = define_request
14
+ raise ArgumentError, 'Unknown type of Alexa request' if @request.nil?
15
+ @response = Response.new(@request.type, @request.version)
16
+ end
17
+
18
+ private
19
+
20
+ # Check if it is an invalid request
21
+ #
22
+ # @return [Boolean]
23
+ def invalid_request?
24
+ @req[:version].nil? || @req[:context].nil? || @req[:request].nil?
25
+ end
26
+
27
+ # Request structure isn't valid, raise exception
28
+ def invalid_request_exception
29
+ raise ArgumentError,
30
+ 'Invalid request structure, ' \
31
+ 'please, refer to the Amazon Alexa manual: ' \
32
+ 'https://developer.amazon.com/public/solutions' \
33
+ '/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-reference'
34
+ end
35
+
36
+ # Initialize proper request object
37
+ #
38
+ # @return [Object] request object
39
+ def define_request
40
+ case @req[:request][:type]
41
+ when /Launch/
42
+ LaunchRequest.new(@req)
43
+ when /Intent/
44
+ IntentRequest.new(@req)
45
+ when /SessionEnded/
46
+ SessionEndedRequest.new(@req)
47
+ when /AudioPlayer/, /PlaybackController/
48
+ AudioPlayerRequest.new(@req)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,50 +1,43 @@
1
1
  module AlexaRuby
2
- # AudioPlayerRequest class implements Alexa "AudioPlayer" request type
3
- class AudioPlayerRequest < Request
4
- attr_accessor :playback_state, :playback_offset, :error_type,
5
- :error_message, :error_playback_token, :error_player_activity
2
+ # Alexa "AudioPlayer" and "PlaybackController" request type
3
+ class AudioPlayerRequest < BaseRequest
4
+ attr_reader :playback_state, :playback_offset, :error_type,
5
+ :error_message, :error_playback_token, :error_player_activity
6
6
 
7
7
  # Initialize new AudioPlayer request
8
8
  #
9
- # @param json [Hash] valid JSON request from Amazon
10
- def initialize(json)
9
+ # @param request [Hash] valid request from Amazon Alexa service
10
+ def initialize(request)
11
11
  @type = :audio_player
12
- req = json[:request]
12
+ super
13
+ req = @req[:request]
13
14
  @playback_state = req[:type].gsub!('AudioPlayer.', '')
14
15
  @playback_offset = current_offset(req)
15
16
  define_error_params(req) if @playback_state == 'PlaybackFailed'
16
- super
17
- end
18
-
19
- # Outputs the launch requestID
20
- #
21
- # @return [String] launch request ID
22
- def to_s
23
- "AudioPlayerRequest requestID: #{request_id}"
24
17
  end
25
18
 
26
19
  private
27
20
 
28
21
  # Get current playback offset from request
29
22
  #
30
- # @param json [Hash] "request" part of json request from Amazon
23
+ # @param request [Hash] valid request from Amazon Alexa service
31
24
  # @return [Integer] playback offset in milliseconds at the moment of request
32
- def current_offset(json)
25
+ def current_offset(request)
33
26
  if @playback_state == 'PlaybackFailed'
34
- json[:currentPlaybackState][:offsetInMilliseconds]
27
+ request[:currentPlaybackState][:offsetInMilliseconds]
35
28
  else
36
- json[:offsetInMilliseconds]
29
+ request[:offsetInMilliseconds]
37
30
  end
38
31
  end
39
32
 
40
33
  # Define all error parameters if an error occured during playback
41
34
  #
42
- # @param json [Hash] "request" part of json request from Amazon
43
- def define_error_params(json)
44
- @error_type = json[:error][:type]
45
- @error_message = json[:error][:message]
46
- @error_playback_token = json[:currentPlaybackState][:token]
47
- @error_player_activity = json[:currentPlaybackState][:playerActivity]
35
+ # @param request [Hash] valid request from Amazon Alexa service
36
+ def define_error_params(request)
37
+ @error_type = request[:error][:type]
38
+ @error_message = request[:error][:message]
39
+ @error_playback_token = request[:currentPlaybackState][:token]
40
+ @error_player_activity = request[:currentPlaybackState][:playerActivity]
48
41
  end
49
42
  end
50
43
  end
@@ -0,0 +1,28 @@
1
+ module AlexaRuby
2
+ # User device parameters
3
+ class Device
4
+ attr_reader :id, :interfaces
5
+
6
+ # Initialize new device
7
+ #
8
+ # @param device [Hash] user device parameters
9
+ # @raise [ArgumentError] if device ID is nil
10
+ def initialize(device)
11
+ raise ArgumentError, 'Missing device ID' if device[:deviceId].nil?
12
+ @id = device[:deviceId]
13
+ load_interfaces(device[:supportedInterfaces])
14
+ end
15
+
16
+ private
17
+
18
+ # Load supported interfaces
19
+ #
20
+ # @param device [Hash] supported interfaces list
21
+ def load_interfaces(device)
22
+ @interfaces = []
23
+ device.each do |k, _|
24
+ @interfaces << k
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module AlexaRuby
2
+ # Amazon Alexa user
3
+ class User
4
+ attr_reader :id, :access_token, :permissions_token
5
+
6
+ # Initialize new user
7
+ #
8
+ # @param user [Hash] user parameters
9
+ # @raise [ArgumentError] if user ID is nil
10
+ def initialize(user)
11
+ raise ArgumentError, 'Missing user ID' if user[:userId].nil?
12
+ @id = user[:userId]
13
+ @access_token = user[:accessToken] unless user[:accessToken].nil?
14
+ return if user[:permissions].nil?
15
+ @permissions_token = permissions(user[:permissions])
16
+ end
17
+
18
+ private
19
+
20
+ # Get user permissions token
21
+ #
22
+ # @param permissions [Hash] user permissions object
23
+ # @return [String] user permissions consent token
24
+ def permissions(permissions)
25
+ permissions[:consentToken] unless permissions[:consentToken].nil?
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ module AlexaRuby
2
+ # Amazon Alexa request context - application, user and device info
3
+ class Context
4
+ attr_reader :app_id, :user, :device, :api_endpoint
5
+
6
+ # Initialize new Context object
7
+ #
8
+ # @param context [Hash] request context parameters
9
+ # @raise [ArgumentError] if application ID, or user ID, or device ID are nil
10
+ def initialize(context)
11
+ @app_id = get_app_id(context[:System][:application])
12
+ raise ArgumentError, 'Missing application ID' unless @app_id
13
+
14
+ @user = load_user(context[:System][:user])
15
+ @device = load_device(context[:System][:device])
16
+ @api_endpoint = context[:System][:apiEndpoint]
17
+ end
18
+
19
+ private
20
+
21
+ # Get application ID
22
+ #
23
+ # @param app [Hash] application parameters
24
+ # @return [String] application ID
25
+ def get_app_id(app)
26
+ app[:applicationId] unless app[:applicationId].nil?
27
+ end
28
+
29
+ # Initialize user parameters
30
+ #
31
+ # @param params [Hash] user parameters
32
+ # @return [Object] new User object instance
33
+ def load_user(params)
34
+ User.new(params)
35
+ end
36
+
37
+ # Initialize user device parameters
38
+ #
39
+ # @param params [Hash] user device parameters
40
+ # @return [Object] new Device object instance
41
+ def load_device(params)
42
+ Device.new(params)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,60 @@
1
+ module AlexaRuby
2
+ # Amazon Alexa user session
3
+ class Session
4
+ attr_reader :id, :attributes, :end_reason, :error
5
+ attr_accessor :state
6
+
7
+ # Initialize new Session
8
+ #
9
+ # @param session [Hash] session parameters
10
+ # @raise [ArgumentError] if user session data is absent
11
+ def initialize(session)
12
+ @session = session
13
+ raise ArgumentError, 'Empty user session' if invalid_session?
14
+
15
+ @state = @session[:new] ? :new : :old
16
+ @id = @session[:sessionId]
17
+ @attributes = @session[:attributes] || {}
18
+ end
19
+
20
+ # Set session end reason
21
+ #
22
+ # @param reason [String] reason type from Amazon Alexa request
23
+ def end_reason=(reason)
24
+ @end_reason =
25
+ case reason
26
+ when 'USER_INITIATED'
27
+ :user_quit
28
+ when 'ERROR'
29
+ :processing_error
30
+ when 'EXCEEDED_MAX_REPROMPTS'
31
+ :user_idle
32
+ end
33
+ end
34
+
35
+ # Set error parameters
36
+ #
37
+ # @param err [Hash] error params
38
+ def error=(err)
39
+ @error = { message: err[:message] }
40
+ @error[:type] =
41
+ case err[:type]
42
+ when 'INVALID_RESPONSE'
43
+ :invalid_alexa_ruby_response
44
+ when 'DEVICE_COMMUNICATION_ERROR'
45
+ :device_error
46
+ when 'INTERNAL_ERROR'
47
+ :runtime_error
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ # Check if it is an invalid user session
54
+ #
55
+ # @return [Boolean]
56
+ def invalid_session?
57
+ @session.nil?
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,53 @@
1
+ module AlexaRuby
2
+ # Amazon Alexa web service request
3
+ class BaseRequest
4
+ attr_reader :version, :type, :session, :context, :id, :timestamp, :locale
5
+
6
+ # Initialize new request object
7
+ #
8
+ # @param request [Hash] request from Amazon Alexa web service
9
+ def initialize(request)
10
+ @req = request
11
+ @version = @req[:version]
12
+ @session = parse_session unless @type == :audio_player
13
+ @context = parse_context
14
+ @id = nil
15
+ @timestamp = nil
16
+ @locale = nil
17
+ parse_base_params(@req[:request])
18
+ end
19
+
20
+ # Return JSON representation of given request
21
+ #
22
+ # @return [String] request json
23
+ def json
24
+ Oj.to_json(@req)
25
+ end
26
+
27
+ private
28
+
29
+ # Build session object
30
+ def parse_session
31
+ Session.new(@req[:session])
32
+ end
33
+
34
+ # Build a request context object
35
+ #
36
+ # @return [Object] new Context object instance
37
+ def parse_context
38
+ Context.new(@req[:context])
39
+ end
40
+
41
+ # Set request parameters
42
+ #
43
+ # @param req [Hash] request parameters
44
+ # @raise [ArgumentError] if missing ID or timestamp
45
+ def parse_base_params(req)
46
+ @id = req[:requestId] unless req[:requestId].nil?
47
+ raise ArgumentError, 'Missing request ID' unless @id
48
+ @timestamp = DateTime.parse(req[:timestamp]) unless req[:timestamp].nil?
49
+ raise ArgumentError, 'Missing request timestamp' unless @timestamp
50
+ @locale = req[:locale] unless req[:locale].nil?
51
+ end
52
+ end
53
+ end
@@ -1,23 +1,40 @@
1
1
  module AlexaRuby
2
2
  # Class that encapsulates each slot
3
3
  class Slot
4
- attr_accessor :name, :value
4
+ attr_accessor :name, :value, :confirmation_status
5
5
 
6
6
  # Initialize slot and define its name and value
7
7
  #
8
- # @param name [String] slot name
9
- # @param value [String] slot value
10
- def initialize(name, value)
11
- raise ArgumentError, 'Need a name and a value' if name.nil? || value.nil?
12
- @name = name
13
- @value = value
8
+ # @param slot [Hash] slot parameters
9
+ def initialize(slot)
10
+ @slot = slot
11
+ raise ArgumentError, 'Missing slot parameters' if invalid_slot?
12
+ @name = @slot[:name]
13
+ @value = @slot[:value]
14
+ @confirmation_status = define_confirmation_status
14
15
  end
15
16
 
16
- # Outputs Slot name and value
17
+ private
18
+
19
+ # Check if it is a valid slot or not
20
+ #
21
+ # @return [Boolean]
22
+ def invalid_slot?
23
+ @slot[:name].nil? || @slot[:value].nil?
24
+ end
25
+
26
+ # Define user confirmation status
17
27
  #
18
- # @return [String] Slot name and value
19
- def to_s
20
- "Slot Name: #{name}, Value: #{value}"
28
+ # @return [Symbol] current confirmation status
29
+ def define_confirmation_status
30
+ case @slot[:confirmationStatus]
31
+ when 'NONE'
32
+ :unknown
33
+ when 'CONFIRMED'
34
+ :confirmed
35
+ when 'DENIED'
36
+ :denied
37
+ end
21
38
  end
22
39
  end
23
40
  end
@@ -1,61 +1,60 @@
1
- require 'alexa_ruby/request/intent_request/slot'
2
-
3
1
  module AlexaRuby
4
2
  # IntentRequest class implements Alexa "IntentRequest" request type
5
- class IntentRequest < Request
6
- attr_accessor :intent, :name, :slots
3
+ class IntentRequest < BaseRequest
4
+ attr_reader :intent_name, :dialog_state, :confirmation_status, :slots
7
5
 
8
6
  # Initialize new Intent request
9
7
  #
10
- # @param json [JSON] valid JSON request from Amazon
11
- def initialize(json)
12
- @intent = json[:request][:intent]
13
- if @intent.nil?
14
- raise ArgumentError, 'Intent should exist on an IntentRequest'
15
- end
16
-
8
+ # @param request [Hash] valid request from Amazon Alexa service
9
+ def initialize(request)
17
10
  @type = :intent
18
- @name = @intent[:name]
19
- @slots = @intent[:slots]
20
-
21
11
  super
22
- end
23
-
24
- # Takes a Hash object with slots and add it to slots node
25
- #
26
- # @param slots [Hash] hash with slots data
27
- def add_hash_slots(slots)
28
- raise ArgumentError, 'Slots can\'t be empty' if slots.nil?
29
- slots.each do |slot|
30
- @slots[:slot[:name]] = Slot.new(slot[:name], slot[:value])
12
+ if @req[:request][:intent].nil?
13
+ raise ArgumentError, 'Intent must be defined'
31
14
  end
32
- @slots
15
+ @intent = @req[:request][:intent]
16
+ @dialog_state = define_dialog_state
17
+ @intent_name = @intent[:name]
18
+ @confirmation_status = define_confirmation_status
19
+ parse_slots unless @intent[:slots].nil?
33
20
  end
34
21
 
35
- # Takes a JSON with slots and add it to slots node
22
+ private
23
+
24
+ # Define current dialog state
36
25
  #
37
- # @param slots [JSON] json object with slots data
38
- def add_slots(slots)
39
- slot_hash = Oj.load(slots, symbol_keys: true)
40
- add_hash_slots(slot_hash)
26
+ # @return [Symbol] current dialog state
27
+ def define_dialog_state
28
+ case @req[:request][:dialogState]
29
+ when 'STARTED'
30
+ :started
31
+ when 'IN_PROGRESS'
32
+ :in_progress
33
+ when 'COMPLETED'
34
+ :completed
35
+ end
41
36
  end
42
37
 
43
- # Adds a slot from a name and a value
38
+ # Define user confirmation status
44
39
  #
45
- # @param name [String] slot name
46
- # @param value [String] slot value
47
- # @return [Object] new slot object
48
- def add_slot(name, value)
49
- slot = Slot.new(name, value)
50
- @slots[:name] = slot
51
- slot
40
+ # @return [Symbol] current confirmation status
41
+ def define_confirmation_status
42
+ case @intent[:confirmationStatus]
43
+ when 'NONE'
44
+ :unknown
45
+ when 'CONFIRMED'
46
+ :confirmed
47
+ when 'DENIED'
48
+ :denied
49
+ end
52
50
  end
53
51
 
54
- # Outputs the Intent Name, request Id and slot information
55
- #
56
- # @return [String] Intent Name, request Id and slot information
57
- def to_s
58
- "IntentRequest: #{name} requestID: #{request_id} Slots: #{slots}"
52
+ # Parse slots and initialize each slot
53
+ def parse_slots
54
+ @slots = []
55
+ @intent[:slots].each do |_, v|
56
+ @slots << Slot.new(v)
57
+ end
59
58
  end
60
59
  end
61
60
  end