Giter Site home page Giter Site logo

imryche / blockkit Goto Github PK

View Code? Open in Web Editor NEW
70.0 2.0 11.0 789 KB

A fast way to build Block Kit interfaces in Python

Home Page: https://blockkit.botsignals.co

License: MIT License

Python 100.00%
python slack slackbot slack-api blockkit bot-framework slackapi slack-bot slack-webhook slack-commands

blockkit's People

Contributors

cleavenworth avatar dependabot-preview[bot] avatar dependabot[bot] avatar imryche avatar jelizaga3-gatech avatar jimmyruann avatar kvalenti avatar liaungyip avatar lookforward-github avatar parente avatar pyhsieh-cyberbiz avatar pykenny avatar raycharius avatar twiedenbein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blockkit's Issues

Message surface text attribute

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?

RichText type error for Message

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)

Fields and context not working for latest release 1.6.2 and even 1.6.1

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]']}}

Add attachments to the blockkit

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"
}
}
]
}
]
}

Mattermost Support

Purpose

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.

Details

Mattermost mostly follows legacy practice of Slack:

  • Message body only allows plain text, written in Markdown similar to Slack's syntax, compares to Block Kit, which allows app/bot developers to stack multiple different sections in main message.
  • For interactive messages, section and interactive components are all placed under attachment part of the message, as Slack's legacy approach did (Interactive Message Documentation)
  • Structure of interactive dialog seems very similar to legacy slack dialog as well. (Form Documentation)
  • Mattermost only implements a subset of form/interactive components compared to Slack. And seems that they're not adding more of them in the short term.

By doing so, we can also consider reviving #43 to allow building attachments in Slack messages until Slack fully deprecates support.

does not work with pydantic 2.5.2

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")

Add method that creates link to Slack Bot Builder

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)

Support Datetime Picker

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.

Missing requirement for pydantic 2 in setup.py

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,

issue with blockkit generator site

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.