Skip to content

Add lightweight module with slack message formatting utility #415

@stthazin

Description

@stthazin

Is your feature request related to a problem? Please describe.

When building Slack messages programmatically, developers need to manually construct Slack's mrkdwn formatting syntax (e.g., *bold*, _italic_, <url|text>). This is tedious and error-prone,
especially for link formatting with the pipe syntax or user/channel mentions. Currently, there's no lightweight utility in the slack-client library to help with common message formatting tasks,
forcing every consumer to either write their own helpers or manually concatenate strings with formatting characters. Example, there are multiple SlackMessageFormatter's in the HubSpot codebase (sourcegraph search). I think we can heavily benefit from having a basic formatting helper.

Describe the solution you'd like

A new lightweight slack-commons module (or something along the lines) containing a SlackMessageFormatter utility class with static helper methods for common Slack message formatting operations:

  • Text formatting: bold(), italic(), strikethrough(), code(), codeBlock()
  • Links: formatLink(url), formatLink(url, text)
  • Mentions: mentionUser(userId), mentionChannel(channelId)
  • Quotes: quote(), blockQuote()

This module should have minimal dependencies so it can be imported without pulling in the full slack-client stack, making it useful for lightweight services that just
need to format messages.

Describe alternatives you've considered

  1. Manual string formatting - Current approach, but error-prone and repetitive
  2. Adding to slack-base - Would work but forces consumers to import heavier dependencies (Jackson, Guava, Immutables) just for simple string formatting
  3. String templates or builders - More complex and less discoverable than simple static methods
  4. Third-party libraries - I have not found an existing library specifically handles Slack's mrkdwn syntax

Additional context

This utility class encapsulates Slack's mrkdwn formatting rules in a discoverable, type-safe way. It's particularly useful for services that construct dynamic Slack messages (alerts, notifications,
reports) where formatting needs to be applied programmatically. The lightweight nature of slack-commons makes it suitable for any project that needs to format Slack messages, regardless of whether
they use the full slack-client library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions