ttaylorr / slacker

A loosely coupled, flexible chat-bot framework.
MIT License
25 stars 7 forks source link

Add JSON Responder module #9

Closed justinhennessy closed 10 years ago

justinhennessy commented 10 years ago

This module sets up a rapid mechanism for people to develop Slacker plugins that call an HTTP end point then render the JSON returned for use in slacker.

So here is a simple scenario, I have an HTTP service that tells me what my IP is:

http://jsonip.com

And when called this is what it returns:

{"ip"=>"xxx.xxx.xxx.xxx", "about"=>"/about", "Pro!"=>"http://getjsonip.com"}

So with JSON Responder you can build a plugin as follows:

require_relative 'json_responder'

module Slacker
  class MyIP < Plugin
    include JSONResponder

    def help
      "slacker myip"
    end

    def pattern
      /myip/i
    end

    def url_for
      'http://jsonip.com'
    end

    def process_response (result)
      result["ip"]
    end

    Bot.register(MyIP)
  end
end
ttaylorr commented 10 years ago

Awesome!