Comments (6)
Hi, @supermomonga, and thank you for your interest in the project.
Your confusion stems mostly from my own inability to decide on a good way to keep the JVM running. I'm having the exact same issue myself, and my solution is not exactly elegant.
The heart of the issue is that emit!
returns immediately, and that nothing spawned by the library prevents the JVM from exiting. Your -main
function simply exits, and soon after the JVM follows. This is not really what you want with a bot, I will be the first to admit. I can list a number of ways to prevent this:
- Run things in a REPL (this is dreadful for deployment).
- End your
-main
function with something that doesn't return. - Something better?
As to 1, I'm sure you will not find it very appealing if you intend to deploy it anywhere. I know I don't. It works well for development, though.
2 is quick, easy, and dirty. Assuming you're requiring <!
and timeout
from clojure.core.async
, you can do something like:
(defn -main
[& args]
(emit! :slacker.client/connect-bot api-token)
(loop []
(<! (timeout 1000))
(recur)))
It's not great, but it has worked for my own bots.
Regarding 3, I'd really like to force the JVM to keep running, but I'm not actually that knowledgeable in terms of the JVM. If you have any good ideas I'll be happy to implement them. The idea as I imagine it is to have :slack.client/connect-bot
spawn something that prevents the JVM from shutting down. Perhaps a Java Thread might suffice.
PS:
While your ping-pong implementation is exactly how I'd imagine it should be, I'm actually reading the Slack API the other way around entirely: To signal activity you should ping, and they will pong.
I hope this helps. In any case I'm happy to help you further, so be sure to report back.
/Emil
from slacker.
I gave it some thought and I actually think a nice solution would be the ability to await the closing of the open bot connection. This would be a blocking call and would allow code like:
(defn -main
[& args]
(emit! :slacker.client/connect-bot api-token)
(await! :slacker.client/bot-disconnected))
This would leave your main function (and hence the JVM) running until the bot disconnects for some reason. You should probably use the infinite loop work around until I release the above idea in the next version, but I hope I can find the time this weekend to do so.
from slacker.
I do apologize for the sheer amounts of notifications this must be generating, but I've released a new version of Slacker: 1.5.0. This should allow for the await-based flow I've described above, and hopefully that will make the experience better.
from slacker.
Thanks for your reply, and implement await feature so quickly, that seems awesome!
I'll try it today to make my example app works.
I'm sorry but I'm Clojure newbie so I will probably ask you some questions about this feature.
from slacker.
I just cloned your repo, and it seems to keep the JVM running now. If you have any further questions, be sure to let me know. slacker
was a library born out of my own necessity as I needed a means of writing some event hooks for a Slack bot, but I would be very pleased if it proves useful for other people as well.
It has been developed on a "You Ain't Gonna Need It"-basis, and it will probably continue to be so. As such it has only the features I've needed, but I am very interested in hearing about the needs of other Slack bot writers. It doesn't really matter if it's questions about usage, bugs, ideas for new features or whatnot. The library currently has a very fast turn-around time for new features, and adding them is quite fun.
from slacker.
I just cloned your repo, and it seems to keep the JVM running now.
Yeah, await!
seems works perfectly.
If you have any further questions, be sure to let me know. slacker was a library born out of my own necessity as I needed a means of writing some event hooks for a Slack bot, but I would be very pleased if it proves useful for other people as well.
It has been developed on a "You Ain't Gonna Need It"-basis, and it will probably continue to be so. As such it has only the features I've needed, but I am very interested in hearing about the needs of other Slack bot writers. It doesn't really matter if it's questions about usage, bugs, ideas for new features or whatnot. The library currently has a very fast turn-around time for new features, and adding them is quite fun.
Thank you for your explanation of your stance about develop slacker, and I understood that.
I have some thoughts about await!
feature so will create new issue later to discuss it.
from slacker.
Related Issues (20)
- Improve error handling in `handle` HOT 1
- Rename to avoid clash on Clojars HOT 1
- Better testing solution
- Fix clojars deployment
- Logging
- Web interface for monitoring bot health HOT 1
- Report errors HOT 1
- Awaiting response HOT 1
- Monitor websocket connectivity HOT 1
- Needs more core.typed HOT 2
- Improve unit test feedback
- emit! is incorrectly returning a go block HOT 1
- Rethink handle HOT 1
- Write a simple smoke test HOT 1
- Switch to Clojure 1.7 HOT 1
- Inappropriate NPE HOT 1
- slacker.client/receive-message seems passes no arguments HOT 2
- Expose Slack's HTTP API through Slacker
- Is there any way to detect connection fail? HOT 7
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 slacker.