slackapi / bolt-python

A framework to build Slack apps using Python
https://slack.dev/bolt-python/
MIT License
1.03k stars 237 forks source link

How do I use strong message types? #1023

Closed KaloyanP closed 4 months ago

KaloyanP commented 5 months ago

This is more of a query, rather than a bug:

I can't find a type-based way to construct requests I send to Slack or to route messages I receive from Slack.

I want to have stronger typing of messages I receive from and send to Slack so that I can benefit from:

Simplistically, I imagine this would look something like this:

class Section(BaseBlock):
    _type: str = 'section'
    text: TextObject
    accessory: ElementObject
    block_id: str

section1=Section()
section2=Section()

def send_hello(client: WebClient)
    client.chat_PostMessage(
        channel='C123456',
        blocks=[section1, section2]
    )

Is there a package I can use to enforce this typing?

The slack_bolt version

Any

Python runtime version

Any

OS info

Any

Requirements

See preamble

seratch commented 5 months ago

Hi @KaloyanP, thanks for asking this!

bolt-python's underlying slack-sdk package offers class-based Block Kit construction approach like you mentioned. Check the module's api docs and unit tests should be the quickest way to learn how to use it:

I hope this helps.

github-actions[bot] commented 4 months ago

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

github-actions[bot] commented 4 months ago

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.