Skip to content

Commit f2423d4

Browse files
authored
Merge pull request #549 from n0h0/add-group-id-formatting
Add group ID formatting support for message mentions
2 parents 720b75f + ba282e5 commit f2423d4

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 2.5.3 (Next)
22

3+
* [#549](https://github.com/slack-ruby/slack-ruby-client/pull/549): Add group ID formatting support for message mentions - [@n0h0](https://github.com/n0h0).
34
* Your contribution here.
45

56
### 2.5.2 (2025/02/19)

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messagin
5757
- [Date and Time Formatting](#date-and-time-formatting)
5858
- [Channel ID Formatting](#channel-id-formatting)
5959
- [User ID Formatting](#user-id-formatting)
60+
- [Group ID Formatting](#group-id-formatting)
6061
- [URL Formatting](#url-formatting)
6162
- [Markdown Formatting](#markdown-formatting)
6263
- [Parsing Messages](#parsing-messages)
@@ -665,6 +666,16 @@ Slack::Messages::Formatting.user_link(user_id)
665666
# => "<@U0000000001>"
666667
```
667668

669+
##### Group ID Formatting
670+
671+
If you already know the group name you can just embed it in the message as `@some_group`, but if you only have the ID you can embed it using special syntax which Slack will display as the group name.
672+
673+
```ruby
674+
group_id = 'S0000000001'
675+
Slack::Messages::Formatting.group_link(group_id)
676+
# => "<!subteam^S0000000001>"
677+
```
678+
668679
##### URL Formatting
669680

670681
Slack will automatically parse fully qualified URLs in messages, but you need special formatting to embed a link with different text.

lib/slack/messages/formatting.rb

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ def user_link(user_id)
6161
"<@#{user_id}>"
6262
end
6363

64+
#
65+
# Embed a link to a group in a message by group ID
66+
# @see https://api.slack.com/reference/surfaces/formatting#mentioning-groups
67+
#
68+
def group_link(group_id)
69+
"<!subteam^#{group_id}>"
70+
end
71+
6472
#
6573
# Embed a URL with custom link text in a message
6674
# @see https://api.slack.com/reference/surfaces/formatting#linking-urls

spec/slack/messages/formatting_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@
113113
end
114114
end
115115

116+
context '#group_link' do
117+
let(:group_id) { 'S0000000001' }
118+
119+
it 'links to a group by its ID' do
120+
expect(formatting.group_link(group_id)).to eq "<!subteam^#{group_id}>"
121+
end
122+
end
123+
116124
context '#url_link' do
117125
let(:text) { 'super cool website' }
118126
let(:url) { 'https://theuselessweb.site/' }

0 commit comments

Comments
 (0)