require "sinbotra/bot/conversation" require "sinbotra/bot/conversation_repo" require "sinbotra/bot/user" require "sinbotra/bot/user_repo" require "sucker_punch" module Sinbotra class Bot class << self def handle(provider, entry) Sinbotra::Config.logger.debug("ENTRY DEBUG:\n" + entry.inspect) if ENV["DEBUG"] #perform_async(provider, entry) new.perform(provider, entry) end def add_handler(provider, handler) @handlers ||= {} @handlers[provider.to_sym] = handler end def receive(provider, msg) handler = @handlers[provider.to_sym] Sinbotra::Config.logger.debug("MESSAGE DEBUG:\n" + msg.inspect) if ENV["DEBUG"] handler.handle_message(msg) end end include SuckerPunch::Job def perform(provider, msg) # THis needs to be done elsewhere msg["entry"].first["messaging"].each do |m| Sinbotra::Bot.receive(provider, m) end end end end