Comments (6)
@wasnotrice can you show me your regexes for your hear
and respond
? You may just need to build them with a bit more care.
The way the responders work is completely async. Each incoming message is dispatched to all responders. If a message matches a responder it will be run.
from hedwig.
@scrogson here's an example set of hear/respond invocations with regexes:
hear ~r/let (.*) know/, message do
sendRandomKnowledge message
end
respond ~r/let (.*) know/, message do
replyOrEmoteRandomly message
end
As you see, the regexes are the same. I guess my confusion comes from the fact that I don't expect the hear
responder to fire in the case where the regex matches, but the message is addressed to my bot. In that case, I only expect the respond
responder to fire. Likewise, if the regex matches, but the message is not addressed to my bot, then I expect the hear
responder to fire and not the respond
responder.
I don't think I articulated the issue well initially. You're right, of course, the responders are async so it doesn't make sense to talk about "if no respond
handler matches". The issue is really that (according to my mental model) hear
responders should only match messages that are not addressed to the bot, and respond
responders should only match messages that are addressed to the bot.
Am I thinking about it all wrong?
from hedwig.
@wasnotrice re-writing your hear
responder to this should work:
hear ~r/^let (.*) know/i, msg do
send_random_knowledge msg
end
That would ensure that it would only respond if the message begins with let
.
In any case, I guess I would need to see where other use-cases might really require a different implementation than I currently have.
from hedwig.
@scrogson hmmmmm, I see how anchoring the regex would filter out direct messages, so that is a workaround. But it would also mean that I can't match a message like please let me know
.
I could write a much more complicated regex that filtered out only messages starting with my bot's name/alias, but I'm looking for the framework to provide a macro for that, rather than having to code the regex for individual responders. If hear
is specifically designed to have this behavior, maybe there is the possibility of adding a third macro like overhear
, which would only fire for messages that are not addressed to the bot? I guess I could just write that here in my bot. Maybe that's a good place to start if it doesn't fit into Hedwig just yet.
FWIW, I am porting these responders from a Hubot bot, where they work as I expect (i.e. the hear
responder does not fire on direct messages).
Thanks!
from hedwig.
Gotcha. I will work on a solution. Thanks.
from hedwig.
@scrogson thanks! happy to pitch in and/or draft something if its helpful :)
from hedwig.
Related Issues (20)
- Support multiple configurations of the same adapter HOT 1
- Hedwig.whereis/1 not working HOT 2
- Can't compile responder when there are chinese characters in regular expression HOT 4
- Document return values from `handle_in/2`
- What is the recommended alternative to `ignore_from_self?` HOT 2
- how to test responders? HOT 2
- Process registration: `handle_connect` not being called? HOT 3
- Double supervision HOT 1
- Make Robot a real OTP behaviour HOT 4
- Making a tutorial / howto regarding adapters HOT 6
- Crash when trying to create a secure connection HOT 3
- enter responder macro HOT 4
- hot code reload responders when in dev mode
- Use up and down arrows for history in console adapter HOT 1
- Reconnect does not work HOT 7
- `hedwig` package published on hex is out of date HOT 3
- Defining adapter-dependent actions HOT 2
- Support multiple AKA fields
- Ability to listen but not respond HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hedwig.