Skip to content

Commit 792f7ed

Browse files
authored
Merge pull request #999 from toshok/message-timestamp-is-string
link_shared `message_ts` field isn't always a number
2 parents 979adb8 + b40bd98 commit 792f7ed

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

slackevents/inner_events.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@ type GridMigrationStartedEvent struct {
161161

162162
// LinkSharedEvent A message was posted containing one or more links relevant to your application
163163
type LinkSharedEvent struct {
164-
Type string `json:"type"`
165-
User string `json:"user"`
166-
TimeStamp string `json:"ts"`
167-
Channel string `json:"channel"`
168-
MessageTimeStamp json.Number `json:"message_ts"`
164+
Type string `json:"type"`
165+
User string `json:"user"`
166+
TimeStamp string `json:"ts"`
167+
Channel string `json:"channel"`
168+
// MessageTimeStamp can be both a numeric timestamp if the LinkSharedEvent corresponds to a sent
169+
// message and (contrary to the field name) a uuid if the LinkSharedEvent is generated in the
170+
// compose text area.
171+
MessageTimeStamp string `json:"message_ts"`
169172
ThreadTimeStamp string `json:"thread_ts"`
170173
Links []sharedLinks `json:"links"`
171174
}

slackevents/inner_events_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,38 @@ func TestLinkSharedEvent(t *testing.T) {
103103
}
104104
}
105105

106+
func TestLinkSharedComposerEvent(t *testing.T) {
107+
rawE := []byte(`
108+
{
109+
"type": "link_shared",
110+
"channel": "COMPOSER",
111+
"is_bot_user_member": true,
112+
"user": "Uxxxxxxx",
113+
"message_ts": "Uxxxxxxx-909b5454-75f8-4ac4-b325-1b40e230bbd8-gryl3kb80b3wm49ihzoo35fyqoq08n2y",
114+
"unfurl_id": "Uxxxxxxx-909b5454-75f8-4ac4-b325-1b40e230bbd8-gryl3kb80b3wm49ihzoo35fyqoq08n2y",
115+
"source": "composer",
116+
"links": [
117+
{
118+
"domain": "example.com",
119+
"url": "https://example.com/12345"
120+
},
121+
{
122+
"domain": "example.com",
123+
"url": "https://example.com/67890"
124+
},
125+
{
126+
"domain": "another-example.com",
127+
"url": "https://yet.another-example.com/v/abcde"
128+
}
129+
]
130+
}
131+
`)
132+
err := json.Unmarshal(rawE, &LinkSharedEvent{})
133+
if err != nil {
134+
t.Error(err)
135+
}
136+
}
137+
106138
func TestMessageEvent(t *testing.T) {
107139
rawE := []byte(`
108140
{

0 commit comments

Comments
 (0)