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
27
28
29
30
# 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   if !route.command
    return if response.matches.flatten[0].match(route.pattern)
  end

  if response.matches.flatten[0].match(/ところで|それはそうと|そういえば|BTW/)
    Lita.redis.del context_key(response)
  end

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