question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manually call a .respond listener

See original GitHub issue

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

module.exports = (robot) ->
  robot.respond /hello!/i, (msg) ->
      msg.send "Hello to you too, sir!"
      # Something here to call the below listener and have Hubot also wish the user a great day

  robot.respond /have a great day/i, (msg) ->
      msg.send "I wish upon you a fantastic day, as well!"

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
xrysanthoscommented, Sep 28, 2017

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.

0reactions
stale[bot]commented, May 30, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

call component Listener manually - java - Stack Overflow
I know I'm a bit late, but this should do the trick: ItemListener listener = new ItemListener() { public void itemStateChanged(ItemEvent e) {...
Read more >
Firing a listener without firing an event first. - Laracasts
Is there a way to cause a listener to run manually without having an event fired first? Kind of like running it like...
Read more >
Using a Request Object Event Listener - AWS Documentation
Use a request object event listener for asynchronous calls with the SDK for JavaScript. ... Request object that must be manually sent using...
Read more >
JavaScript Event Listeners Ultimate Guide
This function is called every time the event occurs and the event object contains information about the event. Depending on what event you ......
Read more >
Introduction to Event Listeners (The Java™ Tutorials ...
One of the event listeners (an instance of a class called MultiListener ) listens for events from both buttons. When it receives an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found