imryche / blockkit Goto Github PK
View Code? Open in Web Editor NEWA fast way to build Block Kit interfaces in Python
Home Page: https://blockkit.botsignals.co
License: MIT License
A fast way to build Block Kit interfaces in Python
Home Page: https://blockkit.botsignals.co
License: MIT License
I just found your library and it looks like it could be very useful. Is it possible to (re)add the text attribute to the Message surface?
In my case, I'm looking to use this with slack_bolt using the following endpoint:
@app.message("hello")
def message_hello(message, say):
# say() sends a message to the channel where the event was triggered
message = Message(
blocks=[
Section(text="Hey there")
],
).build()
say(message)
When I use this, I get a slack_bolt warning in my logs saying:
/Users/me/Library/Caches/pypoetry/virtualenvs/mack-0TpdqiFV-py3.9/lib/python3.9/site-packages/slack_sdk/web/
internal_utils.py:271: UserWarning: The `text` argument is missing in the request payload for a chat.postMessage
call - It's a best practice to always provide a `text` argument when posting a message. The `text` argument is
used in places where content cannot be rendered such as: system push notifications, assistive technology such as
screen readers, etc.
warnings.warn(message, UserWarning)
What I would like to be able to do is the following:
message = Message(
blocks=[
Section(text="Hey there")
],
text="Hey there"
).build()
I know that I can work around it by manually adding text
after creating the message, but I'd prefer to do it all in one operation.
I see that text
was previously available ~2 years ago. Was there a reason that it was removed?
Nit-picking:
Class blockkit.elements.Timepicker
, constructor of "Time Picker" element in Slack block kit, should be renamed to TimePicker
. (e.g. DatePicker
follows the convention as the constructor of "Date Picker" element.)
blockkit-generator.com is now a domain landing page
Getting a type error when trying to add RichText
block to Message
.
Argument of type "list[Section | RichText]" cannot be assigned to parameter "blocks" of type "List[Block] | None" in function "__init__"
Type "RichText" cannot be assigned to type "Block"
"RichText" is incompatible with "Actions"
"RichText" is incompatible with "Context"
"RichText" is incompatible with "Divider"
"RichText" is incompatible with "Header"
"RichText" is incompatible with "ImageBlock"
"RichText" is incompatible with "Input"
"RichText" is incompatible with "Section"Pylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues)
still the fields are not working error is : The server responded with: {'ok': False, 'error': 'invalid_arguments', 'response_metadata': {'messages': ['[ERROR] failed to match all allowed schemas [json-pointer:/view]', '[ERROR] failed to match all allowed schemas [json-pointer:/view/blocks/4/fields/0]', '[ERROR] must provide an object [json-pointer:/view/blocks/4/fields/0]', '[ERROR] must provide an object [json-pointer:/view/blocks/4/fields/0]', '[ERROR] failed to match all allowed schemas [json-pointer:/view/blocks/4/fields/1]', '[ERROR] must provide an object [json-pointer:/view/blocks/4/fields/1]', '[ERROR] must provide an object [json-pointer:/view/blocks/4/fields/1]', '[ERROR] failed to match all allowed schemas [json-pointer:/view/blocks/5/fields/0]', '[ERROR] must provide an object [json-pointer:/view/blocks/5/fields/0]', '[ERROR] must provide an object [json-pointer:/view/blocks/5/fields/0]', '[ERROR] failed to match all allowed schemas [json-pointer:/view/blocks/5/fields/1]', '[ERROR] must provide an object [json-pointer:/view/blocks/5/fields/1]', '[ERROR] must provide an object [json-pointer:/view/blocks/5/fields/1]']}}
json example
"attachments": [
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Alternative hotel options"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://example.com|Bates Motel> ⭐⭐"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View",
"emoji": true
},
"value": "view_alternate_1"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<https://example.com|The Great Northern Hotel> ⭐⭐⭐⭐"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "View",
"emoji": true
},
"value": "view_alternate_2"
}
}
]
}
]
}
Hi, black
is listed in the required packages:
https://github.com/imryche/blockkit/blob/master/setup.py#L20
It is being used only in generators.py
:
https://github.com/imryche/blockkit/blob/master/blockkit/generators.py#L3
I think this is only being used for https://blockkit-generator.com/, right? Therefore I propose to make black an optional dependency.
For me context and field is not working using blockkit in the version update to latest
Recently I'm looking up Mattermost's documentation and feels like it would be useful to add component building support in Mattermost. Given that they offers example for writing apps in Python, plus they're following a lot of Slack's (previous) design/practice, offering extra support for Mattermost message building may be doable and useful.
Mattermost mostly follows legacy practice of Slack:
By doing so, we can also consider reviving #43 to allow building attachments in Slack messages until Slack fully deprecates support.
Is there interest for adding support for https://api.slack.com/reference/block-kit/blocks#rich_text to the blockkit library?
I might be able to send a PR for it. Since it's a sizable addition, I wanted to check in first and see if there's support or if someone else is already working on it.
Can you add rich text input into Input block type?
Rich Text Input
Blockkit builder supports putting MarkdownText
in a checkbox's option description but the module doesn't accept a MarkdownText class/type for the Option description
field.
Any plan to update this/workaround?
When blockkit
is used with the latest version of pydantic, I get errors like
AttributeError: 'StaticSelect' object has no attribute 'get'
This is caused by model validators not checking if passed argument is actually a dictionary
@model_validator(mode="before")
def _validate_values(cls, values: Dict) -> Dict:
# I added these 2 lines to fix the issue, but I'm not sure if I'm breaking the validation process here
if not isinstance(values, dict):
return values
initial_options = values.get("initial_options")
https://github.com/oneor0/blockkit-slack/blob/master/blockkit/objects.py#L55-L61
blockkit.objects.Option
does not support description
field as per Slack Block Kit documentation.
I'll try to create a PR shortly, a fix should not be too complicated (like 2 changed lines + tests iirc) unless @OneOr0 has any objections :)
I got the idea from here:
https://github.com/ASU-CodeDevils/slack-blockkit#online-message-blocks
I already wrote the code with tests and documentation, the function is essentially
def create_block_kit_builder_url(block_kit_like_object):
"""
Takes block_kit_like_object like element, component, surfaces, and objects
block_kit_like_object can be built (build()) or unbuilt, see example
"""
block_kit_builder_url = "https://app.slack.com/block-kit-builder/#"
try:
block_dump = dumps(block_kit_like_object.build())
except AttributeError as attribute_error:
if str(attribute_error) == "'dict' object has no attribute 'build'":
block_dump = dumps(block_kit_like_object)
else:
raise AttributeError
except Exception as e:
raise e from None
final_url = block_kit_builder_url + block_dump
final_url_safe = quote(final_url, safe='/:?=&#')
msg = "Block kit builder example/validation: \n\t" + final_url_safe
print(msg)
Slack provides datetime picker (datetimepicker
) as interactive component, which allows user to enter both date and time in one input field. And currently blockkit
lacks support on this component in elements
module.
Dependabot couldn't authenticate with https://pypi.python.org/simple/.
You can provide authentication details in your Dependabot dashboard by clicking into the account menu (in the top right) and selecting 'Config variables'.
Hey there,
I wanted to give you a heads up about an issue I've come across with the recent release of Blockkit 1.6.0.
It seems like Blockkit 1.6.0 doesn't have a version constraint for its dependency on pydantic. Even though it seems to need pydantic 2, the version on PyPI doesn't specify this requirement. So, when I tried to use Blockkit 1.6.0 along with pydantic 1 in my project, pip upgraded to 1.6.0 but kept pydantic 1. Unfortunately, Blockkit 1.6.0 doesn't work properly with pydantic 1.
I noticed that the setup.py file doesn't mention any requirement for pydantic 2. As a result, package managers think it's okay to install Blockkit 1.6.0 alongside pydantic 1, which leads to the compatibility problem I ran into.
Could you consider adding a constraint to the package that requires pydantic 2?
Thanks so much for looking into this.
Cheers,
Related to #99, when running pip install blockkit
, pip sees the dependency as pydantic>=2
rather than the pinned version of 2.3.0
Hi,
This tool is really good and the site itself sometimes gets cert issues or domain issue, If a Docker image is availble we can host it locally, Please consider that request so we can lauch the tool from a local instance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.