diff --git a/docs/custom_responder.md b/docs/custom_responder.md index 1a5fd030..69b9598a 100644 --- a/docs/custom_responder.md +++ b/docs/custom_responder.md @@ -248,13 +248,54 @@ module Myorganization "@#{bot_name} #{params[:command] || 'what time is it?'}" end end +end +``` + +## Sample custom responder + +The final version of our clock responder (in `app/responders/myorganization/clock_responder.rb`): +```ruby +require_relative '../../lib/responder' + +module Myorganization + class ClockResponder < Responder + keyname :clock + + def define_listening + @event_action = "issue_comment.created" + @event_regex = /\A@#{bot_name} #{clock_command}\s*\z/i + end + + def process_message(message) + respond(Time.now.strftime("⏱ The time is %H:%M:%S %Z, today is %d-%m-%Y ⏱")) + end - def example_invocation - "@#{bot_name} #{params[:command] || 'what time is it?'}" + def clock_command + params[:command] || "what time is it\\?" + end + + def description + "Get the current time" + end + + def example_invocation + "@#{bot_name} #{params[:command] || 'what time is it?'}" + end end end ``` +Adding its key to the configuration file in the responder settings: +```yaml +buffy: + responders: + clock: +... +``` + +The responder should be available and ready to use: + +![](./images/responders/custom_example_1.png "Custom responder in action: clock responder") ## Tests diff --git a/docs/images/responders/custom_example_1.png b/docs/images/responders/custom_example_1.png new file mode 100644 index 00000000..a07cf311 Binary files /dev/null and b/docs/images/responders/custom_example_1.png differ