Skip to content

Commit

Permalink
Merge pull request #999 from toshok/message-timestamp-is-string
Browse files Browse the repository at this point in the history
link_shared `message_ts` field isn't always a number
  • Loading branch information
kanata2 committed Nov 14, 2021
2 parents 979adb8 + b40bd98 commit 792f7ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
13 changes: 8 additions & 5 deletions slackevents/inner_events.go
Expand Up @@ -161,11 +161,14 @@ type GridMigrationStartedEvent struct {

// LinkSharedEvent A message was posted containing one or more links relevant to your application
type LinkSharedEvent struct {
Type string `json:"type"`
User string `json:"user"`
TimeStamp string `json:"ts"`
Channel string `json:"channel"`
MessageTimeStamp json.Number `json:"message_ts"`
Type string `json:"type"`
User string `json:"user"`
TimeStamp string `json:"ts"`
Channel string `json:"channel"`
// MessageTimeStamp can be both a numeric timestamp if the LinkSharedEvent corresponds to a sent
// message and (contrary to the field name) a uuid if the LinkSharedEvent is generated in the
// compose text area.
MessageTimeStamp string `json:"message_ts"`
ThreadTimeStamp string `json:"thread_ts"`
Links []sharedLinks `json:"links"`
}
Expand Down
32 changes: 32 additions & 0 deletions slackevents/inner_events_test.go
Expand Up @@ -103,6 +103,38 @@ func TestLinkSharedEvent(t *testing.T) {
}
}

func TestLinkSharedComposerEvent(t *testing.T) {
rawE := []byte(`
{
"type": "link_shared",
"channel": "COMPOSER",
"is_bot_user_member": true,
"user": "Uxxxxxxx",
"message_ts": "Uxxxxxxx-909b5454-75f8-4ac4-b325-1b40e230bbd8-gryl3kb80b3wm49ihzoo35fyqoq08n2y",
"unfurl_id": "Uxxxxxxx-909b5454-75f8-4ac4-b325-1b40e230bbd8-gryl3kb80b3wm49ihzoo35fyqoq08n2y",
"source": "composer",
"links": [
{
"domain": "example.com",
"url": "https://example.com/12345"
},
{
"domain": "example.com",
"url": "https://example.com/67890"
},
{
"domain": "another-example.com",
"url": "https://yet.another-example.com/v/abcde"
}
]
}
`)
err := json.Unmarshal(rawE, &LinkSharedEvent{})
if err != nil {
t.Error(err)
}
}

func TestMessageEvent(t *testing.T) {
rawE := []byte(`
{
Expand Down

0 comments on commit 792f7ed

Please sign in to comment.