GithubHelp home page GithubHelp logo

Simple example project about slacker HOT 6 CLOSED

supermomonga avatar supermomonga commented on July 19, 2024
Simple example project

from slacker.

Comments (6)

emiln avatar emiln commented on July 19, 2024

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:

  1. Run things in a REPL (this is dreadful for deployment).
  2. End your -main function with something that doesn't return.
  3. 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.

emiln avatar emiln commented on July 19, 2024

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.

emiln avatar emiln commented on July 19, 2024

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.

supermomonga avatar supermomonga commented on July 19, 2024

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.

emiln avatar emiln commented on July 19, 2024

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.

supermomonga avatar supermomonga commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.