Class: Slack::BlockKit::Blocks

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/block_kit/blocks.rb

Overview

Blocks are a series of components that can be combined to create visually rich and compellingly interactive messages.

api.slack.com/reference/messaging/blocks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Blocks

Returns a new instance of Blocks.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
# File 'lib/slack/block_kit/blocks.rb', line 12

def initialize
  @blocks = []

  yield(self) if block_given?
end

Instance Attribute Details

#blocksObject

Returns the value of attribute blocks.



10
11
12
# File 'lib/slack/block_kit/blocks.rb', line 10

def blocks
  @blocks
end

Instance Method Details

#actions(block_id: nil) {|block| ... } ⇒ Object

Yields:

  • (block)


18
19
20
21
22
23
24
# File 'lib/slack/block_kit/blocks.rb', line 18

def actions(block_id: nil)
  block = Layout::Actions.new(block_id: block_id)

  yield(block) if block_given?

  append(block)
end

#append(block) ⇒ Object



102
103
104
105
106
# File 'lib/slack/block_kit/blocks.rb', line 102

def append(block)
  @blocks << block

  self
end

#as_jsonObject



108
109
110
# File 'lib/slack/block_kit/blocks.rb', line 108

def as_json(*)
  @blocks.map(&:as_json)
end

#context(block_id: nil) {|block| ... } ⇒ Object

Yields:

  • (block)


26
27
28
29
30
31
32
# File 'lib/slack/block_kit/blocks.rb', line 26

def context(block_id: nil)
  block = Layout::Context.new(block_id: block_id)

  yield(block) if block_given?

  append(block)
end

#divider(block_id: nil) ⇒ Object



34
35
36
37
38
# File 'lib/slack/block_kit/blocks.rb', line 34

def divider(block_id: nil)
  block = Layout::Divider.new(block_id: block_id)

  append(block)
end

#header(text:, block_id: nil, emoji: nil) ⇒ Object



40
41
42
43
44
# File 'lib/slack/block_kit/blocks.rb', line 40

def header(text:, block_id: nil, emoji: nil)
  block = Layout::Header.new(text: text, block_id: block_id, emoji: emoji)

  append(block)
end

#image(url:, alt_text:, title: nil, block_id: nil, emoji: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/slack/block_kit/blocks.rb', line 46

def image(url:, alt_text:, title: nil, block_id: nil, emoji: nil)
  block = Layout::Image.new(
    url: url,
    alt_text: alt_text,
    title: title,
    block_id: block_id,
    emoji: emoji
  )

  append(block)
end

#input(label:, hint: nil, block_id: nil, dispatch_action: nil, optional: nil, emoji: nil) {|block| ... } ⇒ Object

Yields:

  • (block)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/slack/block_kit/blocks.rb', line 87

def input(label:, hint: nil, block_id: nil, dispatch_action: nil, optional: nil, emoji: nil)
  block = Layout::Input.new(
    label: label,
    hint: hint,
    block_id: block_id,
    dispatch_action: dispatch_action,
    optional: optional,
    emoji: emoji
  )

  yield(block) if block_given?

  append(block)
end

#rich_text(block_id: nil) {|block| ... } ⇒ Object

Yields:

  • (block)


58
59
60
61
62
63
64
# File 'lib/slack/block_kit/blocks.rb', line 58

def rich_text(block_id: nil)
  block = Layout::RichText.new(block_id: block_id)

  yield(block) if block_given?

  append(block)
end

#section(block_id: nil) {|block| ... } ⇒ Object

Yields:

  • (block)


79
80
81
82
83
84
85
# File 'lib/slack/block_kit/blocks.rb', line 79

def section(block_id: nil)
  block = Layout::Section.new(block_id: block_id)

  yield(block) if block_given?

  append(block)
end

#video(alt_text:, thumbnail_url:, video_url:, title:, description:, **optional_args) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/slack/block_kit/blocks.rb', line 66

def video(alt_text:, thumbnail_url:, video_url:, title:, description:, **optional_args)
  block = Layout::Video.new(
    alt_text: alt_text,
    thumbnail_url: thumbnail_url,
    video_url: video_url,
    title: title,
    description: description,
    **optional_args
  )

  append(block)
end