Repository: slack-go/slack
Pull request #986 (2021-10-08 17:51:45)

add message subType constants from https://api.slack.com/events/message
Add Message SubTypes from https://api.slack.com/events/message as constants


Patch:
diff --git a/messages.go b/messages.go
index 999df5d..2f05f6d 100644
--- a/messages.go
+++ b/messages.go
@@ -19,6 +19,38 @@ type Message struct {
 	PreviousMessage *Msg `json:"previous_message,omitempty"`
 }
 
+// Msg SubTypes (https://api.slack.com/events/message)
+const (
+	MsgSubTypeBotMessage                = "bot_message"                 // [Events API, RTM] A message was posted by an integration
+	MsgSubTypeMeMessage                 = "me_message"                  // [Events API, RTM] A /me message was sent
+	MsgSubTypeMessageChanged            = "message_changed"             // [Events API, RTM] A message was changed
+	MsgSubTypeMessageDeleted            = "message_deleted"             // [Events API, RTM] A message was deleted
+	MsgSubTypeMessageReplied            = "message_replied"             // [Events API, RTM] A message thread received a reply
+	MsgSubTypeReplyBroadcast            = "reply_broadcast"             // @Deprecated (No longer served) A message thread's reply was broadcast to a channel
+	MsgSubTypeThreadBroadcast           = "thread_broadcast"            // [Events API, RTM] A message thread's reply was broadcast to a channel
+	MsgSubTypeChannelJoin               = "channel_join"                // [Events API, RTM] A member joined a channel
+	MsgSubTypeChannelLeave              = "channel_leave"               // [Events API, RTM] A member left a channel
+	MsgSubTypeChannelTopic              = "channel_topic"               // [Events API, RTM] A channel topic was updated
+	MsgSubTypeChannelPurpose            = "channel_purpose"             // [Events API, RTM] A channel purpose was updated
+	MsgSubTypeChannelName               = "channel_name"                // [Events API, RTM] A channel was renamed
+	MsgSubTypeChannelArchive            = "channel_archive"             // [Events API, RTM] A channel was archived
+	MsgSubTypeChannelUnarchive          = "channel_unarchive"           // [Events API, RTM] A channel was unarchived
+	MsgSubTypeGroupJoin                 = "group_join"                  // [RTM] A member joined a group
+	MsgSubTypeGroupLeave                = "group_leave"                 // [RTM] A member left a group
+	MsgSubTypeGroupTopic                = "group_topic"                 // [RTM] A group topic was updated
+	MsgSubTypeGroupPurpose              = "group_purpose"               // [RTM] A group purpose was updated
+	MsgSubTypeGroupName                 = "group_name"                  // [RTM] A group was renamed
+	MsgSubTypeGroupArchive              = "group_archive"               // [RTM] A group was archived
+	MsgSubTypeGroupUnarchive            = "group_unarchive"             // [RTM] A group was unarchived
+	MsgSubTypeFileShare                 = "file_share"                  // [Events API, RTM] A file was shared into a channel
+	MsgSubTypeFileComment               = "file_comment"                // [RTM] A comment was added to a file
+	MsgSubTypeGileMention               = "file_mention"                // [RTM] A file was mentioned in a channel
+	MsgSubTypePinnedItem                = "pinned_item"                 // [RTM] An item was pinned in a channel
+	MsgSubTypeUnpinnedItem              = "unpinned_item"               // [RTM] An item was unpinned from a channel
+	MsgSubTypeEkmAccessDenied           = "ekm_access_denied"           // [Events API, RTM] Message content redacted due to Enterprise Key Management (EKM)
+	MsgSubTypeChannelPostingPermissions = "channel_posting_permissions" // [Events API, RTM] The posting permissions for a channel changed
+)
+
 // Msg contains information about a slack message
 type Msg struct {
 	// Basic Message


Test patch:
diff --git a/messages_test.go b/messages_test.go
index d47800e..62fd759 100644
--- a/messages_test.go
+++ b/messages_test.go
@@ -50,7 +50,7 @@ func TestStarredMessage(t *testing.T) {
 	assert.NotNil(t, message)
 	assert.Equal(t, "is testing", message.Text)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "me_message", message.SubType)
+	assert.Equal(t, MsgSubTypeMeMessage, message.SubType)
 	assert.Equal(t, "U2147483697", message.User)
 	assert.Equal(t, "1433314126.000003", message.Timestamp)
 	assert.Equal(t, true, message.IsStarred)
@@ -136,7 +136,7 @@ func TestUploadedFile(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "file_share", message.SubType)
+	assert.Equal(t, MsgSubTypeFileShare, message.SubType)
 	assert.Equal(t, "<@U2147483697|tester> uploaded a file: <https://test.slack.com/files/tester/abc/test.txt|test.txt> and commented: test comment here", message.Text)
 	// TODO: Assert File
 	assert.Equal(t, "U2147483697", message.User)
@@ -190,7 +190,7 @@ func TestPost(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "file_share", message.SubType)
+	assert.Equal(t, MsgSubTypeFileShare, message.SubType)
 	assert.Equal(t, "<@U2147483697|tester> shared a file: <https://test.slack.com/files/tester/abc/test_post|test post>", message.Text)
 	// TODO: Assert File
 	assert.Equal(t, "U2147483697", message.User)
@@ -250,7 +250,7 @@ func TestComment(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "file_comment", message.SubType)
+	assert.Equal(t, MsgSubTypeFileComment, message.SubType)
 	assert.Equal(t, "<@U2147483697|tester> commented on <@U2147483697|tester>'s file <https://test.slack.com/files/tester/abc/test_post|test post>: another comment", message.Text)
 	// TODO: Assert File
 	// TODO: Assert Comment
@@ -290,7 +290,7 @@ func TestBotMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "bot_message", message.SubType)
+	assert.Equal(t, MsgSubTypeBotMessage, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "Pushing is the answer", message.Text)
 	assert.Equal(t, "BB12033", message.BotID)
@@ -325,7 +325,7 @@ func TestMeMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "me_message", message.SubType)
+	assert.Equal(t, MsgSubTypeMeMessage, message.SubType)
 	assert.Equal(t, "C2147483705", message.Channel)
 	assert.Equal(t, "U2147483697", message.User)
 	assert.Equal(t, "is doing that thing", message.Text)
@@ -355,7 +355,7 @@ func TestMessageChangedMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "message_changed", message.SubType)
+	assert.Equal(t, MsgSubTypeMessageChanged, message.SubType)
 	assert.True(t, message.Hidden)
 	assert.Equal(t, "C2147483705", message.Channel)
 	assert.NotNil(t, message.SubMessage)
@@ -383,7 +383,7 @@ func TestMessageDeletedMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "message_deleted", message.SubType)
+	assert.Equal(t, MsgSubTypeMessageDeleted, message.SubType)
 	assert.True(t, message.Hidden)
 	assert.Equal(t, "C2147483705", message.Channel)
 	assert.Equal(t, "1358878755.000001", message.Timestamp)
@@ -403,7 +403,7 @@ func TestChannelJoinMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_join", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelJoin, message.SubType)
 	assert.Equal(t, "1358877458.000011", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "<@U2147483828|cal> has joined the channel", message.Text)
@@ -423,7 +423,7 @@ func TestChannelJoinInvitedMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_join", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelJoin, message.SubType)
 	assert.Equal(t, "1358877458.000011", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "<@U2147483828|cal> has joined the channel", message.Text)
@@ -443,7 +443,7 @@ func TestChannelLeaveMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_leave", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelLeave, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "<@U2147483828|cal> has left the channel", message.Text)
@@ -463,7 +463,7 @@ func TestChannelTopicMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_topic", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelTopic, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "hello world", message.Topic)
@@ -484,7 +484,7 @@ func TestChannelPurposeMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_purpose", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelPurpose, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "whatever", message.Purpose)
@@ -506,7 +506,7 @@ func TestChannelNameMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_name", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelName, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "random", message.OldName)
@@ -528,7 +528,7 @@ func TestChannelArchiveMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_archive", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelArchive, message.SubType)
 	assert.Equal(t, "1361482916.000003", message.Timestamp)
 	assert.Equal(t, "<U1234|@cal> archived the channel", message.Text)
 	assert.Equal(t, "U1234", message.User)
@@ -549,7 +549,7 @@ func TestChannelUnarchiveMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "channel_unarchive", message.SubType)
+	assert.Equal(t, MsgSubTypeChannelUnarchive, message.SubType)
 	assert.Equal(t, "1361482916.000003", message.Timestamp)
 	assert.Equal(t, "<U1234|@cal> un-archived the channel", message.Text)
 	assert.Equal(t, "U1234", message.User)
@@ -627,7 +627,7 @@ func TestGroupJoinMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_join", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupJoin, message.SubType)
 	assert.Equal(t, "1358877458.000011", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "<@U2147483828|cal> has joined the group", message.Text)
@@ -647,7 +647,7 @@ func TestGroupJoinInvitedMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_join", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupJoin, message.SubType)
 	assert.Equal(t, "1358877458.000011", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "<@U2147483828|cal> has joined the group", message.Text)
@@ -667,7 +667,7 @@ func TestGroupLeaveMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_leave", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupLeave, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "<@U2147483828|cal> has left the group", message.Text)
@@ -687,7 +687,7 @@ func TestGroupTopicMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_topic", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupTopic, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "hello world", message.Topic)
@@ -708,7 +708,7 @@ func TestGroupPurposeMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_purpose", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupPurpose, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "whatever", message.Purpose)
@@ -730,7 +730,7 @@ func TestGroupNameMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_name", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupName, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "U2147483828", message.User)
 	assert.Equal(t, "random", message.OldName)
@@ -752,7 +752,7 @@ func TestGroupArchiveMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_archive", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupArchive, message.SubType)
 	assert.Equal(t, "1361482916.000003", message.Timestamp)
 	assert.Equal(t, "<U1234|@cal> archived the group", message.Text)
 	assert.Equal(t, "U1234", message.User)
@@ -773,7 +773,7 @@ func TestGroupUnarchiveMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "group_unarchive", message.SubType)
+	assert.Equal(t, MsgSubTypeGroupUnarchive, message.SubType)
 	assert.Equal(t, "1361482916.000003", message.Timestamp)
 	assert.Equal(t, "<U1234|@cal> un-archived the group", message.Text)
 	assert.Equal(t, "U1234", message.User)
@@ -834,7 +834,7 @@ func TestFileShareMessage(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotNil(t, message)
 	assert.Equal(t, "message", message.Type)
-	assert.Equal(t, "file_share", message.SubType)
+	assert.Equal(t, MsgSubTypeFileShare, message.SubType)
 	assert.Equal(t, "1358877455.000010", message.Timestamp)
 	assert.Equal(t, "<@cal> uploaded a file: <https:...7.png|7.png>", message.Text)
 	assert.Equal(t, "U2147483697", message.User)