slackblocks 1.2.3__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.
- slackblocks-1.2.3/LICENSE +7 -0
- slackblocks-1.2.3/LICENSE.BSD-3-Clause +29 -0
- slackblocks-1.2.3/PKG-INFO +123 -0
- slackblocks-1.2.3/README.md +91 -0
- slackblocks-1.2.3/pyproject.toml +82 -0
- slackblocks-1.2.3/setup.py +26 -0
- slackblocks-1.2.3/slackblocks/__init__.py +77 -0
- slackblocks-1.2.3/slackblocks/attachments.py +196 -0
- slackblocks-1.2.3/slackblocks/blocks.py +575 -0
- slackblocks-1.2.3/slackblocks/elements.py +1739 -0
- slackblocks-1.2.3/slackblocks/errors.py +17 -0
- slackblocks-1.2.3/slackblocks/messages.py +288 -0
- slackblocks-1.2.3/slackblocks/modals.py +30 -0
- slackblocks-1.2.3/slackblocks/objects.py +624 -0
- slackblocks-1.2.3/slackblocks/rich_text/__init__.py +28 -0
- slackblocks-1.2.3/slackblocks/rich_text/elements.py +352 -0
- slackblocks-1.2.3/slackblocks/rich_text/objects.py +256 -0
- slackblocks-1.2.3/slackblocks/utils.py +228 -0
- slackblocks-1.2.3/slackblocks/views.py +168 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2019 Nicholas Lambourne
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019, Nicholas Lambourne
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: slackblocks
|
|
3
|
+
Version: 1.2.3
|
|
4
|
+
Summary: Python wrapper for the Slack Blocks API
|
|
5
|
+
Home-page: https://github.com/nicklambourne/slackblocks
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: slackblocks,slack,messaging,message generation,slack blocks,blocks
|
|
8
|
+
Author: Nicholas Lambourne
|
|
9
|
+
Author-email: dev@ndl.im
|
|
10
|
+
Maintainer: Nicholas Lambourne
|
|
11
|
+
Maintainer-email: dev@ndl.im
|
|
12
|
+
Requires-Python: >=3.8.1
|
|
13
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
27
|
+
Classifier: Topic :: Communications :: Chat
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Project-URL: Repository, https://github.com/nicklambourne/slackblocks
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# slackblocks <img src="https://github.com/nicklambourne/slackblocks/raw/master/docs_src/img/sb.png" align="right" width="250px"/>
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+

|
|
36
|
+

|
|
37
|
+
[](https://pypi.org/project/slackblocks/#history)
|
|
38
|
+
[](https://pepy.tech/project/slackblocks)
|
|
39
|
+
[](https://github.com/nicklambourne/slackblocks/actions)
|
|
40
|
+
[](https://nicklambourne.github.io/slackblocks)
|
|
41
|
+
|
|
42
|
+
## What is it?
|
|
43
|
+
`slackblocks` is a Python API for building messages in the fancy Slack [Block Kit API](https://api.slack.com/block-kit)
|
|
44
|
+
|
|
45
|
+
## Documentation
|
|
46
|
+
Full documentation is provided [here](https://nicklambourne.github.io/slackblocks/latest/).
|
|
47
|
+
|
|
48
|
+
## Requirements
|
|
49
|
+
`slackblocks` requires Python >= 3.8.
|
|
50
|
+
|
|
51
|
+
As of version 0.1.0 it has no dependencies outside the Python standard library.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
```bash
|
|
55
|
+
pip install slackblocks
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Basic Usage
|
|
59
|
+
```python
|
|
60
|
+
from slackblocks import Message, SectionBlock
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
block = SectionBlock("Hello, world!")
|
|
64
|
+
message = Message(channel="#general", blocks=block)
|
|
65
|
+
message.json()
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Will produce the following JSON string:
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"channel": "#general",
|
|
73
|
+
"mrkdwn": true,
|
|
74
|
+
"blocks": [
|
|
75
|
+
{
|
|
76
|
+
"type": "section",
|
|
77
|
+
"block_id": "992ceb6b-9ad4-496b-b8e6-1bd8a632e8b3",
|
|
78
|
+
"text": {
|
|
79
|
+
"type": "mrkdwn",
|
|
80
|
+
"text": "Hello, world!"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
Which can be sent as payload to the Slack message API HTTP endpoints.
|
|
87
|
+
|
|
88
|
+
Of more practical use is the ability to unpack the objects directly into
|
|
89
|
+
the [(Legacy) Python Slack Client](https://pypi.org/project/slackclient/) in order to send messages:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from os import environ
|
|
93
|
+
from slack import WebClient
|
|
94
|
+
from slackblocks import Message, SectionBlock
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
client = WebClient(token=environ["SLACK_API_TOKEN"])
|
|
98
|
+
block = SectionBlock("Hello, world!")
|
|
99
|
+
message = Message(channel="#general", blocks=block)
|
|
100
|
+
|
|
101
|
+
response = client.chat_postMessage(**message)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Or the modern Python [Slack SDK](https://pypi.org/project/slack-sdk/):
|
|
105
|
+
```python
|
|
106
|
+
from os import environ
|
|
107
|
+
from slack_sdk import WebClient
|
|
108
|
+
from slackblocks import Message, SectionBlock
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
client = WebClient(token=environ["SLACK_API_TOKEN"])
|
|
112
|
+
block = SectionBlock("Hello, world!")
|
|
113
|
+
message = Message(channel="#general", blocks=block)
|
|
114
|
+
|
|
115
|
+
response = client.chat_postMessage(**message)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Note the `**` operator in front of the `message` object.
|
|
119
|
+
|
|
120
|
+
## Can I use this in my project?
|
|
121
|
+
Yes, please do! The code is all open source and dual BSD-3.0 and MIT licensed
|
|
122
|
+
(use what suits you best).
|
|
123
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# slackblocks <img src="https://github.com/nicklambourne/slackblocks/raw/master/docs_src/img/sb.png" align="right" width="250px"/>
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
[](https://pypi.org/project/slackblocks/#history)
|
|
7
|
+
[](https://pepy.tech/project/slackblocks)
|
|
8
|
+
[](https://github.com/nicklambourne/slackblocks/actions)
|
|
9
|
+
[](https://nicklambourne.github.io/slackblocks)
|
|
10
|
+
|
|
11
|
+
## What is it?
|
|
12
|
+
`slackblocks` is a Python API for building messages in the fancy Slack [Block Kit API](https://api.slack.com/block-kit)
|
|
13
|
+
|
|
14
|
+
## Documentation
|
|
15
|
+
Full documentation is provided [here](https://nicklambourne.github.io/slackblocks/latest/).
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
`slackblocks` requires Python >= 3.8.
|
|
19
|
+
|
|
20
|
+
As of version 0.1.0 it has no dependencies outside the Python standard library.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
```bash
|
|
24
|
+
pip install slackblocks
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Basic Usage
|
|
28
|
+
```python
|
|
29
|
+
from slackblocks import Message, SectionBlock
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
block = SectionBlock("Hello, world!")
|
|
33
|
+
message = Message(channel="#general", blocks=block)
|
|
34
|
+
message.json()
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Will produce the following JSON string:
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"channel": "#general",
|
|
42
|
+
"mrkdwn": true,
|
|
43
|
+
"blocks": [
|
|
44
|
+
{
|
|
45
|
+
"type": "section",
|
|
46
|
+
"block_id": "992ceb6b-9ad4-496b-b8e6-1bd8a632e8b3",
|
|
47
|
+
"text": {
|
|
48
|
+
"type": "mrkdwn",
|
|
49
|
+
"text": "Hello, world!"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
Which can be sent as payload to the Slack message API HTTP endpoints.
|
|
56
|
+
|
|
57
|
+
Of more practical use is the ability to unpack the objects directly into
|
|
58
|
+
the [(Legacy) Python Slack Client](https://pypi.org/project/slackclient/) in order to send messages:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from os import environ
|
|
62
|
+
from slack import WebClient
|
|
63
|
+
from slackblocks import Message, SectionBlock
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
client = WebClient(token=environ["SLACK_API_TOKEN"])
|
|
67
|
+
block = SectionBlock("Hello, world!")
|
|
68
|
+
message = Message(channel="#general", blocks=block)
|
|
69
|
+
|
|
70
|
+
response = client.chat_postMessage(**message)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or the modern Python [Slack SDK](https://pypi.org/project/slack-sdk/):
|
|
74
|
+
```python
|
|
75
|
+
from os import environ
|
|
76
|
+
from slack_sdk import WebClient
|
|
77
|
+
from slackblocks import Message, SectionBlock
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
client = WebClient(token=environ["SLACK_API_TOKEN"])
|
|
81
|
+
block = SectionBlock("Hello, world!")
|
|
82
|
+
message = Message(channel="#general", blocks=block)
|
|
83
|
+
|
|
84
|
+
response = client.chat_postMessage(**message)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Note the `**` operator in front of the `message` object.
|
|
88
|
+
|
|
89
|
+
## Can I use this in my project?
|
|
90
|
+
Yes, please do! The code is all open source and dual BSD-3.0 and MIT licensed
|
|
91
|
+
(use what suits you best).
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "slackblocks"
|
|
3
|
+
version = "1.2.3"
|
|
4
|
+
description = "Python wrapper for the Slack Blocks API"
|
|
5
|
+
authors = [
|
|
6
|
+
"Nicholas Lambourne <dev@ndl.im>",
|
|
7
|
+
]
|
|
8
|
+
maintainers = [
|
|
9
|
+
"Nicholas Lambourne <dev@ndl.im>",
|
|
10
|
+
]
|
|
11
|
+
homepage = "https://github.com/nicklambourne/slackblocks"
|
|
12
|
+
repository = "https://github.com/nicklambourne/slackblocks"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
keywords = [
|
|
16
|
+
"slackblocks",
|
|
17
|
+
"slack",
|
|
18
|
+
"messaging",
|
|
19
|
+
"message generation",
|
|
20
|
+
"slack blocks",
|
|
21
|
+
"blocks",
|
|
22
|
+
]
|
|
23
|
+
classifiers=[
|
|
24
|
+
"Programming Language :: Python :: 3.8",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
|
+
"License :: OSI Approved :: BSD License",
|
|
32
|
+
"License :: OSI Approved :: MIT License",
|
|
33
|
+
"Operating System :: OS Independent",
|
|
34
|
+
"Typing :: Typed",
|
|
35
|
+
"Topic :: Communications :: Chat"
|
|
36
|
+
]
|
|
37
|
+
exclude = ["test/**", "docs/**"]
|
|
38
|
+
|
|
39
|
+
[tool.poetry.dependencies]
|
|
40
|
+
python = ">=3.8.1"
|
|
41
|
+
|
|
42
|
+
[tool.poetry.group.dev.dependencies]
|
|
43
|
+
aiohttp = "^3.10.11"
|
|
44
|
+
black = "^24.8.0"
|
|
45
|
+
flake8 = "^6.1.0"
|
|
46
|
+
flake8-pyproject = "^1.2.3"
|
|
47
|
+
mypy = "^1.14.1"
|
|
48
|
+
pytest = "^8.3.4"
|
|
49
|
+
slack-sdk = "^3.33.4"
|
|
50
|
+
twine = "^6.0.1"
|
|
51
|
+
wheel = "^0.45.1"
|
|
52
|
+
|
|
53
|
+
[tool.poetry.group.docs.dependencies]
|
|
54
|
+
mike = {version = "^2.1.3", python = ">=3.9"}
|
|
55
|
+
mkdocs = {version = "^1.6.1", python = ">=3.9"}
|
|
56
|
+
mkdocs-material = {version = "^9.5.49", python = ">=3.9"}
|
|
57
|
+
mkdocstrings = {extras = ["python"], version = "^0.27.0", python = ">=3.9"}
|
|
58
|
+
mkdocstrings-python = {version = "^1.13.0", python = ">=3.9"}
|
|
59
|
+
|
|
60
|
+
[build-system]
|
|
61
|
+
requires = ["poetry-core"]
|
|
62
|
+
build-backend = "poetry.core.masonry.api"
|
|
63
|
+
|
|
64
|
+
[tool.flake8]
|
|
65
|
+
exclude = [".venv", "./build", "./dist", ".eggs", ".git"]
|
|
66
|
+
max-line-length = 100
|
|
67
|
+
extend-ignore = """
|
|
68
|
+
BLK100
|
|
69
|
+
"""
|
|
70
|
+
per-file-ignores = [
|
|
71
|
+
"slackblocks/__init__.py:F401",
|
|
72
|
+
"slackblocks/rich_text/__init__.py:F401",
|
|
73
|
+
"slackblocks/rich_text/objects.py:W605",
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
[tool.pytest.ini_options]
|
|
77
|
+
filterwarnings = [
|
|
78
|
+
#transform warnings into errors so they are not possible to ignore
|
|
79
|
+
"error",
|
|
80
|
+
#except when defined explicitly as per example below. See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#controlling-warnings
|
|
81
|
+
#"ignore::UserWarning",
|
|
82
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['slackblocks', 'slackblocks.rich_text']
|
|
6
|
+
|
|
7
|
+
package_data = \
|
|
8
|
+
{'': ['*']}
|
|
9
|
+
|
|
10
|
+
setup_kwargs = {
|
|
11
|
+
'name': 'slackblocks',
|
|
12
|
+
'version': '1.2.3',
|
|
13
|
+
'description': 'Python wrapper for the Slack Blocks API',
|
|
14
|
+
'long_description': '# slackblocks <img src="https://github.com/nicklambourne/slackblocks/raw/master/docs_src/img/sb.png" align="right" width="250px"/>\n\n\n\n\n[](https://pypi.org/project/slackblocks/#history)\n[](https://pepy.tech/project/slackblocks)\n[](https://github.com/nicklambourne/slackblocks/actions)\n[](https://nicklambourne.github.io/slackblocks)\n\n## What is it?\n`slackblocks` is a Python API for building messages in the fancy Slack [Block Kit API](https://api.slack.com/block-kit)\n\n## Documentation\nFull documentation is provided [here](https://nicklambourne.github.io/slackblocks/latest/).\n\n## Requirements\n`slackblocks` requires Python >= 3.8.\n\nAs of version 0.1.0 it has no dependencies outside the Python standard library.\n\n## Installation\n```bash\npip install slackblocks\n```\n\n## Basic Usage\n```python\nfrom slackblocks import Message, SectionBlock\n\n\nblock = SectionBlock("Hello, world!")\nmessage = Message(channel="#general", blocks=block)\nmessage.json()\n\n```\n\nWill produce the following JSON string:\n```json\n{\n "channel": "#general",\n "mrkdwn": true,\n "blocks": [\n {\n "type": "section",\n "block_id": "992ceb6b-9ad4-496b-b8e6-1bd8a632e8b3",\n "text": {\n "type": "mrkdwn",\n "text": "Hello, world!"\n }\n }\n ]\n}\n```\nWhich can be sent as payload to the Slack message API HTTP endpoints.\n\nOf more practical use is the ability to unpack the objects directly into \nthe [(Legacy) Python Slack Client](https://pypi.org/project/slackclient/) in order to send messages:\n\n```python\nfrom os import environ\nfrom slack import WebClient\nfrom slackblocks import Message, SectionBlock\n\n\nclient = WebClient(token=environ["SLACK_API_TOKEN"])\nblock = SectionBlock("Hello, world!")\nmessage = Message(channel="#general", blocks=block)\n\nresponse = client.chat_postMessage(**message)\n```\n\nOr the modern Python [Slack SDK](https://pypi.org/project/slack-sdk/):\n```python\nfrom os import environ\nfrom slack_sdk import WebClient\nfrom slackblocks import Message, SectionBlock\n\n\nclient = WebClient(token=environ["SLACK_API_TOKEN"])\nblock = SectionBlock("Hello, world!")\nmessage = Message(channel="#general", blocks=block)\n\nresponse = client.chat_postMessage(**message)\n```\n\nNote the `**` operator in front of the `message` object.\n\n## Can I use this in my project?\nYes, please do! The code is all open source and dual BSD-3.0 and MIT licensed\n (use what suits you best).\n',
|
|
15
|
+
'author': 'Nicholas Lambourne',
|
|
16
|
+
'author_email': 'dev@ndl.im',
|
|
17
|
+
'maintainer': 'Nicholas Lambourne',
|
|
18
|
+
'maintainer_email': 'dev@ndl.im',
|
|
19
|
+
'url': 'https://github.com/nicklambourne/slackblocks',
|
|
20
|
+
'packages': packages,
|
|
21
|
+
'package_data': package_data,
|
|
22
|
+
'python_requires': '>=3.8.1',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
setup(**setup_kwargs)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from .attachments import Attachment, Color, Field
|
|
2
|
+
from .blocks import (
|
|
3
|
+
ActionsBlock,
|
|
4
|
+
ContextBlock,
|
|
5
|
+
DividerBlock,
|
|
6
|
+
FileBlock,
|
|
7
|
+
HeaderBlock,
|
|
8
|
+
ImageBlock,
|
|
9
|
+
InputBlock,
|
|
10
|
+
RichTextBlock,
|
|
11
|
+
SectionBlock,
|
|
12
|
+
TableBlock,
|
|
13
|
+
)
|
|
14
|
+
from .elements import (
|
|
15
|
+
Button,
|
|
16
|
+
ChannelMultiSelectMenu,
|
|
17
|
+
ChannelSelectMenu,
|
|
18
|
+
CheckboxGroup,
|
|
19
|
+
ConversationMultiSelectMenu,
|
|
20
|
+
ConversationSelectMenu,
|
|
21
|
+
DatePicker,
|
|
22
|
+
DateTimePicker,
|
|
23
|
+
Element,
|
|
24
|
+
EmailInput,
|
|
25
|
+
ExternalMultiSelectMenu,
|
|
26
|
+
ExternalSelectMenu,
|
|
27
|
+
Image,
|
|
28
|
+
NumberInput,
|
|
29
|
+
OverflowMenu,
|
|
30
|
+
PlainTextInput,
|
|
31
|
+
RadioButtonGroup,
|
|
32
|
+
RichTextInput,
|
|
33
|
+
StaticMultiSelectMenu,
|
|
34
|
+
StaticSelectMenu,
|
|
35
|
+
TimePicker,
|
|
36
|
+
URLInput,
|
|
37
|
+
UserMultiSelectMenu,
|
|
38
|
+
UserSelectMenu,
|
|
39
|
+
WorkflowButton,
|
|
40
|
+
)
|
|
41
|
+
from .errors import InvalidUsageError
|
|
42
|
+
from .messages import Message, MessageResponse, ResponseType, WebhookMessage
|
|
43
|
+
from .modals import Modal
|
|
44
|
+
from .objects import (
|
|
45
|
+
ColumnSettings,
|
|
46
|
+
Confirm,
|
|
47
|
+
ConfirmationDialogue,
|
|
48
|
+
ConversationFilter,
|
|
49
|
+
DispatchActionConfiguration,
|
|
50
|
+
InputParameter,
|
|
51
|
+
Option,
|
|
52
|
+
OptionGroup,
|
|
53
|
+
RawText,
|
|
54
|
+
Text,
|
|
55
|
+
TextType,
|
|
56
|
+
Trigger,
|
|
57
|
+
Workflow,
|
|
58
|
+
)
|
|
59
|
+
from .rich_text.elements import (
|
|
60
|
+
RichText,
|
|
61
|
+
RichTextChannel,
|
|
62
|
+
RichTextElement,
|
|
63
|
+
RichTextEmoji,
|
|
64
|
+
RichTextLink,
|
|
65
|
+
RichTextUser,
|
|
66
|
+
RichTextUserGroup,
|
|
67
|
+
)
|
|
68
|
+
from .rich_text.objects import (
|
|
69
|
+
RichTextCodeBlock,
|
|
70
|
+
RichTextList,
|
|
71
|
+
RichTextObject,
|
|
72
|
+
RichTextQuote,
|
|
73
|
+
RichTextSection,
|
|
74
|
+
)
|
|
75
|
+
from .views import HomeTabView, ModalView, View
|
|
76
|
+
|
|
77
|
+
name = "slackblocks"
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Secondary (less important) content can be attached using the deprecated
|
|
3
|
+
attachments API.
|
|
4
|
+
|
|
5
|
+
See: <https://api.slack.com/slackblocks/latest/reference/messaging/attachments>.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from enum import Enum
|
|
9
|
+
from json import dumps
|
|
10
|
+
from typing import Any, Dict, List, Optional, Union
|
|
11
|
+
|
|
12
|
+
from slackblocks.blocks import Block
|
|
13
|
+
from slackblocks.errors import InvalidUsageError
|
|
14
|
+
from slackblocks.utils import coerce_to_list, is_hex
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Color(Enum):
|
|
18
|
+
"""
|
|
19
|
+
Color is a utility class for use with the Slack secondary attachments API.
|
|
20
|
+
|
|
21
|
+
Pass these to the `color` argument of
|
|
22
|
+
[`Attachment`](/slackblocks/latest/reference/attachments/#attachments.Attachment).
|
|
23
|
+
|
|
24
|
+
<table style="width:50%">
|
|
25
|
+
<tr>
|
|
26
|
+
<td><code>Color.GOOD</code></td>
|
|
27
|
+
<td>
|
|
28
|
+
<img valign='middle' alt='good' src='https://readme-swatches.vercel.app/4CAF50?style=round'/>
|
|
29
|
+
</td>
|
|
30
|
+
</tr>
|
|
31
|
+
<tr>
|
|
32
|
+
<td><code>Color.WARNING</code></td>
|
|
33
|
+
<td>
|
|
34
|
+
<img valign='middle' alt='warning' src='https://readme-swatches.vercel.app/FFEB3B?style=round'/>
|
|
35
|
+
</td>
|
|
36
|
+
</tr>
|
|
37
|
+
<tr>
|
|
38
|
+
<td><code>Color.DANGER</code></td>
|
|
39
|
+
<td>
|
|
40
|
+
<img valign='middle' alt='danger' src='https://readme-swatches.vercel.app/F44336?style=round'/>
|
|
41
|
+
</td>
|
|
42
|
+
</tr>
|
|
43
|
+
<tr>
|
|
44
|
+
<td><code>Color.RED</code></td>
|
|
45
|
+
<td>
|
|
46
|
+
<img valign='middle' alt='red' src='https://readme-swatches.vercel.app/ff0000?style=round'/>
|
|
47
|
+
</td>
|
|
48
|
+
</tr>
|
|
49
|
+
<tr>
|
|
50
|
+
<td><code>Color.BLUE</code></td>
|
|
51
|
+
<td>
|
|
52
|
+
<img valign='middle' alt='blue' src='https://readme-swatches.vercel.app/0000ff?style=round'/>
|
|
53
|
+
</td>
|
|
54
|
+
</tr>
|
|
55
|
+
<tr>
|
|
56
|
+
<td><code>Color.YELLOW</code></td>
|
|
57
|
+
<td>
|
|
58
|
+
<img valign='middle' alt='yellow' src='https://readme-swatches.vercel.app/ffff00?style=round'/>
|
|
59
|
+
</td>
|
|
60
|
+
</tr>
|
|
61
|
+
<tr>
|
|
62
|
+
<td><code>Color.GREEN</code></td>
|
|
63
|
+
<td>
|
|
64
|
+
<img valign='middle' alt='green' src='https://readme-swatches.vercel.app/00ff00?style=round'/>
|
|
65
|
+
</td>
|
|
66
|
+
</tr>
|
|
67
|
+
<tr>
|
|
68
|
+
<td><code>Color.ORANGE</code></td>
|
|
69
|
+
<td>
|
|
70
|
+
<img valign='middle' alt='orange' src='https://readme-swatches.vercel.app/ff8800?style=round'/>
|
|
71
|
+
</td>
|
|
72
|
+
</tr>
|
|
73
|
+
<tr>
|
|
74
|
+
<td><code>Color.PURPLE</code></td>
|
|
75
|
+
<td>
|
|
76
|
+
<img valign='middle' alt='purple' src='https://readme-swatches.vercel.app/8800ff?style=round'/>
|
|
77
|
+
</td>
|
|
78
|
+
</tr>
|
|
79
|
+
<tr>
|
|
80
|
+
<td><code>Color.BLACK</code></td>
|
|
81
|
+
<td>
|
|
82
|
+
<img valign='middle' alt='black' src='https://readme-swatches.vercel.app/000000?style=round'/>
|
|
83
|
+
</td>
|
|
84
|
+
</tr>
|
|
85
|
+
</table>
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
GOOD = "good"
|
|
89
|
+
WARNING = "warning"
|
|
90
|
+
DANGER = "danger"
|
|
91
|
+
RED = "#ff0000"
|
|
92
|
+
BLUE = "#0000ff"
|
|
93
|
+
YELLOW = "#ffff00"
|
|
94
|
+
GREEN = "#00ff00"
|
|
95
|
+
ORANGE = "#ff8800"
|
|
96
|
+
PURPLE = "#8800ff"
|
|
97
|
+
BLACK = "#000000"
|
|
98
|
+
|
|
99
|
+
def __repr__(self) -> str:
|
|
100
|
+
return f"<slackblocks Color {self.name}: {self.value}>"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class Field:
|
|
104
|
+
"""
|
|
105
|
+
Field text objects for use with Slack's secondary attachment API.
|
|
106
|
+
|
|
107
|
+
See <https://api.slack.com/reference/messaging/attachments#fields>.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
title: text shown as a bold heading on the field.
|
|
111
|
+
value: text (`mrkdwn` or `plaintext`) representing the value of the field.
|
|
112
|
+
short: whether the contents of the field is short enough to be presented in
|
|
113
|
+
multipe columns.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def __init__(
|
|
117
|
+
self,
|
|
118
|
+
title: Optional[str] = None,
|
|
119
|
+
value: Optional[str] = None,
|
|
120
|
+
short: Optional[bool] = False,
|
|
121
|
+
):
|
|
122
|
+
self.title = title
|
|
123
|
+
self.value = value
|
|
124
|
+
self.short = short
|
|
125
|
+
|
|
126
|
+
def _resolve(self):
|
|
127
|
+
field = dict()
|
|
128
|
+
field["short"] = self.short
|
|
129
|
+
if self.title:
|
|
130
|
+
field["title"] = self.title
|
|
131
|
+
if self.value:
|
|
132
|
+
field["value"] = self.value
|
|
133
|
+
return dumps(field)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class Attachment:
|
|
137
|
+
"""
|
|
138
|
+
Lower priority content can be attached to messages using Attachments.
|
|
139
|
+
This is content that doesn't necessarily need to be seen to appreciate
|
|
140
|
+
the intent of the message, but perhaps adds further context or additional information.
|
|
141
|
+
|
|
142
|
+
See <https://api.slack.com/reference/messaging/attachments>.
|
|
143
|
+
|
|
144
|
+
N.B: `fields` is a deprecated field, included only for legacy purposes. Other legacy
|
|
145
|
+
fields, e.g. `author_name` are deliberately omitted as they were never implemented in
|
|
146
|
+
`slackblocks`.
|
|
147
|
+
|
|
148
|
+
Args:
|
|
149
|
+
blocks: an array of Blocks that define the content of the attachment.
|
|
150
|
+
color: the color (in hex format, e.g. #ffffff) of the vertical bar to the left of the
|
|
151
|
+
attachment content. Consider using the `Color` enum from this module.
|
|
152
|
+
fields: a list of `Field` objects to be included in what's rendered in the attachment.
|
|
153
|
+
fallback: A plain text summary of the attachment used in clients that don't show
|
|
154
|
+
formatted text (eg. IRC, mobile notifications).
|
|
155
|
+
|
|
156
|
+
Throws:
|
|
157
|
+
InvalidUsageError: if the `color` code provided is invalid.
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
def __init__(
|
|
161
|
+
self,
|
|
162
|
+
blocks: Optional[Union[Block, List[Block]]] = None,
|
|
163
|
+
color: Optional[Union[str, Color]] = None,
|
|
164
|
+
fields: Optional[Union[Field, List[Field]]] = None,
|
|
165
|
+
fallback: Optional[str] = None,
|
|
166
|
+
):
|
|
167
|
+
self.blocks = coerce_to_list(blocks, Block, allow_none=True)
|
|
168
|
+
self.fields = coerce_to_list(fields, Field, allow_none=True)
|
|
169
|
+
self.fallback = fallback
|
|
170
|
+
self.color: Optional[str]
|
|
171
|
+
if type(color) is Color:
|
|
172
|
+
self.color = color.value
|
|
173
|
+
elif type(color) is str:
|
|
174
|
+
if len(color) == 7 and color.startswith("#") and is_hex(color[1:]):
|
|
175
|
+
self.color = color
|
|
176
|
+
elif len(color) == 6 and is_hex(color):
|
|
177
|
+
self.color = f"#{color}"
|
|
178
|
+
else:
|
|
179
|
+
raise InvalidUsageError(
|
|
180
|
+
"Color must be a valid hex code (e.g. `#ffffff`)"
|
|
181
|
+
)
|
|
182
|
+
else:
|
|
183
|
+
self.color = None
|
|
184
|
+
|
|
185
|
+
def _resolve(self) -> Dict[str, Any]:
|
|
186
|
+
attachment: Dict[str, Any] = {}
|
|
187
|
+
if self.blocks:
|
|
188
|
+
attachment["blocks"] = [block._resolve() for block in self.blocks]
|
|
189
|
+
if self.color:
|
|
190
|
+
attachment["color"] = self.color
|
|
191
|
+
if self.fallback:
|
|
192
|
+
attachment["fallback"] = self.fallback
|
|
193
|
+
return attachment
|
|
194
|
+
|
|
195
|
+
def __repr__(self) -> str:
|
|
196
|
+
return dumps(self._resolve(), indent=4)
|