From ac91448e54eb6ee25680641e7e7bf1d00b1f1e02 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 9 Nov 2021 21:38:24 -0800 Subject: [PATCH 1/3] sometimes the message_ts isn't a json.Number --- slackevents/inner_events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slackevents/inner_events.go b/slackevents/inner_events.go index 20152d600..ee43ae17c 100644 --- a/slackevents/inner_events.go +++ b/slackevents/inner_events.go @@ -165,7 +165,7 @@ type LinkSharedEvent struct { User string `json:"user"` TimeStamp string `json:"ts"` Channel string `json:"channel"` - MessageTimeStamp json.Number `json:"message_ts"` + MessageTimeStamp string `json:"message_ts"` ThreadTimeStamp string `json:"thread_ts"` Links []sharedLinks `json:"links"` } From c415915e40f91a77f753713c046fc8048c173d04 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Wed, 10 Nov 2021 10:55:31 -0800 Subject: [PATCH 2/3] add a new test with the payload from link_shared docs re: unfurls in the message composer --- slackevents/inner_events_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/slackevents/inner_events_test.go b/slackevents/inner_events_test.go index af3ca776c..14e70f5f8 100644 --- a/slackevents/inner_events_test.go +++ b/slackevents/inner_events_test.go @@ -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(` { From b40bd985030f7b1c71492c38b5b906543b569561 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Wed, 10 Nov 2021 20:17:43 -0800 Subject: [PATCH 3/3] add a comment for why MessageTimeStamp is a string, not json.Number --- slackevents/inner_events.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/slackevents/inner_events.go b/slackevents/inner_events.go index ee43ae17c..452328e88 100644 --- a/slackevents/inner_events.go +++ b/slackevents/inner_events.go @@ -161,10 +161,13 @@ 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"` + 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"`