Class: Slackathon::SlackCommandJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/slackathon/slack_command_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(name, type, params) ⇒ Object



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
# File 'app/jobs/slackathon/slack_command_job.rb', line 8

def perform(name, type, params)
  klass = name.constantize
  params = params.with_indifferent_access
  url = params[:response_url]

  body = case type
  when "command"
    klass.dispatch_command(params)
  when "interaction"
    klass.dispatch_interaction(params)
  end

  say(url, body)
rescue => e
  say(url, {
    response_type: "ephemeral",
    text: "      :mac_bomb: Darn - that slash command (\#{name.underscore.gsub(\"_command\", \"\")}) didn't work\n      ```\n      \#{e.class}: \#{e.message}\n      \#{e.backtrace.take(5).map { |line| line.indent(4) }.join(\"\\n\")}\n          ...\n      ```\n    TEXT\n  })\n\n  raise e\nend\n"