Skip to content

Commit

Permalink
add complete example in action
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Mar 25, 2021
1 parent 97c6834 commit 0f306c2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions docs/custom_responder.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added docs/images/responders/custom_example_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0f306c2

Please sign in to comment.