-
Notifications
You must be signed in to change notification settings - Fork 273
Description
Hi,
I have created this issue in order to clarify some issues and questions I have regarding the code and the Slack integration approach. I have read official Slack integration document available here: https://api.slack.com/start/building/bolt-python, but there is very little explanation in regards to the internal implementation.
I'm trying to implement Slack integration for the Django-based software that handles multiple user accounts. Each account can request installation of the app to individual Slack workspace (using OAuth), and I have based my current implementation on examples available here: https://github.com/slackapi/bolt-python/tree/main/examples/django/oauth_app
-
What is the difference between
SlackBotandSlackInstallationobjects?
This is a very basic question but I just can figure out the differences/relation between those two models. When should the installation, and when the bot should be used? Could you point me to some document describing the differences? I see that those two database models share a lot of fields, could this be streamlined, e.g. installation having multiple bots, etc.? -
Why store
client_idvalue inSlackBotdatabase object?
From what I understand theclient_idis a sensitive value. It looks like (looking at the example datastore implementation) it is actually never used after saving it in the database (https://github.com/slackapi/bolt-python/blob/main/examples/django/oauth_app/slack_datastores.py#L100). Could this field be omitted, and not stored within a database? -
Why store multiple instances of bot and installation objects in the database?
I don't understand the idea behind saving new instances of what is essentially the same SlackBot. Would a following code work better, or is there some specific reason multiple instances are required? There could be a unique constraint on (enterprise_id and team_id) pair in the database.
installation_data = installation.to_dict()
if is_naive(installation_data["installed_at"]):
installation_data["installed_at"] = make_aware(installation_data["installed_at"])
if SlackInstallation.objects.filter(
team_id=installation.team_id, enterprise_id=installation.enterprise_id,
).exists():
SlackInstallation.objects.filter(
team_id=installation.team_id, enterprise_id=installation.enterprise_id,
).update(**installation_data)
else:
SlackInstallation.objects.create(**installation_data)
-
Is it possible to link SlackBot/SlackInstallation object with an internal user account that initiated the app installation?
I would like to know which of my users installed bot. I'd like to add foreign key pointing to User model in the SlackBot, and have it filled in during installation process (taking user from django request object). From what I see, the exampleOAuthFlowobject hashandle_callbackmethod, but is called with slack request instead of django request object. -
Is it possible to request removal of the installed Slack app?
If the point 4. of this question is not possible, and the user would have to "connect/link" bot from the Slack workspace (e.g. by issuing some command asking for authorization), would it be possible to remove bots that have not been linked after certain period and expire their tokens? I'd like to do this for safety reasons.
Imagine the following situation:
a) User installs the app in the Slack workspace
b) User invites the bot the channel, but does not authorize it in my app (I have SlackBot with no User object connected in my database)
c) Malicious actions steal bot details
d) I delete bot details after certain time during which the bot has not been linked to the User account in my system (user forgot or was unable to authorize bot in my app)
c) Having the `token` and bot details mailicious code could (potentially) send messages to the channel the bot has been invited to, creating a situation in which user is presented with messages not coming from my system
I would like to ensure that the bot token is invalidated during its removal from my database.