Skip to content

Commit 164c1c8

Browse files
authored
Merge pull request #374 from shanedewael/add-block-kit-example
Add Block Kit example to docs
2 parents 7589d39 + bff7436 commit 164c1c8

File tree

13 files changed

+106
-1
lines changed

13 files changed

+106
-1
lines changed

docs-src/basic_usage.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,55 @@ See `chat.postEphemeral <https://api.slack.com/methods/chat.postEphemeral>`_ for
5959

6060
--------
6161

62+
Customizing a message's layout
63+
-----------------------
64+
The chat.postMessage method takes an optional blocks argument that allows you to customize the layout of a message.
65+
Blocks for Web API methods are all specified in a single object literal, so just add additional keys for any optional argument.
66+
67+
To send a message to a channel, use the channel's ID. For IMs, use the user's ID.
68+
69+
.. code-block:: python
70+
71+
sc.api_call(
72+
"chat.postMessage",
73+
channel="C0XXXXXX",
74+
blocks=[
75+
{
76+
"type": "section",
77+
"text": {
78+
"type": "mrkdwn",
79+
"text": "Danny Torrence left the following review for your property:"
80+
}
81+
},
82+
{
83+
"type": "section",
84+
"text": {
85+
"type": "mrkdwn",
86+
"text": "<https://example.com|Overlook Hotel> \n :star: \n Doors had too many axe holes, guest in room " +
87+
"237 was far too rowdy, whole place felt stuck in the 1920s."
88+
},
89+
"accessory": {
90+
"type": "image",
91+
"image_url": "https://images.pexels.com/photos/750319/pexels-photo-750319.jpeg",
92+
"alt_text": "Haunted hotel image"
93+
}
94+
},
95+
{
96+
"type": "section",
97+
"fields": [
98+
{
99+
"type": "mrkdwn",
100+
"text": "*Average Rating*\n1.0"
101+
}
102+
]
103+
}
104+
]
105+
)
106+
107+
**Note:** You can use the `Block Kit Builder <https://api.slack.com/tools/block-kit-builder>`for a playground where you can prototype your message's look and feel.
108+
109+
--------
110+
62111
Replying to messages and creating threads
63112
------------------------------------------
64113
Threaded messages are just like regular messages, except thread replies are grouped together to provide greater context

docs/about.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/auth.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/basic_usage.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1 current"><a class="current reference internal" href="#">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="#deleting-a-message">Deleting a message</a></li>
@@ -202,6 +203,51 @@ <h2>Sending a message<a class="headerlink" href="#sending-a-message" title="Perm
202203
<p>See <a class="reference external" href="https://api.slack.com/methods/chat.postEphemeral">chat.postEphemeral</a> for more info.</p>
203204
</div>
204205
<hr class="docutils" />
206+
<div class="section" id="customizing-a-message-s-layout">
207+
<h2>Customizing a message’s layout<a class="headerlink" href="#customizing-a-message-s-layout" title="Permalink to this headline"></a></h2>
208+
<p>The chat.postMessage method takes an optional blocks argument that allows you to customize the layout of a message.
209+
Blocks for Web API methods are all specified in a single object literal, so just add additional keys for any optional argument.</p>
210+
<p>To send a message to a channel, use the channel’s ID. For IMs, use the user’s ID.</p>
211+
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span>
212+
<span class="s2">&quot;chat.postMessage&quot;</span><span class="p">,</span>
213+
<span class="n">channel</span><span class="o">=</span><span class="s2">&quot;C0XXXXXX&quot;</span><span class="p">,</span>
214+
<span class="n">blocks</span><span class="o">=</span><span class="p">[</span>
215+
<span class="p">{</span>
216+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;section&quot;</span><span class="p">,</span>
217+
<span class="s2">&quot;text&quot;</span><span class="p">:</span> <span class="p">{</span>
218+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;mrkdwn&quot;</span><span class="p">,</span>
219+
<span class="s2">&quot;text&quot;</span><span class="p">:</span> <span class="s2">&quot;Danny Torrence left the following review for your property:&quot;</span>
220+
<span class="p">}</span>
221+
<span class="p">},</span>
222+
<span class="p">{</span>
223+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;section&quot;</span><span class="p">,</span>
224+
<span class="s2">&quot;text&quot;</span><span class="p">:</span> <span class="p">{</span>
225+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;mrkdwn&quot;</span><span class="p">,</span>
226+
<span class="s2">&quot;text&quot;</span><span class="p">:</span> <span class="s2">&quot;&lt;https://example.com|Overlook Hotel&gt; </span><span class="se">\n</span><span class="s2"> :star: </span><span class="se">\n</span><span class="s2"> Doors had too many axe holes, guest in room &quot;</span> <span class="o">+</span>
227+
<span class="s2">&quot;237 was far too rowdy, whole place felt stuck in the 1920s.&quot;</span>
228+
<span class="p">},</span>
229+
<span class="s2">&quot;accessory&quot;</span><span class="p">:</span> <span class="p">{</span>
230+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;image&quot;</span><span class="p">,</span>
231+
<span class="s2">&quot;image_url&quot;</span><span class="p">:</span> <span class="s2">&quot;https://images.pexels.com/photos/750319/pexels-photo-750319.jpeg&quot;</span><span class="p">,</span>
232+
<span class="s2">&quot;alt_text&quot;</span><span class="p">:</span> <span class="s2">&quot;Haunted hotel image&quot;</span>
233+
<span class="p">}</span>
234+
<span class="p">},</span>
235+
<span class="p">{</span>
236+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;section&quot;</span><span class="p">,</span>
237+
<span class="s2">&quot;fields&quot;</span><span class="p">:</span> <span class="p">[</span>
238+
<span class="p">{</span>
239+
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;mrkdwn&quot;</span><span class="p">,</span>
240+
<span class="s2">&quot;text&quot;</span><span class="p">:</span> <span class="s2">&quot;*Average Rating*</span><span class="se">\n</span><span class="s2">1.0&quot;</span>
241+
<span class="p">}</span>
242+
<span class="p">]</span>
243+
<span class="p">}</span>
244+
<span class="p">]</span>
245+
<span class="p">)</span>
246+
</pre></div>
247+
</div>
248+
<p><strong>Note:</strong> You can use the <a href="#id1"><span class="problematic" id="id2">`</span></a>Block Kit Builder &lt;<a class="reference external" href="https://api.slack.com/tools/block-kit-builder">https://api.slack.com/tools/block-kit-builder</a>&gt;`for a playground where you can prototype your message’s look and feel.</p>
249+
</div>
250+
<hr class="docutils" />
205251
<div class="section" id="replying-to-messages-and-creating-threads">
206252
<h2>Replying to messages and creating threads<a class="headerlink" href="#replying-to-messages-and-creating-threads" title="Permalink to this headline"></a></h2>
207253
<p>Threaded messages are just like regular messages, except thread replies are grouped together to provide greater context

docs/changelog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/conversations.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/faq.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/genindex.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
</li>
6969
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
7070
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
71+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7374
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

docs/metadata.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</li>
6868
<li class="toctree-l1"><a class="reference internal" href="basic_usage.html">Basic Usage</a><ul>
6969
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#sending-a-message">Sending a message</a></li>
70+
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#customizing-a-message-s-layout">Customizing a message’s layout</a></li>
7071
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li>
7172
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#updating-the-content-of-a-message">Updating the content of a message</a></li>
7273
<li class="toctree-l2"><a class="reference internal" href="basic_usage.html#deleting-a-message">Deleting a message</a></li>

0 commit comments

Comments
 (0)