BlakeWilliams / Elixir-Slack

Slack real time messaging and web API client in Elixir
MIT License
674 stars 182 forks source link

Better support for handling multiple teams #158

Closed intentionally-left-nil closed 5 years ago

intentionally-left-nil commented 6 years ago

The Slack bot works fine if you just need to support one team. However, if you are making a server to support multiple teams, then you need to write code to support it. This is compounded by the problem that if permission is removed, you get a :ssl_socket exception, followed by an account_inactive message when trying to connect.

If you keep trying to re-connect at that point, you'll just deathroll until the supervisor stops restarting you.

I've solved this for my app with a combination of Worker https://github.com/AnilRedshift/yatlab-worker/blob/master/lib/worker.ex and TeamMonitor https://github.com/AnilRedshift/yatlab-worker/blob/master/lib/team_monitor.ex

This issue is to gauge the interest on whether a PR to make the code properly generic would be a welcomed PR to the repository

BlakeWilliams commented 6 years ago

I'd say I have some interest, but I'm curious if the use-case is common enough to warrant supporting it. Would adding a generic solution fit the majority of use-cases?

trojanh commented 6 years ago

I too have Slack bot for multiple teams and it automatically crashes without any Sentry error log. It makes our Slack app very unreliable. We get sentry error each time which is weird. @BlakeWilliams could you help me with some way to handle this so that we can make our Slack app reliable? even a quick rescue block will do. I am not sure where this code terminates in Slack callbacks.

(exit) {:remote, :closed}
gen_fsm.erl in :gen_fsm.terminate/7 at line 602
proc_lib.erl in :proc_lib.init_p_do_apply/3 at line 247
websocket_client in :websocket_client.init/1

or 

(exit) {:error, :nxdomain}
gen_fsm.erl in :gen_fsm.terminate/7 at line 602
proc_lib.erl in :proc_lib.init_p_do_apply/3 at line 247
websocket_client in :websocket_client.init/1
r0zar commented 5 years ago

Yes, having the multi-bot "Add to Slack" app button functionality is essential for my use case. Would really be interested to see if that can be added. I'll have to roll my own otherwise.

BlakeWilliams commented 5 years ago

@trojanh I obviously missed this, so sorry about that. That looks like it's blowing up on websocket_client's side which I don't have much control over.

BlakeWilliams commented 5 years ago

@r0zar I currently have no plans to implement explicit support for single bot multi-slack support. If someone comes up with a good plan and has interest in implementing it I'm not opposed to working with them to get it in though.

BlakeWilliams commented 5 years ago

Closing this for now due to it not being on my radar. If someone wishes to tackle this we can reopen this issue or open a new issue to discuss a strategy around supporting that functionality.

trojanh commented 5 years ago

Thanks, @BlakeWilliams for this package, it makes development a lot faster and overall manages to get the job done.

We wrote a detailed blog on how we went about creating Slack bot and how we handled the crashes and still managed to make it recover from crashes using Supervisors.

Adding a link here for anyone looking for a fix to handle crashes or creating a Slack bot in general.

https://blog.kiprosh.com/developing-a-slack-bot-in-elixir-phoenix/

BlakeWilliams commented 5 years ago

@trojanh Great writeup! Glad you could get some use out of the library. :)