django-slack-tools 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. django_slack_tools-0.1.0/LICENSE +21 -0
  2. django_slack_tools-0.1.0/PKG-INFO +113 -0
  3. django_slack_tools-0.1.0/README.md +92 -0
  4. django_slack_tools-0.1.0/django_slack_tools/__init__.py +1 -0
  5. django_slack_tools-0.1.0/django_slack_tools/app_settings.py +94 -0
  6. django_slack_tools-0.1.0/django_slack_tools/locale/ko_KR/LC_MESSAGES/django.po +446 -0
  7. django_slack_tools-0.1.0/django_slack_tools/slack_messages/__init__.py +0 -0
  8. django_slack_tools-0.1.0/django_slack_tools/slack_messages/admin/__init__.py +6 -0
  9. django_slack_tools-0.1.0/django_slack_tools/slack_messages/admin/mention.py +139 -0
  10. django_slack_tools-0.1.0/django_slack_tools/slack_messages/admin/message.py +128 -0
  11. django_slack_tools-0.1.0/django_slack_tools/slack_messages/admin/message_recipient.py +113 -0
  12. django_slack_tools-0.1.0/django_slack_tools/slack_messages/admin/messaging_policy.py +127 -0
  13. django_slack_tools-0.1.0/django_slack_tools/slack_messages/apps.py +11 -0
  14. django_slack_tools-0.1.0/django_slack_tools/slack_messages/backends/__init__.py +12 -0
  15. django_slack_tools-0.1.0/django_slack_tools/slack_messages/backends/base.py +94 -0
  16. django_slack_tools-0.1.0/django_slack_tools/slack_messages/backends/dummy.py +40 -0
  17. django_slack_tools-0.1.0/django_slack_tools/slack_messages/backends/logging.py +28 -0
  18. django_slack_tools-0.1.0/django_slack_tools/slack_messages/backends/slack.py +204 -0
  19. django_slack_tools-0.1.0/django_slack_tools/slack_messages/message.py +128 -0
  20. django_slack_tools-0.1.0/django_slack_tools/slack_messages/migrations/0001_initial.py +304 -0
  21. django_slack_tools-0.1.0/django_slack_tools/slack_messages/migrations/__init__.py +0 -0
  22. django_slack_tools-0.1.0/django_slack_tools/slack_messages/models/__init__.py +6 -0
  23. django_slack_tools-0.1.0/django_slack_tools/slack_messages/models/mention.py +73 -0
  24. django_slack_tools-0.1.0/django_slack_tools/slack_messages/models/message.py +116 -0
  25. django_slack_tools-0.1.0/django_slack_tools/slack_messages/models/message_recipient.py +59 -0
  26. django_slack_tools-0.1.0/django_slack_tools/slack_messages/models/messaging_policy.py +67 -0
  27. django_slack_tools-0.1.0/django_slack_tools/utils/__init__.py +0 -0
  28. django_slack_tools-0.1.0/django_slack_tools/utils/dict_template.py +55 -0
  29. django_slack_tools-0.1.0/django_slack_tools/utils/model_mixins.py +24 -0
  30. django_slack_tools-0.1.0/django_slack_tools/utils/slack/__init__.py +11 -0
  31. django_slack_tools-0.1.0/django_slack_tools/utils/slack/django.py +45 -0
  32. django_slack_tools-0.1.0/django_slack_tools/utils/slack/message.py +44 -0
  33. django_slack_tools-0.1.0/django_slack_tools/utils/slack/misc.py +29 -0
  34. django_slack_tools-0.1.0/django_slack_tools/utils/widgets.py +29 -0
  35. django_slack_tools-0.1.0/django_slack_tools/views.py +38 -0
  36. django_slack_tools-0.1.0/pyproject.toml +110 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Yuchan Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.1
2
+ Name: django-slack-tools
3
+ Version: 0.1.0
4
+ Summary: Little helpers working with Slack bot 🤖 in Django.
5
+ License: MIT
6
+ Author: Yuchan Lee
7
+ Author-email: lasuillard@gmail.com
8
+ Requires-Python: >=3.8,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: django (>=3.2,<5)
17
+ Requires-Dist: pydantic (>=2,<3)
18
+ Requires-Dist: slack-bolt (>=1,<2)
19
+ Description-Content-Type: text/markdown
20
+
21
+ # django-slack-tools
22
+
23
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
24
+ [![CI](https://github.com/lasuillard/django-slack-tools/actions/workflows/ci.yaml/badge.svg)](https://github.com/lasuillard/django-slack-tools/actions/workflows/ci.yaml)
25
+ [![codecov](https://codecov.io/gh/lasuillard/django-slack-tools/graph/badge.svg?token=c8kzjqjplF)](https://codecov.io/gh/lasuillard/django-slack-tools)
26
+
27
+ Little helpers working with Slack bot 🤖 in Django.
28
+
29
+ This project aims to implementing helpful features making Slack bot and providing reusable Django apps integrated with database.
30
+
31
+ ## ✨ Features
32
+
33
+ Key features are:
34
+
35
+ - [x] Reusable Django app for Slack messaging with various messaging backends for different environments
36
+
37
+ - [x] Database-backed Slack messaging policies with simple dictionary-based template
38
+
39
+ - [x] Message histories
40
+
41
+ - [x] Built-in admin for management working with Slack workspace
42
+
43
+ And more in future roadmap...
44
+
45
+ - [ ] Celery support for messaging backends, management and shortcut tasks, etc.
46
+
47
+ - [ ] Django template support
48
+
49
+ - [ ] New Django apps and helpers for Slack features such as modals, event subscription, etc.
50
+
51
+ Currently it is focused on messaging features. In future, hoping to bring more helpful features across Slack Bot ecosystem, such as event subscriptions, modals, bot interactions, etc.
52
+
53
+ ## 🚀 Installation
54
+
55
+ **django-slack-tools** supports Python 3.8+ and Django 3.2+. Supports for each deps will be dropped as soon as the ends of security updates.
56
+
57
+ Install the package:
58
+
59
+ ```bash
60
+ $ pip install django-slack-tools
61
+ ```
62
+
63
+ Add the app to the your Django settings:
64
+
65
+ ```python
66
+ INSTALLED_APPS = [
67
+ ...
68
+ "django.contrib.messages", # Used in admin
69
+ "django_slack_tools.slack_messages",
70
+ ...
71
+ ]
72
+ ```
73
+
74
+ Add configuration for application:
75
+
76
+ ```python
77
+ DJANGO_SLACK_TOOLS = {
78
+ # Module path to Slack Bolt application or callable returns the app
79
+ "SLACK_APP": "path.to.your.slack.app",
80
+
81
+ # Messaging backend configuration
82
+ "BACKEND": {
83
+ "NAME": "django_slack_tools.slack_messages.backends.SlackBackend",
84
+ "OPTIONS": {
85
+ # TODO(#44): Reasonable defaults to reduce some duplicates
86
+ "slack_app": "path.to.your.slack.app",
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ Then, run the database migration and send messages:
93
+
94
+ ```python
95
+ from django_slack_tools.slack_messages.message import slack_message
96
+
97
+ message = slack_message(
98
+ "I like threading",
99
+ channel="id-of-channel",
100
+ header={"reply_broadcast": True},
101
+ )
102
+ ```
103
+
104
+ Please check the [documentation](https://lasuillard.github.io/django-slack-tools/) for more about details.
105
+
106
+ ## 💖 Contributing
107
+
108
+ All contributions and helps are welcome. Please check the [CONTRIBUTING.md](./CONTRIBUTING.md) file for about details.
109
+
110
+ ## 📜 License
111
+
112
+ This project is licensed under the terms of the MIT license.
113
+
@@ -0,0 +1,92 @@
1
+ # django-slack-tools
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![CI](https://github.com/lasuillard/django-slack-tools/actions/workflows/ci.yaml/badge.svg)](https://github.com/lasuillard/django-slack-tools/actions/workflows/ci.yaml)
5
+ [![codecov](https://codecov.io/gh/lasuillard/django-slack-tools/graph/badge.svg?token=c8kzjqjplF)](https://codecov.io/gh/lasuillard/django-slack-tools)
6
+
7
+ Little helpers working with Slack bot 🤖 in Django.
8
+
9
+ This project aims to implementing helpful features making Slack bot and providing reusable Django apps integrated with database.
10
+
11
+ ## ✨ Features
12
+
13
+ Key features are:
14
+
15
+ - [x] Reusable Django app for Slack messaging with various messaging backends for different environments
16
+
17
+ - [x] Database-backed Slack messaging policies with simple dictionary-based template
18
+
19
+ - [x] Message histories
20
+
21
+ - [x] Built-in admin for management working with Slack workspace
22
+
23
+ And more in future roadmap...
24
+
25
+ - [ ] Celery support for messaging backends, management and shortcut tasks, etc.
26
+
27
+ - [ ] Django template support
28
+
29
+ - [ ] New Django apps and helpers for Slack features such as modals, event subscription, etc.
30
+
31
+ Currently it is focused on messaging features. In future, hoping to bring more helpful features across Slack Bot ecosystem, such as event subscriptions, modals, bot interactions, etc.
32
+
33
+ ## 🚀 Installation
34
+
35
+ **django-slack-tools** supports Python 3.8+ and Django 3.2+. Supports for each deps will be dropped as soon as the ends of security updates.
36
+
37
+ Install the package:
38
+
39
+ ```bash
40
+ $ pip install django-slack-tools
41
+ ```
42
+
43
+ Add the app to the your Django settings:
44
+
45
+ ```python
46
+ INSTALLED_APPS = [
47
+ ...
48
+ "django.contrib.messages", # Used in admin
49
+ "django_slack_tools.slack_messages",
50
+ ...
51
+ ]
52
+ ```
53
+
54
+ Add configuration for application:
55
+
56
+ ```python
57
+ DJANGO_SLACK_TOOLS = {
58
+ # Module path to Slack Bolt application or callable returns the app
59
+ "SLACK_APP": "path.to.your.slack.app",
60
+
61
+ # Messaging backend configuration
62
+ "BACKEND": {
63
+ "NAME": "django_slack_tools.slack_messages.backends.SlackBackend",
64
+ "OPTIONS": {
65
+ # TODO(#44): Reasonable defaults to reduce some duplicates
66
+ "slack_app": "path.to.your.slack.app",
67
+ }
68
+ }
69
+ }
70
+ ```
71
+
72
+ Then, run the database migration and send messages:
73
+
74
+ ```python
75
+ from django_slack_tools.slack_messages.message import slack_message
76
+
77
+ message = slack_message(
78
+ "I like threading",
79
+ channel="id-of-channel",
80
+ header={"reply_broadcast": True},
81
+ )
82
+ ```
83
+
84
+ Please check the [documentation](https://lasuillard.github.io/django-slack-tools/) for more about details.
85
+
86
+ ## 💖 Contributing
87
+
88
+ All contributions and helps are welcome. Please check the [CONTRIBUTING.md](./CONTRIBUTING.md) file for about details.
89
+
90
+ ## 📜 License
91
+
92
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,94 @@
1
+ """Application settings."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from logging import getLogger
6
+ from typing import Any, TypedDict
7
+
8
+ from django.conf import settings
9
+ from django.core.exceptions import ImproperlyConfigured
10
+ from django.utils.module_loading import import_string
11
+ from slack_bolt import App
12
+
13
+ from django_slack_tools.slack_messages.backends.base import BackendBase
14
+
15
+ APP_SETTINGS_KEY = "DJANGO_SLACK_TOOLS"
16
+ "Django settings key for this application."
17
+
18
+ logger = getLogger(__name__)
19
+
20
+
21
+ class AppSettings:
22
+ """Application settings."""
23
+
24
+ backend: BackendBase
25
+
26
+ def __init__(self, settings_dict: ConfigDict | None = None) -> None:
27
+ """Initialize app settings.
28
+
29
+ Args:
30
+ settings_dict: Settings dictionary. If `None`, try to load from Django settings (const `APP_SETTINGS_KEY`).
31
+ Defaults to `None`.
32
+
33
+ Raises:
34
+ ImproperlyConfigured: Required configuration not provided or is unexpected.
35
+ """
36
+ if not settings_dict:
37
+ settings_dict = getattr(settings, APP_SETTINGS_KEY, None)
38
+
39
+ if settings_dict is None:
40
+ msg = "Neither `settings_dict` provided or `django_slack_tools` settings found in Django settings."
41
+ raise ImproperlyConfigured(msg)
42
+
43
+ # Slack app
44
+ slack_app = settings_dict["SLACK_APP"]
45
+ if isinstance(slack_app, str):
46
+ slack_app = import_string(slack_app)
47
+
48
+ if callable(slack_app):
49
+ slack_app = slack_app()
50
+
51
+ if not isinstance(slack_app, App):
52
+ msg = "Provided `SLACK_APP` config is not Slack app."
53
+ raise ImproperlyConfigured(msg)
54
+
55
+ self._slack_app = slack_app
56
+
57
+ # Find backend class
58
+ messaging_backend = import_string(settings_dict["BACKEND"]["NAME"])
59
+ if not issubclass(messaging_backend, BackendBase):
60
+ msg = "Provided backend is not a subclass of `{qualified_path}` class.".format(
61
+ qualified_path=f"{BackendBase.__module__}.{BackendBase.__name__}",
62
+ )
63
+ raise ImproperlyConfigured(msg)
64
+
65
+ # Initialize with provided options
66
+ self.backend = messaging_backend(**settings_dict["BACKEND"]["OPTIONS"])
67
+
68
+ @property
69
+ def slack_app(self) -> App:
70
+ """Registered Slack app or `None`."""
71
+ return self._slack_app
72
+
73
+
74
+ app_settings = AppSettings()
75
+
76
+
77
+ class ConfigDict(TypedDict):
78
+ """Root config dict."""
79
+
80
+ SLACK_APP: App | str | None
81
+ "Import string to Slack app. Used for workspace-related stuffs."
82
+
83
+ BACKEND: BackendConfig
84
+ "Nested backend config."
85
+
86
+
87
+ class BackendConfig(TypedDict):
88
+ """Backend config dict."""
89
+
90
+ NAME: str
91
+ "Import path to backend class."
92
+
93
+ OPTIONS: dict[str, Any]
94
+ "Options to pass to backend class on initialization."