Skip to content

Commit 929008e

Browse files
Add next-gen future documentation (#761)
1 parent df35180 commit 929008e

40 files changed

+1191
-179
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ coverage.xml
2929
.python-version
3030
pip
3131
.mypy_cache/
32+
.ruby-version
3233

3334
# JetBrains PyCharm settings
3435
.idea/

docs/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
source 'https://rubygems.org'
22
gem 'github-pages', group: :jekyll_plugins
33
gem 'dotenv'
4+
gem 'webrick'

docs/_config.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ collections:
1818
tutorials:
1919
output: true
2020
permalink: /tutorials/:slug
21+
future:
22+
output: true
23+
permalink: /future/:slug
2124

2225
defaults:
23-
-
24-
scope:
26+
- scope:
2527
path: ""
2628
values:
2729
layout: "default"
@@ -35,12 +37,16 @@ t:
3537
advanced: Advanced concepts
3638
start: Getting started
3739
contribute: Contributing
40+
beta: BETA
41+
legacy: LEGACY
3842
ja-jp:
3943
basic: 基本的な概念
4044
steps: ワークフローステップ
4145
advanced: 応用コンセプト
4246
start: Bolt 入門ガイド
4347
contribute: 貢献
48+
beta: BETA
49+
legacy: LEGACY
4450

4551
# Metadata
4652
repo_name: bolt-python
@@ -56,7 +62,6 @@ google_tag_manager: GTM-KFZ5MK7
5662
markdown: kramdown
5763
kramdown:
5864
parse_block_html: true
59-
parse_span_html: true
6065
syntax_highlighter_opts:
6166
block:
6267
line_numbers: true

docs/_future/concepts.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Slack developer beta
3+
lang: en
4+
slug: concepts
5+
order: 0
6+
layout: future
7+
permalink: /future/concepts
8+
---
9+
# Slack developer beta concepts <span class="label-beta">BETA</span>
10+
11+
<div class="section-content">
12+
13+
This page contains all the concepts that are necessary to allow you to use the next-gen Slack features in Python.
14+
15+
<p class="alert alert_info">
16+
<ts-icon class="ts_icon_info_circle"></ts-icon>
17+
Our next-generation platform is currently in beta. <a href="https://api.slack.com/future/survey" target="_blank">Your feedback is most welcome</a> - all feedback will help shape the future platform experience!
18+
</p>
19+
</div>

docs/_future/deploy_your_app.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
3+
title: Deploy your app
4+
lang: en
5+
slug: deploy-your-app
6+
order: 6
7+
layout: tutorial
8+
permalink: /tutorial/deploy-your-app
9+
---
10+
# Deploy your app <span class="label-beta">BETA</span>
11+
12+
<div class="section-content">
13+
Instructions for deploying your next-generation Bolt Python application to third-party infrastructure are coming soon! Stay tuned.
14+
15+
<p class="alert alert_info"><ts-icon class="ts_icon_info_circle"></ts-icon>Our next-generation platform is currently in beta. <a href="https://api.slack.com/future/survey" target="_blank">Your feedback is most welcome</a> - all feedback will help shape the future platform experience!</p>
16+
</div>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: Getting started
3+
order: 1
4+
slug: getting-started-future
5+
lang: en
6+
layout: tutorial
7+
permalink: /tutorial/getting-started-future
8+
---
9+
## Getting started <span class="label-beta">BETA</span>
10+
11+
<div class="section-content">
12+
This guide will cover how to get started with your next-gen platform using Bolt for Python, by setting up the Slack CLI and installing the required dependencies.
13+
14+
Find out about the next-generation platform on Slack's <a href="https://api.slack.com/future/intro" target="_blank">official introduction page.</a>
15+
</div>
16+
17+
---
18+
19+
### Limitations
20+
21+
Bolt for Python supports app development using next-gen platform features like <a href="/bolt-python/future/concepts#functions" target="_blank">Functions</a>, <a href="/bolt-python/future/concepts#manifest-workflows" target="_blank">Workflows</a> and tools such as the Slack CLI alongside all current generally available Slack Platform features.
22+
23+
#### We do not yet support
24+
25+
- Deployment to secure and managed Slack infrastructure.
26+
- Datastores API <a href="https://api.slack.com/future/datastores" target="_blank">Datastores</a> functionality.
27+
28+
> 💡 If you'd like to deploy your app with Slack infrastructure, consider building your next-generation application with the Deno Slack API. You can get started with that <a href="https://api.slack.com/future/get-started" target="_blank">here</a>.
29+
30+
---
31+
32+
### Setting up {#setting-up}
33+
34+
#### Slack CLI {#setting-up-cli}
35+
36+
To build a next-generation app with Bolt for Python, you'll need to get the Slack CLI.
37+
38+
Install the Slack CLI by following this <a href="https://api.slack.com/future/quickstart" target="_blank">Quickstart</a>. Since we won't be using Deno to build our next-generation app, you can skip any instructions related to installing Deno or creating an app using a Deno template. Once you've logged into the CLI using `slack login` and verified your login using `slack auth list`, you can proceed with the instructions in this guide.
39+
40+
#### Dependencies {#setting-up-dependencies}
41+
42+
Once the CLI is set up, make sure your machine has the most recent version of <a href="https://www.python.org/" target="_blank">Python</a> installed. You can install Python through a package manager (such as <a href="https://brew.sh/" target="_blank">Homebrew</a> for macOS) or directly from the <a href="https://www.python.org/downloads/" target="_blank">website</a>.
43+
44+
---
45+
46+
### Create a new app {#create-app}
47+
48+
Before you start developing with Bolt, you'll want to create a Slack app.
49+
50+
To create the app, you'll run the following command:
51+
52+
```bash
53+
slack create my-app -t slack-samples/bolt-python-starter-template -b future
54+
```
55+
56+
This command creates an app through the CLI by cloning a specified template. In this case, the template is the <a href="https://github.com/slack-samples/bolt-python-starter-template/tree/future" target="_blank">Bolt for Python Starter Template</a> on the `future` branch. This starter template includes a "Hello World" example that demonstrates how to use <a href="/bolt-python/future/concepts#built-in-functions" target="_blank">built-in</a> and <a href="/bolt-python/future/concepts#functions" target="_blank">custom</a> Functions, <a href="https://api.slack.com/future/triggers" target="_blank">Triggers</a> and <a href="/bolt-python/future/concepts#manifest-workflows" target="_blank">Workflows</a>.
57+
58+
Once the app is successfully created, you should see a message like this:
59+
60+
```text
61+
✨ my-app successfully created
62+
63+
🧭 Explore your project's README.md for documentation and code samples, and at any time run slack help to display a list of available commands
64+
65+
🧑‍🚀 Follow the steps below to try out your new project
66+
67+
1️⃣ Change into your project directory with: cd my-app
68+
69+
2️⃣ Develop locally and see changes in real-time with: slack run
70+
71+
3️⃣ When you're ready to deploy for production use: slack deploy
72+
73+
🔔 If you leave the workspace, you won’t be able to manage any apps you’ve deployed to it. Apps you deploy will belong to the workspace even if you leave the workspace
74+
```
75+
76+
---
77+
78+
### Set up your trigger {#setup-trigger}
79+
80+
As mentioned, this app comes with pre-existing functionality - it uses Functions, Workflows and a <a href="https://api.slack.com/future/triggers/link" target="_blank">Link Trigger</a> that will allow users in Slack to initiate the functionality provided by the app. Let's run a command to initialize that Link Trigger via the CLI.
81+
82+
First, make sure you're in the project directory in your command line: `cd my-app`
83+
84+
Then, run the following command to create a Trigger:
85+
86+
```bash
87+
slack triggers create --trigger-def "triggers/sample-trigger.json"
88+
```
89+
90+
The above command will create a <a href="https://api.slack.com/future/triggers/link" target="_blank">Link Trigger</a> for the selected workspace. Make sure to select the workspace you want. Once the trigger is successfully created, you should see an output like this:
91+
92+
```bash
93+
⚡ Trigger created
94+
Trigger ID: [ID]
95+
Trigger Type: shortcut
96+
Trigger Name: Sample Trigger
97+
URL: https://slack.com/shortcuts/[ID]/[Some ID]
98+
```
99+
100+
The provided URL can be pasted into Slack; Slack will unfurl it into a button that users can interact with to initiate your app's functionality! Copy this URL and save it somewhere; you'll need it for later.
101+
102+
---
103+
104+
### Run your app {#run-your-app}
105+
106+
Now that your app and Trigger are successfully created, let's try running it!
107+
108+
```bash
109+
# install the required project dependencies
110+
pip install -r requirements.txt
111+
112+
# start a local development server
113+
slack run
114+
```
115+
116+
Executing `pip install -r requirements.txt` installs all the project requirements to your machine.
117+
118+
Executing `slack run` starts a local development server, syncing changes to your workspace's development version of your app.
119+
120+
You'll be prompted to select a workspace to install the app to&mdash;select the development instance of your workspace (you'll know it's the development version because the name has the string `(dev)` appended).
121+
122+
> 💡 If you don't see the workspace you'd like to use in the list, you can `CTRL + C` out of the `slack run` command and run `slack auth login`. This will allow you to authenticate in your desired workspace to have it show up in the list for `slack run`.
123+
124+
You'll see an output in your Terminal to indicate your app is running, similar to what you would see with any other Bolt for Python app. You can search for the `⚡️ Bolt app is running! ⚡️` message to make sure that your app has successfully started up.
125+
126+
### Trigger your app's workflow {#trigger-workflow}
127+
128+
With your app running, access your workspace and paste the URL from the Trigger you created in the [previous step](/bolt-python/tutorial/getting-started-future#setup-trigger) into a message in a public channel.
129+
130+
> 💡 App Triggers are automatically saved as a channel bookmark under "Workflows" for easy access.
131+
132+
Send the message and click the "Run" button that appears. A modal will appear prompting you to enter information to greet someone in your Slack workspace. Fill out the requested information.
133+
134+
![Hello World modal](https://slack.dev/bolt-js/assets/hello-world-modal.png "Hello World modal")
135+
136+
Then, submit the form. In the specified channel submitted in the form, you should receive a message from the app tagging the submitted user. The message will also contain a randomly generated greeting and the message you wrote in the form.
137+
138+
The full app flow can be seen here:
139+
![Hello World app](https://slack.dev/bolt-js/assets/hello-world-demo.gif "Hello World app")
140+
141+
---
142+
143+
### Next steps {#next-steps}
144+
145+
Now we have a working instance of a next-generation app in your workspace and you've seen it in action! You can explore on your own and dive into the code yourself <a href="https://github.com/slack-samples/bolt-python-starter-template/tree/future" target="_blank">here</a> or continue your learning journey by diving into [App Manifests](/bolt-python/future/concepts#manifests) or looking into adding more [Functions](/bolt-python/future/concepts#functions), [Workflows](/bolt-python/future/concepts#manifest-workflows), and [Triggers](#setup-trigger) to your app!
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Listening & responding to functions
3+
lang: en
4+
slug: functions
5+
order: 5
6+
layout: future
7+
---
8+
9+
<div class="section-content">
10+
11+
Your app can use the `function()` method to listen to incoming function requests. The method requires a function `callback_id` of type `str`. This `callback_id` must also be defined in your [Function](/bolt-python/future/concepts#manifest-functions) definition. Functions must eventually be completed with the `complete()` function to inform Slack that your app has processed the function request. `complete()` requires **one of two** keyword arguments: `outputs` or `error`. There are two ways to complete a Function with `complete()`:
12+
13+
* `outputs` of type `dict` completes your function **successfully** and provides a dictionary containing the outputs of your function as defined in the app's manifest.
14+
* `error` of type `str` completes your function **unsuccessfully** and provides a message containing information regarding why your function was not successful.
15+
16+
</div>
17+
18+
<div>
19+
<span class="annotation">Refer to <a href="https://slack.dev/bolt-python/api-docs/slack_bolt/kwargs_injection/args.html" target="_blank">the module document</a> to learn the available listener arguments.</span>
20+
```python
21+
# The sample function simply outputs an input
22+
@app.function("sample_function")
23+
def sample_func(event: dict, complete: Complete):
24+
try:
25+
message = event["inputs"]["message"]
26+
complete(
27+
outputs={
28+
"updatedMsg": f":wave: You submitted the following message: \n\n>{message}"
29+
}
30+
)
31+
except Exception as e:
32+
complete(error=f"Cannot submit the message: {e}")
33+
raise e
34+
```
35+
</div>
36+
37+
<details class="secondary-wrapper">
38+
<summary markdown="0">
39+
<h4 class="secondary-header">Function Interactivity</h4>
40+
</summary>
41+
42+
<div class="secondary-content">
43+
44+
The `function()` method returns a `SlackFunction` decorator object. This object can be used by your app to set up interactive listeners such as [actions](/bolt-python/concepts#action-respond) and [views](/bolt-python/concepts#view_submissions). These listeners listen to events created during the handling of your `function` event. Additionally, they will only be called when a user interacts with a block element that has the following attributes:
45+
46+
* It was created during the handling of a `function` event.
47+
* The `action_id` matches the interactive listeners `action_id`.
48+
49+
These listeners behave similarly to the ones assigned directly to your app. The notable difference is that `complete()` must be called once your function is completed.
50+
51+
</div>
52+
53+
```python
54+
# Your listener will be called when your function "sample_function" is triggered from a workflow
55+
# When triggered a message containing a button with an action_id "approve_button" is posted
56+
@app.function("sample_function")
57+
def sample_func(event: dict, complete: Complete):
58+
try:
59+
client.chat_postMessage(
60+
channel="a-channel-id",
61+
text="A new button appears",
62+
blocks=[
63+
{
64+
"type": "actions",
65+
"block_id": "approve-button",
66+
"elements": [
67+
{
68+
"type": "button",
69+
"text": {
70+
"type": "plain_text",
71+
"text": "Click",
72+
},
73+
"action_id": "sample_action",
74+
"style": "primary",
75+
},
76+
],
77+
},
78+
],
79+
)
80+
except Exception as e:
81+
complete(error=f"Cannot post the message: {e}")
82+
raise e
83+
84+
# Your listener will be called when a block element
85+
# - Created by your "sample_func"
86+
# - With the action_id "sample_action"
87+
# is triggered
88+
@sample_func.action("sample_action")
89+
def update_message(ack, body, client, complete):
90+
try:
91+
ack()
92+
if "container" in body and "message_ts" in body["container"]:
93+
client.reactions_add(
94+
name="white_check_mark",
95+
channel=body["channel"]["id"],
96+
timestamp=body["container"]["message_ts"],
97+
)
98+
complete()
99+
except Exception as e:
100+
logger.error(e)
101+
complete(error=f"Cannot react to message: {e}")
102+
raise e
103+
```
104+
105+
</details>

0 commit comments

Comments
 (0)