Sha256: d0617513f7d492e587bf70cab879da529f47d13d8e4fe2614541a0db05184fc8

Contents?: true

Size: 720 Bytes

Versions: 4

Compression:

Stored size: 720 Bytes

Contents

require 'json'

module Ralyxa
  class Request
    INTENT_REQUEST_TYPE = "IntentRequest".freeze

    def initialize(original_request)
      @request = JSON.parse(original_request.body.read)
    end

    def intent_name
      return @request["request"]["type"] unless intent_request?
      @request["request"]["intent"]["name"]
    end

    def slot_value(slot_name)
      @request["request"]["intent"]["slots"][slot_name]["value"]
    end

    def new_session?
      @request["session"]["new"]
    end

    def session_attribute(attribute_name)
      @request["session"]["attributes"][attribute_name]
    end

    private

    def intent_request?
      @request["request"]["type"] == INTENT_REQUEST_TYPE
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ralyxa-1.3.0 lib/ralyxa/request.rb
ralyxa-1.2.0 lib/ralyxa/request.rb
ralyxa-1.1.1 lib/ralyxa/request.rb
ralyxa-1.1.0 lib/ralyxa/request.rb