Class: Lita::Handlers::Motionai

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

Instance Method Summary collapse

Instance Method Details

#anything(response) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lita/handlers/motionai.rb', line 18

def anything(response)
  heard = response.match_data[1]
  Lita.logger.debug("Message Heard: [#{heard}]")

  res = client.message_bot msg: heard, session: response.user.id

  Lita.logger.debug(MultiJson.encode(res.body))

  if res.status == 200 && res.body.key?('botResponse')
    response.reply res.body['botResponse']
  else
    if res.status != 200
      Lita.logger.error("MotionAI API status #{res.status}")
    elsif !res.body.key? 'botResponse'
      Lita.logger.error("MotionAI API `botResponse` not found")
    end
  end
end

#clientObject



12
13
14
15
16
# File 'lib/lita/handlers/motionai.rb', line 12

def client
  return @_client if @_client
  @_client = MotionAI::Client.new config.api_key, config.bot_id
  return @_client
end