Sha256: 82995c146c75afae8018cab4899414369c97b99716456ad97a194ffaa86e07a1

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

require_relative './response_builder'
require_relative './response_entities/card'

# Handler Base Class. Each Intent Handler inherits from this, and overwrites the #handle method.
module Ralyxa
  class Handler
    def initialize(request)
      @request = request
    end

    def handle
      raise NotImplementedError
    end

    def respond(response_text = '', response_details = {}, response_builder = Ralyxa::ResponseBuilder)
      options = response_details
      options[:response_text] = response_text if response_text

      response_builder.build(options)
    end

    def tell(response_text = '', response_details = {})
      respond(response_text, response_details.merge(end_session: true))
    end

    def card(title, body, image_url = nil, card_class = Ralyxa::ResponseEntities::Card)
      card_class.as_hash(title, body, image_url)
    end

    def audio_player
      Ralyxa::ResponseEntities::Directives::AudioPlayer
    end

    def link_account_card(card_class = Ralyxa::ResponseEntities::Card)
      card_class.link_account
    end

    def log(level, message)
      puts "[#{Time.new}] [#{@request.user_id}] #{level} - #{message}"
    end

    alias ask respond

    attr_reader :request
    private :request, :respond, :tell, :ask
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
ralyxa-lambda-1.9.0 lib/ralyxa/handler.rb
ralyxa-lambda-1.8.0 lib/ralyxa/handler.rb
ralyxa-1.8.0 lib/ralyxa/handler.rb
ralyxa-1.7.0 lib/ralyxa/handler.rb