module Slack::BlockKit::Formatting

Formatting contains some utility functions to help formatting text

See: api.slack.com/reference/surfaces/formatting

Constants

DATE_FORMAT_TOKENS

Public Instance Methods

at_channel() click to toggle source

Mention @channel (all users in the current channel)

See: api.slack.com/reference/surfaces/formatting#special-mentions

# File lib/slack/block_kit/formatting.rb, line 91
def at_channel
  '<!channel>'
end
at_everyone() click to toggle source

Mention @everyone (all users in general)

See: api.slack.com/reference/surfaces/formatting#special-mentions

# File lib/slack/block_kit/formatting.rb, line 98
def at_everyone
  '<!everyone>'
end
at_here() click to toggle source

Mention @here (all active users in the current channel)

See: api.slack.com/reference/surfaces/formatting#special-mentions

# File lib/slack/block_kit/formatting.rb, line 83
def at_here
  # additional "|here" is for supporting very old mobile clients apparently!
  '<!here|here>'
end
channel(identifier) click to toggle source

Link a public channel

See: api.slack.com/reference/surfaces/formatting#linking-channels

# File lib/slack/block_kit/formatting.rb, line 62
def channel(identifier)
  "<##{identifier}>"
end
date(timestamp, token_string:, link: nil, fallback_text: nil) click to toggle source

Localise a UNIX timestamp to the user's local timezone

See: api.slack.com/reference/surfaces/formatting#date-formatting

# File lib/slack/block_kit/formatting.rb, line 105
def date(timestamp, token_string:, link: nil, fallback_text: nil)
  datetime_str = [timestamp, token_string, link].compact.join('^')
  str = [datetime_str, fallback_text].compact.join('|')

  "<!date^#{str}>"
end
escape(text) click to toggle source

Escape special characters (<,>,&) with their HTML entity code so Slack's text parsers knows to interpret them as literals.

See: api.slack.com/reference/surfaces/formatting#escaping

# File lib/slack/block_kit/formatting.rb, line 116
def escape(text)
  text
    .gsub('&', '&amp;')
    .gsub('>', '&gt;')
    .gsub('<', '&lt;')
end
group(identifier) click to toggle source

Mention a group

See: api.slack.com/reference/surfaces/formatting#mentioning-groups

# File lib/slack/block_kit/formatting.rb, line 76
def group(identifier)
  "<!subteam^#{identifier}>"
end
mailto(address, link_text: nil) click to toggle source

Format a mailto link

See: api.slack.com/reference/surfaces/formatting#links

# File lib/slack/block_kit/formatting.rb, line 55
def mailto(address, link_text: nil)
  "<mailto:#{[address, link_text].compact.join('|')}>"
end
user(identifier) click to toggle source

Mention a user

See: api.slack.com/reference/surfaces/formatting#mentioning-users

# File lib/slack/block_kit/formatting.rb, line 69
def user(identifier)
  "<@#{identifier}>"
end