Class: Banacle::SlashCommand::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/banacle/slash_command/renderer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, command, config) ⇒ Renderer

Returns a new instance of Renderer.



13
14
15
16
17
# File 'lib/banacle/slash_command/renderer.rb', line 13

def initialize(request, command, config)
  @request = request
  @command = command
  @config = config
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



19
20
21
# File 'lib/banacle/slash_command/renderer.rb', line 19

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/banacle/slash_command/renderer.rb', line 19

def config
  @config
end

#requestObject (readonly)

Returns the value of attribute request.



19
20
21
# File 'lib/banacle/slash_command/renderer.rb', line 19

def request
  @request
end

Class Method Details

.render_error(error) ⇒ Object



6
7
8
9
10
11
# File 'lib/banacle/slash_command/renderer.rb', line 6

def self.render_error(error)
  Slack::Response.new(
    response_type: "ephemeral",
    text: "An error occurred: #{error}",
  ).to_json
end

Instance Method Details

#render_approval_requestObject



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
# File 'lib/banacle/slash_command/renderer.rb', line 21

def render_approval_request
  text = <<-EOS
<@#{user_id}> wants to *#{command.action} NACL DENY entry* under the following conditions:
```
#{JSON.pretty_generate(command.to_h)}
```
  EOS

  Slack::Response.new(
    response_type: "in_channel",
    text: text,
    attachments: [
      Slack::Attachment.new(
        text: config.dig(:approval_request, :attachment, :text) || "*Approval Request*",
        fallback: "TBD",
        callback_id: "banacle_approval_request",
        color: "#3AA3E3",
        attachment_type: "default",
        actions: [
          Slack::Action.approve_button,
          Slack::Action.reject_button,
          Slack::Action.cancel_button,
        ]
      ),
    ],
  ).to_json
end

#user_idObject



49
50
51
# File 'lib/banacle/slash_command/renderer.rb', line 49

def user_id
  request.user_id
end