I am making a slack bot. I have been using python slackclient library to develop the bot. Its working great with one team. I am using Flask Webframework.
As many people add the app to slack via "Add to Slack" button, I get their bot_access_token.
Now how should I run the code with so many Slack tokens. Should I store them in a list and then traverse using for loops for all token! But this was is not good as I may not be able to handle the simultaneous messages or events I receive Or "its a good way". Any other way if its not?
If you're using the real-time API, you'll need one WebSocket open per team. Yes, you would typically use a loop to establish these connections. Depending on the way slackclient
works, you might need to start each in a separate thread or process.
EDIT: As mentioned in the comments below, threading is to be preferred over multiple processes. Even better would be to use something lighter weight than threads, but at this point in your learning, I wouldn't bother over-optimizing here.
SECOND EDIT: It looks like python-slackclient
has non-blocking reads, so you don't even need to use threads. E.g. the following will not block:
for team in teams:
for event in team.client.rtm_read():
# process the event for that team
(This assumes some sort of "team" object that contains an instance of SlackClient
.)