-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually call a .respond listener #823
Comments
For your own scripts, I've found it most useful to have functions that multiple listeners can call. For using other listeners, there's not really a simple way of getting listeners and calling them. That said, you can probably experiment a bit to find a way. Here's some pointers:
So basically, you might be able to loop over robot.listeners to get a specific listener. Then, construct a Message object and then Kinda related is #803 which would add support to listeners to have metadata, which would make it easier to identify in the array. |
Thanks for the input 👍 I agree, the most useful and best practice way would be to abstract out the deeper stuff. As you said, have functions that multiple listeners can call. |
As soon as #803 merges, I've got a commit queued up to add In a unit test scenario: describe 'listener "get-room-oncall"', ->
it 'should match "who is oncall?"', (testDone) ->
listener = @robot.listenerById 'get-room-oncall'
# Stub out the real work; just testing the match
listener.callback = sinon.stub() # private API
testMessage = new TextMessage @user, "TestHubot: who is oncall?"
listener.call testMessage, (result) -> # private API
expect(result).to.be.ok
testDone() The relevant bit of script would be: module.exports = (robot) ->
robot.respond /who is oncall?/, id: 'get-room-oncall', (response) ->
# it does stuff |
i'm interested in being able to do this too, it seems kind of odd that I can't arbitrarily send a message back to hubot and chain event togethers. |
@radius314 What exactly are you trying to accomplish? While I hope to enable listener retrieval soon, I envision manual invocation as an edge case ( |
Opened #1031 to add |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi all! This type of functionality is really important when it comes down to re-using behind the scenes 3rd party script packs. For example if I'm building a script pack for my specific business context it would be great if I could just execute one or more commands exposed by another library (e.g. google maps scripts, etc) explicitly by using its text patterns. This way developers can really work on the semantic layer of things without having to worry about internal listener IDs and other low-level stuff. @michaelansel solution is clean but cannot work with existing libraries if no IDs have been specified for each listener. For example if my listener hears for: get service x location and I'm using hubot_maps as a dependency, my service would return the location details in the controller and if I wanted to enrich the message with geo info I'd just have an extra step calling hubot map me 'query' passing the coordinates, get its response and return the enriched message. Command composition is definitely a great way of leveraging re-usability. |
I'm wondering if there's a best practice way of manually calling a
.respond
listener. In some instances, it would be great if I could manually call one and let params go through as default (eg,msg.match[1]
for example will match nothing and fallback to default).Normally, the action performed by the listener being called would be abstracted out but I'm just curious if anyone else has gone this way.
For example
The text was updated successfully, but these errors were encountered: