A Django app to help integrate Slack
Project description
Django Slack Integration
This application helps you to integrate your existing Django application with Slack.
It provides you with
- Models - needed to keep information from Slack API
- Decorators - help you to write implementation of your Slack endpoints
- Authorisation backend - allows you to pair your existing user model with your Slack users
- Views - OAuth callbacks for "Add To Slack" and "Login With Slack" actions
Installation
-
Add 'slack_app' to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'slack_app', ... ]
-
Include the urls in your project
urls.py
like this:path('slack/', include('slack_app.urls')),
-
Run
python manage.py migrate
to create theslack_app
models. -
Add
slack_app.auth_backends.SlackAuthenticationBackend
to yourAUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', 'slack_app.auth_backends.SlackAuthenticationBackend', ]
-
Update your
settings.py
SLACK_CLIENT_ID="" SLACK_CLIENT_SECRET="" SLACK_SIGNING_SECRET="" SLACK_LOGIN_OAUTH_REDIRECT_URL="" SLACK_INSTALL_OAUTH_REDIRECT_URL=""
-
Add following URLs to your Slack app's Redirect URLs (OAuth & Permissions)
<your_host>/slack/oauthcallback/ <your_host>/slack/login/
-
(Optional) Put
<your_host>/slack/interactivity/
as your Request URL inInteractive Components
section -
(Optional) Configure your Slash commands's Request URL as
<your_host>/slack/commands/<command_name>/
Usage
Slack commands
If you want to create a new Slack command with name /example
, configure your Request URL as <your_host>/slack/commands/example/
and put the following code into slack.py
inside your app's directory.
@slack_command('example', require_linked_account=True)
def scrumie_staging_command(request, slack_user_mapping, slack_workspace):
print(slack_user_mapping, slack_workspace)
return JsonResponse({
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello _world_"
},
}
],
"text": "Hello World"
})
Slack Interactivity
Put the following to your slack.py
inside your app's directory.
@slack_interactivity('block_actions')
def process_block_actions(payload):
print('>>>>', payload)
return HttpResponse()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_slack_app-1.0.32-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77b2e3fea34d7defeffa7fd3bf03b0a349ea3df13ed58b5a50f128773ff2ebc5 |
|
MD5 | b362fd96b99b6a2760b6c1e5a87f4ad3 |
|
BLAKE2b-256 | 9933af604f2ec73ddca183d8792d64842521fbf03d95c05985c6629ec2478f26 |