Class: Slack::Surfaces::Modal

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/surfaces/modal.rb

Overview

Modals provide focused spaces ideal for requesting and collecting data from users, or temporarily displaying dynamic and interactive information.

api.slack.com/surfaces#modals api.slack.com/reference/surfaces/views

Constant Summary collapse

TYPE =
'modal'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, blocks: nil, private_metadata: nil, callback_id: nil, external_id: nil, clear_on_close: nil, notify_on_close: nil) ⇒ Modal

Returns a new instance of Modal.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/slack/surfaces/modal.rb', line 17

def initialize(
  title: nil,
  blocks: nil,
  private_metadata: nil,
  callback_id: nil,
  external_id: nil,
  clear_on_close: nil,
  notify_on_close: nil
)
  @blocks = blocks || Slack::BlockKit::Blocks.new

  @private_metadata = 
  @callback_id = callback_id
  @external_id = external_id

  @clear_on_close = clear_on_close
  @notify_on_close = notify_on_close

  @title = Slack::BlockKit::Composition::PlainText.new(text: title) if title

  @close, @submit = nil
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



40
41
42
# File 'lib/slack/surfaces/modal.rb', line 40

def blocks
  @blocks
end

Instance Method Details

#as_jsonObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/slack/surfaces/modal.rb', line 60

def as_json(*)
  {
    type: TYPE,
    blocks: @blocks.as_json,
    title: @title&.as_json,
    close: @close&.as_json,
    submit: @submit&.as_json,
    clear_on_close: @clear_on_close,
    notify_on_close: @notify_on_close,
    private_metadata: @private_metadata,
    callback_id: @callback_id,
    external_id: @external_id
  }.compact
end

#close(text:, emoji: nil) ⇒ Object



48
49
50
51
52
# File 'lib/slack/surfaces/modal.rb', line 48

def close(text:, emoji: nil)
  @close = Slack::BlockKit::Composition::PlainText.new(text: text, emoji: emoji)

  self
end

#submit(text:, emoji: nil) ⇒ Object



54
55
56
57
58
# File 'lib/slack/surfaces/modal.rb', line 54

def submit(text:, emoji: nil)
  @submit = Slack::BlockKit::Composition::PlainText.new(text: text, emoji: emoji)

  self
end

#title(text:, emoji: nil) ⇒ Object



42
43
44
45
46
# File 'lib/slack/surfaces/modal.rb', line 42

def title(text:, emoji: nil)
  @title = Slack::BlockKit::Composition::PlainText.new(text: text, emoji: emoji)

  self
end