Skip to content

Commit

Permalink
Don't use json.Number to encode/decode events event_ts
Browse files Browse the repository at this point in the history
This field should always be stored/used as a string according to [1].
This also makes the type more consistent across events.

[1] slackhq/slack-api-docs#7 (comment)
  • Loading branch information
abustany committed Apr 11, 2022
1 parent 179dac2 commit 6361adf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
52 changes: 25 additions & 27 deletions slackevents/inner_events.go
Expand Up @@ -3,8 +3,6 @@
package slackevents

import (
"encoding/json"

"github.com/slack-go/slack"
)

Expand All @@ -16,13 +14,13 @@ type EventsAPIInnerEvent struct {

// AppMentionEvent is an (inner) EventsAPI subscribable event.
type AppMentionEvent struct {
Type string `json:"type"`
User string `json:"user"`
Text string `json:"text"`
TimeStamp string `json:"ts"`
ThreadTimeStamp string `json:"thread_ts"`
Channel string `json:"channel"`
EventTimeStamp json.Number `json:"event_ts"`
Type string `json:"type"`
User string `json:"user"`
Text string `json:"text"`
TimeStamp string `json:"ts"`
ThreadTimeStamp string `json:"thread_ts"`
Channel string `json:"channel"`
EventTimeStamp string `json:"event_ts"`

// When Message comes from a channel that is shared between workspaces
UserTeam string `json:"user_team,omitempty"`
Expand All @@ -34,12 +32,12 @@ type AppMentionEvent struct {

// AppHomeOpenedEvent Your Slack app home was opened.
type AppHomeOpenedEvent struct {
Type string `json:"type"`
User string `json:"user"`
Channel string `json:"channel"`
EventTimeStamp json.Number `json:"event_ts"`
Tab string `json:"tab"`
View slack.View `json:"view"`
Type string `json:"type"`
User string `json:"user"`
Channel string `json:"channel"`
EventTimeStamp string `json:"event_ts"`
Tab string `json:"tab"`
View slack.View `json:"view"`
}

// AppUninstalledEvent Your Slack app was uninstalled.
Expand Down Expand Up @@ -198,15 +196,15 @@ type sharedLinks struct {
// TODO: Improve this so that it is not required to manually parse ChannelType
type MessageEvent struct {
// Basic Message Event - https://api.slack.com/events/message
ClientMsgID string `json:"client_msg_id"`
Type string `json:"type"`
User string `json:"user"`
Text string `json:"text"`
ThreadTimeStamp string `json:"thread_ts"`
TimeStamp string `json:"ts"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
EventTimeStamp json.Number `json:"event_ts"`
ClientMsgID string `json:"client_msg_id"`
Type string `json:"type"`
User string `json:"user"`
Text string `json:"text"`
ThreadTimeStamp string `json:"thread_ts"`
TimeStamp string `json:"ts"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
EventTimeStamp string `json:"event_ts"`

// When Message comes from a channel that is shared between workspaces
UserTeam string `json:"user_team,omitempty"`
Expand Down Expand Up @@ -308,9 +306,9 @@ type TokensRevokedEvent struct {

// EmojiChangedEvent is the event of custom emoji has been added or changed
type EmojiChangedEvent struct {
Type string `json:"type"`
Subtype string `json:"subtype"`
EventTimeStamp json.Number `json:"event_ts"`
Type string `json:"type"`
Subtype string `json:"subtype"`
EventTimeStamp string `json:"event_ts"`

// filled out when custom emoji added
Name string `json:"name,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion socketmode/socketmode_test.go
Expand Up @@ -236,7 +236,7 @@ func TestEventParsing(t *testing.T) {
TimeStamp: "1610927831.000200",
ThreadTimeStamp: "",
Channel: "redacted",
EventTimeStamp: json.Number("1610927831.000200"),
EventTimeStamp: "1610927831.000200",
},
},
},
Expand Down

0 comments on commit 6361adf

Please sign in to comment.