Skip to content

Commit 0c594ea

Browse files
nemuvskigautamr95
authored andcommitted
feat: Add support for parsing AppRateLimited events (slack-go#1308)
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.
1 parent 0c084c0 commit 0c594ea

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

slackevents/parsers.go

+26
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,32 @@ func ParseEvent(rawEvent json.RawMessage, opts ...Option) (EventsAPIEvent, error
212212
}
213213
return innerEvent, nil
214214
}
215+
216+
if e.Type == AppRateLimited {
217+
appRateLimitedEvent := &EventsAPIAppRateLimited{}
218+
err = json.Unmarshal(rawEvent, appRateLimitedEvent)
219+
if err != nil {
220+
return EventsAPIEvent{
221+
"",
222+
"",
223+
"unmarshalling_error",
224+
"",
225+
"",
226+
&slack.UnmarshallingErrorEvent{ErrorObj: err},
227+
EventsAPIInnerEvent{},
228+
}, err
229+
}
230+
return EventsAPIEvent{
231+
e.Token,
232+
e.TeamID,
233+
e.Type,
234+
e.APIAppID,
235+
e.EnterpriseID,
236+
appRateLimitedEvent,
237+
EventsAPIInnerEvent{},
238+
}, nil
239+
}
240+
215241
urlVerificationEvent := &EventsAPIURLVerificationEvent{}
216242
err = json.Unmarshal(rawEvent, urlVerificationEvent)
217243
if err != nil {

slackevents/parsers_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ func TestParseURLVerificationEvent(t *testing.T) {
7373
}
7474
}
7575

76+
func TestParseAppRateLimitedEvent(t *testing.T) {
77+
event := `
78+
{
79+
"token": "fake-token",
80+
"team_id": "T123ABC456",
81+
"minute_rate_limited": 1518467820,
82+
"api_app_id": "A123ABC456",
83+
"type": "app_rate_limited"
84+
}
85+
`
86+
msg, e := ParseEvent(json.RawMessage(event), OptionVerifyToken(&TokenComparator{"fake-token"}))
87+
if e != nil {
88+
fmt.Println(e)
89+
t.Fail()
90+
}
91+
switch ev := msg.Data.(type) {
92+
case *EventsAPIAppRateLimited:
93+
{
94+
}
95+
default:
96+
{
97+
fmt.Println(ev)
98+
t.Fail()
99+
}
100+
}
101+
}
102+
76103
func TestThatOuterCallbackEventHasInnerEvent(t *testing.T) {
77104
eventsAPIRawCallbackEvent := `
78105
{

0 commit comments

Comments
 (0)