Module: SlackBot::GrapeHelpers
- Includes:
- Dispatch, Interactions
- Defined in:
- lib/slack_bot/grape_extension.rb,
lib/slack_bot/grape_helpers/dispatch.rb,
lib/slack_bot/grape_helpers/interactions.rb,
sig/slack_bot.rbs
Defined Under Namespace
Modules: Dispatch, Interactions
Constant Summary
collapse
- TIMESTAMP_TOLERANCE_SECONDS =
Slack recommends rejecting requests older than 5 minutes
300
- MIN_SIGNING_SECRET_LENGTH =
Minimum length for Slack signing secret (Slack's requirement)
32
Instance Method Summary
collapse
#validate_callback_user!
Instance Method Details
#dispatch_event ⇒ Boolean
336
|
# File 'sig/slack_bot.rbs', line 336
def dispatch_event: (handler: Class, params: Hash[String, untyped], current_user: untyped) -> bool
|
#events_callback ⇒ Object
332
|
# File 'sig/slack_bot.rbs', line 332
def events_callback: (Hash[String, untyped] params) -> untyped
|
#fetch_team_id ⇒ String?
18
19
20
|
# File 'lib/slack_bot/grape_extension.rb', line 18
def fetch_team_id
params.dig("team_id") || params.dig("team", "id")
end
|
#fetch_user_id ⇒ String?
22
23
24
|
# File 'lib/slack_bot/grape_extension.rb', line 22
def fetch_user_id
params.dig("user_id") || params.dig("user", "id") || params.dig("event", "user")
end
|
#handle_block_actions_message ⇒ Object
335
|
# File 'sig/slack_bot.rbs', line 335
def handle_block_actions_message: (payload: Hash[String, untyped], user: untyped, params: Hash[String, untyped]) -> untyped
|
#handle_block_actions_view ⇒ Object
334
|
# File 'sig/slack_bot.rbs', line 334
def handle_block_actions_view: (view: Hash[String, untyped]?, user: untyped, params: Hash[String, untyped]) -> untyped
|
#interaction_team_id(payload) ⇒ String?
46
47
48
|
# File 'lib/slack_bot/grape_extension.rb', line 46
def interaction_team_id(payload)
payload.dig("team", "id") || payload["team_id"] || payload.dig("user", "team_id")
end
|
#resolve_event_user ⇒ Object?
331
|
# File 'sig/slack_bot.rbs', line 331
def resolve_event_user: (Hash[String, untyped] params) -> untyped?
|
#resolve_user_session ⇒ Object?
330
|
# File 'sig/slack_bot.rbs', line 330
def resolve_user_session: (String? team_id, String? user_id) -> untyped?
|
#route_interaction ⇒ Object
337
|
# File 'sig/slack_bot.rbs', line 337
def route_interaction: (payload: Hash[String, untyped], user: untyped, params: Hash[String, untyped]) -> untyped
|
#slack_request_retry? ⇒ Boolean
66
67
68
|
# File 'lib/slack_bot/grape_extension.rb', line 66
def slack_request_retry?
("x-slack-retry-num", "X-Slack-Retry-Num").present?
end
|
#url_verification(params) ⇒ Hash[String, String]
70
71
72
73
|
# File 'lib/slack_bot/grape_extension.rb', line 70
def url_verification(params)
SlackBot::DevConsole.log_input "SlackApi::Events#url_verification: #{params.inspect}"
{challenge: params[:challenge]}
end
|
#verify_current_user! ⇒ Boolean
60
61
62
63
64
|
# File 'lib/slack_bot/grape_extension.rb', line 60
def verify_current_user!
return true if current_user
raise SlackBot::Errors::UserAuthenticationError.new("User is not authorized")
end
|
#verify_direct_message_channel! ⇒ Boolean
50
51
52
53
54
55
56
57
58
|
# File 'lib/slack_bot/grape_extension.rb', line 50
def verify_direct_message_channel!
if params[:channel_name] == "directmessage"
true
else
raise SlackBot::Errors::ChannelAuthenticationError.new(
"This command is only available in direct messages"
)
end
end
|
#verify_slack_signature! ⇒ Boolean
26
27
28
29
30
31
32
33
34
|
# File 'lib/slack_bot/grape_extension.rb', line 26
def verify_slack_signature!
slack_signing_secret = ENV["SLACK_SIGNING_SECRET"]
timestamp = ("x-slack-request-timestamp", "X-Slack-Request-Timestamp")
slack_signature = ("x-slack-signature", "X-Slack-Signature")
(slack_signing_secret, timestamp, slack_signature)
validate_request_timestamp!(timestamp)
verify_signature_match!(slack_signing_secret, timestamp, slack_signature)
end
|
#verify_slack_team!(team_id = nil) ⇒ Boolean
36
37
38
39
40
41
42
43
44
|
# File 'lib/slack_bot/grape_extension.rb', line 36
def verify_slack_team!(team_id = nil)
slack_team_id = ENV["SLACK_TEAM_ID"]
requested_team_id = team_id || fetch_team_id
if slack_team_id.present? && slack_team_id == requested_team_id
true
else
raise SlackBot::Errors::TeamAuthenticationError.new("Team is not authorized")
end
end
|