class Lita::Handlers::Motionai

Public Instance Methods

anything(response) click to toggle source
# 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
client() click to toggle source
# 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