Skip to content

Commit

Permalink
Merge pull request #1052 from abustany/add-missing-event-ts-on-inner-…
Browse files Browse the repository at this point in the history
…events

Uniformize event_ts support on inner events
  • Loading branch information
kanata2 committed Jun 2, 2022
2 parents 497c385 + 6361adf commit 8d2ed5e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 70 deletions.
151 changes: 82 additions & 69 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 All @@ -56,34 +54,39 @@ type ChannelCreatedEvent struct {

// ChannelDeletedEvent represents the Channel deleted event
type ChannelDeletedEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
Type string `json:"type"`
Channel string `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// ChannelArchiveEvent represents the Channel archive event
type ChannelArchiveEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
User string `json:"user"`
Type string `json:"type"`
Channel string `json:"channel"`
User string `json:"user"`
EventTimestamp string `json:"event_ts"`
}

// ChannelUnarchiveEvent represents the Channel unarchive event
type ChannelUnarchiveEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
User string `json:"user"`
Type string `json:"type"`
Channel string `json:"channel"`
User string `json:"user"`
EventTimestamp string `json:"event_ts"`
}

// ChannelLeftEvent represents the Channel left event
type ChannelLeftEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
Type string `json:"type"`
Channel string `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// ChannelRenameEvent represents the Channel rename event
type ChannelRenameEvent struct {
Type string `json:"type"`
Channel ChannelRenameInfo `json:"channel"`
Type string `json:"type"`
Channel ChannelRenameInfo `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// ChannelIDChangedEvent represents the Channel identifier changed event
Expand Down Expand Up @@ -112,32 +115,37 @@ type ChannelRenameInfo struct {

// GroupDeletedEvent represents the Group deleted event
type GroupDeletedEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
Type string `json:"type"`
Channel string `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// GroupArchiveEvent represents the Group archive event
type GroupArchiveEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
Type string `json:"type"`
Channel string `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// GroupUnarchiveEvent represents the Group unarchive event
type GroupUnarchiveEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
Type string `json:"type"`
Channel string `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// GroupLeftEvent represents the Group left event
type GroupLeftEvent struct {
Type string `json:"type"`
Channel string `json:"channel"`
Type string `json:"type"`
Channel string `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// GroupRenameEvent represents the Group rename event
type GroupRenameEvent struct {
Type string `json:"type"`
Channel GroupRenameInfo `json:"channel"`
Type string `json:"type"`
Channel GroupRenameInfo `json:"channel"`
EventTimestamp string `json:"event_ts"`
}

// GroupRenameInfo represents the information associated with the Group rename event
Expand Down Expand Up @@ -171,6 +179,7 @@ type LinkSharedEvent struct {
MessageTimeStamp string `json:"message_ts"`
ThreadTimeStamp string `json:"thread_ts"`
Links []sharedLinks `json:"links"`
EventTimestamp string `json:"event_ts"`
}

type sharedLinks struct {
Expand All @@ -187,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 @@ -227,21 +236,23 @@ type MessageEvent struct {

// MemberJoinedChannelEvent A member joined a public or private channel
type MemberJoinedChannelEvent struct {
Type string `json:"type"`
User string `json:"user"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
Team string `json:"team"`
Inviter string `json:"inviter"`
Type string `json:"type"`
User string `json:"user"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
Team string `json:"team"`
Inviter string `json:"inviter"`
EventTimestamp string `json:"event_ts"`
}

// MemberLeftChannelEvent A member left a public or private channel
type MemberLeftChannelEvent struct {
Type string `json:"type"`
User string `json:"user"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
Team string `json:"team"`
Type string `json:"type"`
User string `json:"user"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
Team string `json:"team"`
EventTimestamp string `json:"event_ts"`
}

type pinEvent struct {
Expand Down Expand Up @@ -281,21 +292,23 @@ type tokens struct {

// TeamJoinEvent A new member joined a workspace - https://api.slack.com/events/team_join
type TeamJoinEvent struct {
Type string `json:"type"`
User *slack.User `json:"user"`
Type string `json:"type"`
User *slack.User `json:"user"`
EventTimestamp string `json:"event_ts"`
}

// TokensRevokedEvent APP's API tokes are revoked - https://api.slack.com/events/tokens_revoked
// TokensRevokedEvent APP's API tokens are revoked - https://api.slack.com/events/tokens_revoked
type TokensRevokedEvent struct {
Type string `json:"type"`
Tokens tokens `json:"tokens"`
Type string `json:"type"`
Tokens tokens `json:"tokens"`
EventTimestamp string `json:"event_ts"`
}

// 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 All @@ -313,10 +326,10 @@ type EmojiChangedEvent struct {

// WorkflowStepExecuteEvent is fired, if a workflow step of your app is invoked
type WorkflowStepExecuteEvent struct {
Type string `json:"type"`
CallbackID string `json:"callback_id"`
WorkflowStep EventWorkflowStep `json:"workflow_step"`
EventTS string `json:"event_ts"`
Type string `json:"type"`
CallbackID string `json:"callback_id"`
WorkflowStep EventWorkflowStep `json:"workflow_step"`
EventTimestamp string `json:"event_ts"`
}

type EventWorkflowStep struct {
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 8d2ed5e

Please sign in to comment.