Skip to content

Commit

Permalink
Merge pull request #794 from Jmainguy/bot_profile
Browse files Browse the repository at this point in the history
Add bot_profile to messages
  • Loading branch information
kanata2 authored Sep 9, 2020
2 parents 7a67a6a + b464c32 commit cc94355
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
18 changes: 15 additions & 3 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
33 changes: 31 additions & 2 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = `{
Expand Down

0 comments on commit cc94355

Please sign in to comment.