-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathMethodsRateLimitTier.java
More file actions
93 lines (77 loc) · 3.35 KB
/
MethodsRateLimitTier.java
File metadata and controls
93 lines (77 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.slack.api.methods;
import java.util.HashMap;
import java.util.Map;
/**
* @see <a href="https://docs.slack.dev/apis/web-api/rate-limits">Slack Rate Limits</a>
*/
public enum MethodsRateLimitTier {
/**
* 1+ per minute
* <p>
* Access tier 1 methods infrequently. A small amount of burst behavior is tolerated.
*/
Tier1,
/**
* 20+ per minute
* <p>
* Most methods allow at least 20 requests per minute, while allowing for occasional bursts of more requests.
*/
Tier2,
/**
* 50+ per minute
* <p>
* Tier 3 methods allow a larger number of requests and are typically attached to methods with paginating collections of conversations or users. Sporadic bursts are welcome.
*/
Tier3,
/**
* 100+ per minute
* <p>
* Enjoy a large request quota for Tier 4 methods, including generous burst behavior.
*/
Tier4,
/**
* This method allows hundreds of requests per minute. Use it as often as is reasonably required.
*/
SpecialTier_auth_test,
/**
* assistant.search.context has special rate limiting conditions.
* It generally allows 10+ requests per minute for most teams.
*/
SpecialTier_assistant_search_context,
/**
* assistant.threads.setStatus has the similar tier with chat.postMessage API.
*/
SpecialTier_assistant_threads_setStatus,
/**
* chat.postMessage has special rate limiting conditions.
* It will generally allow an app to post 1 message per second to a specific channel.
* There are limits governing your app's relationship with the entire workspace above that,
* limiting posting to several hundred messages per minute. Generous burst behavior is also granted.
*/
SpecialTier_chat_postMessage,
/**
* This method allows hundreds of requests per minute. Use it as often as is reasonably required.
*/
SpecialTier_chat_getPermalink;
// --------------------------------------------------------------------------------------------
private static final Map<MethodsRateLimitTier, Integer> allowedRequestsPerMinute = new HashMap<>();
static {
allowedRequestsPerMinute.put(MethodsRateLimitTier.Tier1, 1);
allowedRequestsPerMinute.put(MethodsRateLimitTier.Tier2, 20);
allowedRequestsPerMinute.put(MethodsRateLimitTier.Tier3, 50);
allowedRequestsPerMinute.put(MethodsRateLimitTier.Tier4, 100);
allowedRequestsPerMinute.put(MethodsRateLimitTier.SpecialTier_auth_test, 600);
allowedRequestsPerMinute.put(MethodsRateLimitTier.SpecialTier_assistant_search_context, 10);
allowedRequestsPerMinute.put(MethodsRateLimitTier.SpecialTier_chat_getPermalink, 600);
allowedRequestsPerMinute.put(MethodsRateLimitTier.SpecialTier_chat_postMessage, 60); // per channel
allowedRequestsPerMinute.put(MethodsRateLimitTier.SpecialTier_assistant_threads_setStatus, 60); // per DM
}
public static Integer getAllowedRequestsPerMinute(MethodsRateLimitTier tier) {
if (tier == null) {
// Just in case, this method returns Tier2 when the given Tier is null to avoid runtime errors
// Tier2 may not be optimal in the case but it works for most cases
return allowedRequestsPerMinute.get(MethodsRateLimitTier.Tier2);
}
return allowedRequestsPerMinute.get(tier);
}
}