Class: Jambots::Controllers::ChatController

Inherits:
Object
  • Object
show all
Defined in:
lib/jambots/controllers/chat_controller.rb

Constant Summary collapse

DEFAULT_BOT =
"jambot"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ChatController

Returns a new instance of ChatController.



7
8
9
10
# File 'lib/jambots/controllers/chat_controller.rb', line 7

def initialize(options)
  @options = options
  @renderer = Jambots::Renderer.new
end

Instance Method Details

#chat(query) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jambots/controllers/chat_controller.rb', line 12

def chat(query)
  bot = Jambots::Bot.new(
    @options[:bot] || DEFAULT_BOT,
    path: Jambots::Bot.find_path(@options[:path])
  )

  last = @options[:last]
  previous_conversation = last ? bot.conversations.last : bot.load_conversation(@options[:conversation])

  conversation = previous_conversation || bot.new_conversation

  @renderer.spinner.auto_spin
  message = bot.message(query, conversation)
  @renderer.spinner.success
  @renderer.render(message, conversation)
end