class DvelpFlow::Responders::Base

Attributes

content[RW]
session_uuid[RW]

Public Class Methods

new(params: {}) click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 6
def initialize(params: {})
  self.content = params[:content]
  self.session_uuid = params[:session_uuid]
end

Public Instance Methods

content_chain() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 20
def content_chain
  DvelpFlow.cache.read("contents/#{session_uuid}") || []
end
final?() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 16
def final?
  !intent_parser.parameters.include? :continue
end
to_s() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 11
def to_s
  create_interaction
  intent_parser.speech
end

Private Instance Methods

api_intent_response() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 45
def api_intent_response
  intent_ai_client.text_request(content)
end
create_interaction() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 28
def create_interaction
  DvelpFlow.cache.write(
    "contents/#{session_uuid}",
    content_chain << content,
    expires_in: 5.minutes
  )
end
intent_ai_client() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 49
def intent_ai_client
  @intent_ai_client ||= DvelpFlow::DialogFlow::Client.init(
    access_token: DvelpFlow::Google::Auth::Token.fetch!,
    api_session_id: session_uuid
  )
end
intent_parser() click to toggle source
# File lib/dvelp_flow/responders/base.rb, line 36
def intent_parser
  klass = Object.const_get(
    "::DvelpFlow::Parsers::V#{DialogFlow::VERSION}"
  )
  @intent_parser ||= klass.new(
    response: api_intent_response
  )
end