module Slack::BlockKit::Formatting
Formatting
contains some utility functions to help formatting text
Constants
- DATE_FORMAT_TOKENS
Public Instance Methods
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
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
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
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
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 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('&', '&') .gsub('>', '>') .gsub('<', '<') end
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
Format a URL
See: api.slack.com/reference/surfaces/formatting#links
# File lib/slack/block_kit/formatting.rb, line 48 def link(url, link_text: nil) "<#{[url, link_text].compact.join('|')}>" end
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
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