Class: Lita::Handlers::Talk

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/talk.rb

Instance Method Summary collapse

Instance Method Details

#talk(response) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lita/handlers/talk.rb', line 12

def talk(response)
  @robot.handlers.map do |handler|
    next nil if handler == self.class
    next nil unless handler.respond_to?(:routes)
    handler.routes
  end.flatten.compact.each do |route|
    next unless route.command
    return if response.message.body.match(route.pattern)
  end

  context = Lita.redis.get context_key(response)
  api_response = client.create_dialogue(response.message.body, params(context))
  Lita.redis.set context_key(response), api_response.body["context"]
  response.reply api_response.body["utt"]
end