bolt-python icon indicating copy to clipboard operation
bolt-python copied to clipboard

How do I use strong message types?

Open KaloyanP opened this issue 2 years ago • 1 comments

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:

  • static analysis of my code,
  • prevent silly naming errors
  • test the requests my app would send to Slack in CI
  • write bots faster
  • make Copilot and IntelliSense suggestions smarter
  • tab-autocomplete my way to success (maybe not quite that one)

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

KaloyanP avatar Jan 30 '24 12:01 KaloyanP

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:

  • https://slack.dev/python-slack-sdk/api-docs/slack_sdk/models/blocks/index.html
  • https://github.com/slackapi/python-slack-sdk/tree/main/tests/slack_sdk/models

I hope this helps.

seratch avatar Feb 01 '24 23:02 seratch

👋 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] avatar Mar 04 '24 00:03 github-actions[bot]

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.

github-actions[bot] avatar Mar 18 '24 00:03 github-actions[bot]