Skip to content

Commit aa18a88

Browse files
committed
Add some examples
1 parent 520a3e3 commit aa18a88

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,53 @@ Finally, require this:
3737
require 'slack/block_kit'
3838
```
3939

40+
## Examples
41+
42+
Here are a few examples that might help you get started!
43+
44+
```ruby
45+
require 'faraday'
46+
require 'slack/block_kit'
47+
require 'json'
48+
49+
a_prebuilt_block = Slack::BlockKit::Layout::Section.new
50+
text = Slack::BlockKit::Composition::Mrkdwn.new(text: ':wave: *hello*')
51+
an_image = Slack::BlockKit::Element::Image.new(image_url: 'https://git.io/fjDW8', alt_text: 'a picture')
52+
a_prebuilt_block.accessorise(an_image)
53+
a_prebuilt_block.text = text
54+
55+
blocks = Slack::BlockKit.blocks do |b|
56+
b.section do |s|
57+
s.plain_text(text: 'Some plain text message!')
58+
s.button(text: 'A button that is important', style: 'primary', action_id: 'id')
59+
end
60+
61+
b.divider
62+
63+
b.context do |c|
64+
c.mrkdwn(text: '_some italicised text for context_')
65+
end
66+
67+
b.append(a_prebuilt_block)
68+
end
69+
70+
webhook_url = 'https://hooks.slack.com/services/your/webhook/url'
71+
body = { blocks: blocks.as_json, text: 'New block message!' }
72+
73+
response = Faraday.post(
74+
webhook_url,
75+
body.to_json,
76+
'Content-Type' => 'application/json'
77+
)
78+
```
79+
80+
This will create a message like this:
81+
82+
![example block message](https://git.io/fjDWR)
83+
84+
You can also check out the [`slackerduty`](https://github.com/CGA1123/slackerduty) project for some example,
85+
[`Slackerduty::Alert`](https://github.com/CGA1123/slackerduty/blob/b33d708124ddf36d1432080ba7e16e66fefa6993/lib/slackerduty/alert.rb#L28-L34) and [`Slackerduty::Blocks`](https://github.com/CGA1123/slackerduty/blob/master/lib/slackerduty/blocks) may be helpful places to start.
86+
4087
## Contributing
4188

4289
Bug reports and pull requests are welcome on GitHub at https://github.com/CGA1123/slack_block_kit-ruby

0 commit comments

Comments
 (0)