Repository: slack-go/slack
Pull request #794 (2020-09-08 20:42:53)

Add bot_profile to messages
Add testing for new fields

Jmainguy: I am not a slack expert, but with slack.OptionDebug(true), I get this output when receiving a message from a bot.

```
{
    "type": "message",
    "subtype": "bot_message",
    "text": "<@U01AN1UT741> has created a new story for estimation.",
    "suppress_notification": false,
    "bot_id": "B01AZA490HE",
    "team": "T01A9CUMPQA",
    "bot_profile": {
        "id": "B01AZA490HE",
        "deleted": false,
        "name": "storypoker",
        "updated": 1599574335,
        "app_id": "A6DB2SWUW",
        "icons": {
            "image_36": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_36.png",
            "image_48": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_48.png",
            "image_72": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_72.png"
        },
        "team_id": "T01A9CUMPQA"
    },
    "blocks": [],
    "channel": "C01AZ844Z32",
    "event_ts": "1599574912.002300",
    "ts": "1599574912.002300"
}
```

As I need to know the bot's name, and Username is not being passed, but rather as of bot_profile.Name, I changed the code above. I do not know what the handler is doing and if I broke something there, please just let me know.

Also, why this output is so different from https://api.slack.com/events/message/bot_message I would be glad to hear, is Slacks API docs just lagging behind?

Patch:
diff --git a/messages.go b/messages.go
index 09db546..051ae67 100644
--- a/messages.go
+++ b/messages.go
@@ -46,9 +46,10 @@ type Msg struct {
 	EventTimestamp   string `json:"event_ts,omitempty"`
 
 	// bot_message (https://api.slack.com/events/message/bot_message)
-	BotID    string `json:"bot_id,omitempty"`
-	Username string `json:"username,omitempty"`
-	Icons    *Icon  `json:"icons,omitempty"`
+	BotID      string      `json:"bot_id,omitempty"`
+	Username   string      `json:"username,omitempty"`
+	Icons      *Icon       `json:"icons,omitempty"`
+	BotProfile *BotProfile `json:"bot_profile,omitempty"`
 
 	// channel_join, group_join
 	Inviter string `json:"inviter,omitempty"`
@@ -112,6 +113,17 @@ type Icon struct {
 	IconEmoji string `json:"icon_emoji,omitempty"`
 }
 
+// BotProfile contains information about a bot
+type BotProfile struct {
+	AppID   string `json:"app_id,omitempty"`
+	Deleted bool   `json:"deleted,omitempty"`
+	Icons   *Icons `json:"icons,omitempty"`
+	ID      string `json:"id,omitempty"`
+	Name    string `json:"name,omitempty"`
+	TeamID  string `json:"team_id,omitempty"`
+	Updated int64  `json:"updated,omitempty"`
+}
+
 // Edited indicates that a message has been edited.
 type Edited struct {
 	User      string `json:"user,omitempty"`


Test patch:
diff --git a/messages_test.go b/messages_test.go
index 3a05dc8..d47800e 100644
--- a/messages_test.go
+++ b/messages_test.go
@@ -260,11 +260,29 @@ func TestComment(t *testing.T) {
 var botMessage = `{
     "type": "message",
     "subtype": "bot_message",
-    "ts": "1358877455.000010",
     "text": "Pushing is the answer",
+    "suppress_notification": false,
     "bot_id": "BB12033",
     "username": "github",
-    "icons": {}
+    "icons": {},
+    "team": "T01A9CUMPQA",
+    "bot_profile": {
+        "id": "BB12033",
+        "deleted": false,
+        "name": "github",
+        "updated": 1599574335,
+        "app_id": "A6DB2SWUW",
+        "icons": {
+            "image_36": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_36.png",
+            "image_48": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_48.png",
+            "image_72": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_72.png"
+        },
+        "team_id": "T01A9CUMPQA"
+    },
+    "blocks": [],
+    "channel": "C01AZ844Z32",
+    "event_ts": "1358877455.000010",
+    "ts": "1358877455.000010"
 }`
 
 func TestBotMessage(t *testing.T) {
@@ -280,6 +298,17 @@ func TestBotMessage(t *testing.T) {
 	assert.NotNil(t, message.Icons)
 	assert.Empty(t, message.Icons.IconURL)
 	assert.Empty(t, message.Icons.IconEmoji)
+	assert.Equal(t, "github", message.BotProfile.Name)
+	assert.Equal(t, "BB12033", message.BotProfile.ID)
+	assert.Equal(t, false, message.BotProfile.Deleted)
+	assert.Equal(t, int64(1599574335), message.BotProfile.Updated)
+	assert.Equal(t, "A6DB2SWUW", message.BotProfile.AppID)
+	assert.Equal(t, "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_36.png", message.BotProfile.Icons.Image36)
+	assert.Equal(t, "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_48.png", message.BotProfile.Icons.Image48)
+	assert.Equal(t, "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/2017-10-24/261138718469_ada58732a18da119678d_72.png", message.BotProfile.Icons.Image72)
+	assert.Equal(t, "T01A9CUMPQA", message.BotProfile.TeamID)
+	assert.Equal(t, "C01AZ844Z32", message.Channel)
+	assert.Equal(t, "1358877455.000010", message.EventTimestamp)
 }
 
 var meMessage = `{