Skip to content

Commit

Permalink
feat: Add support for parsing AppRateLimited events (#1308)
Browse files Browse the repository at this point in the history
The code changes in this commit add support for parsing AppRateLimited events in the `ParseEvent` function. This allows the application to handle rate-limited events from the Slack API.
  • Loading branch information
nemuvski authored Aug 15, 2024
1 parent e947079 commit 50e7414
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions slackevents/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,32 @@ func ParseEvent(rawEvent json.RawMessage, opts ...Option) (EventsAPIEvent, error
}
return innerEvent, nil
}

if e.Type == AppRateLimited {
appRateLimitedEvent := &EventsAPIAppRateLimited{}
err = json.Unmarshal(rawEvent, appRateLimitedEvent)
if err != nil {
return EventsAPIEvent{
"",
"",
"unmarshalling_error",
"",
"",
&slack.UnmarshallingErrorEvent{ErrorObj: err},
EventsAPIInnerEvent{},
}, err
}
return EventsAPIEvent{
e.Token,
e.TeamID,
e.Type,
e.APIAppID,
e.EnterpriseID,
appRateLimitedEvent,
EventsAPIInnerEvent{},
}, nil
}

urlVerificationEvent := &EventsAPIURLVerificationEvent{}
err = json.Unmarshal(rawEvent, urlVerificationEvent)
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions slackevents/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@ func TestParseURLVerificationEvent(t *testing.T) {
}
}

func TestParseAppRateLimitedEvent(t *testing.T) {
event := `
{
"token": "fake-token",
"team_id": "T123ABC456",
"minute_rate_limited": 1518467820,
"api_app_id": "A123ABC456",
"type": "app_rate_limited"
}
`
msg, e := ParseEvent(json.RawMessage(event), OptionVerifyToken(&TokenComparator{"fake-token"}))
if e != nil {
fmt.Println(e)
t.Fail()
}
switch ev := msg.Data.(type) {
case *EventsAPIAppRateLimited:
{
}
default:
{
fmt.Println(ev)
t.Fail()
}
}
}

func TestThatOuterCallbackEventHasInnerEvent(t *testing.T) {
eventsAPIRawCallbackEvent := `
{
Expand Down

0 comments on commit 50e7414

Please sign in to comment.