Skip to content

Commit 7ff0656

Browse files
committed
pr feedback
1 parent c1872ed commit 7ff0656

File tree

1 file changed

+71
-20
lines changed

1 file changed

+71
-20
lines changed

docs/english/tutorial/order-confirmation/order-confirmation.md

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ If you don't already have the Slack CLI, install it from your terminal: navigate
2727

2828
### Cloning the starter app
2929

30-
Once installed, use the command `slack create` in your terminal, select the `bolt-python-starter-template`, then choose your preferred language (this tutorial shows Python). Alternatively, you can clone the [Bolt for Python template](https://github.com/slack-samples/bolt-python-starter-template) using git.
30+
Once installed, use the command `slack create` to get started with the Bolt for Python [starter template](https://github.com/slack-samples/bolt-python-starter-template). Alternatively, you can clone the template using Git.
3131

3232
You can remove the portions from the template that are not used within this tutorial to make things a bit cleaner for yourself. To do this, open your project in VS Code (you can do this from the terminal with the `code .` command) and delete the `commands`, `events`, and `shortcuts` folders from the `/listeners` folder. You can also do the same to the corresponding folders within the `/listeners/tests` folder as well. Finally, remove the imports of these files from the `/listeners/__init__.py` file.
3333

3434
## Creating your app
3535

3636
We’ll use the contents of the `manifest.json` file below. This file describes the metadata associated with your app, like its name and permissions that it requests.
3737

38-
Copy the contents of the file and [create a new app](https://api.slack.com/apps/new). Next, choose **From a manifest** and follow the prompts, pasting the manifest file contents you copied.
38+
These values are used to create an app in one of two ways:
39+
40+
- **With the Slack CLI**: Save the contents of the file to your project's `manifest.json` file then skip ahead to [starting your app](#starting-your-app).
41+
- **With app settings**: Copy the contents of the file and [create a new app](https://api.slack.com/apps/new). Next, choose **From a manifest** and follow the prompts, pasting the manifest file contents you copied.
3942

4043
```json
4144
{
@@ -84,7 +87,7 @@ Once your app has been created, scroll down to **App-Level Tokens** on the **Bas
8487

8588
Still in the app settings, navigate to the **Install App** page in the left sidebar. Install your app. When you press **Allow**, this means you’re agreeing to install your app with the permissions that it’s requesting. Copy the bot token that you receive as well and store this in a safe place as well for subsequent steps.
8689

87-
## Starting your app's server
90+
## Saving credentials
8891

8992
Within a terminal of your choice, set the two tokens from the previous step as environment variables using the commands below. Make sure not to mix these two up, `SLACK_APP_TOKEN` will start with “xapp-“ and `SLACK_BOT_TOKEN` will start with “xoxb-“.
9093

@@ -109,18 +112,26 @@ $env:SLACK_APP_TOKEN="YOUR-APP-TOKEN-HERE"
109112
$env:SLACK_BOT_TOKEN="YOUR-BOT-TOKEN-HERE"
110113
```
111114

115+
## Starting your app {#starting-your-app}
116+
112117
Run the following commands to activate a virtual environment for your Python packages to be installed, install the dependencies, and start your app.
113118

114119
```bash
115120
# Setup your python virtual environment
116-
python3 -m venv .venv
121+
python -m venv .venv
117122
source .venv/bin/activate
118123

119124
# Install the dependencies
120125
pip install -r requirements.txt
121126

122127
# Start your local server
123-
python3 app.py
128+
slack run
129+
```
130+
131+
If you're not using the Slack CLI, a different `python` command can be used to start your app instead:
132+
133+
```sh
134+
python app.py
124135
```
125136

126137
Now that your app is running, you should be able to see it within Slack. In Slack, create a channel that you can test in and try inviting your bot to it using the `/invite @Your-app-name-here` command. Check that your app works by saying “hi” in the channel where your app is, and you should receive a message back from it. If you don’t, ensure you completed all the steps above.
@@ -138,23 +149,48 @@ For all of these steps, we will use [Block Kit Builder](https://app.slack.com/bl
138149

139150
### Updating the "hi" message
140151

141-
The first thing we want to do is change the “hi, how are you?” message from our app into something more useful. Here’s something that you can use to start off with, but you can make it your own within Block Kit Builder. Once you have something you like, copy the blocks by clicking the **Copy Payload** button in the top right.
152+
The first thing we want to do is change the “hi, how are you?” message from our app into something more useful. Here’s a `blocks` object built with Block Kit Builder:
142153

143-
Take the function below and place your blocks within the blocks dictionary `[]`. Update the payload:
144-
* Remove the initial blocks key and convert any boolean true values to `True` to fit with Python conventions.
145-
* If you see variables within `{}` brackets, this is part of an f-string, which allows you to insert variables within strings in a clean manner. Place the `f` character before these strings like this:
154+
```json
155+
156+
"blocks": [
157+
{
158+
"type": "section",
159+
"text": {
160+
"type": "mrkdwn",
161+
"text": "Confirm *{delivery_id}* is correct?"
162+
}
163+
},
164+
{
165+
"type": "actions",
166+
"elements": [
167+
{
168+
"type": "button",
169+
"text": {
170+
"type": "plain_text",
171+
"text": "Correct",
172+
"emoji": true
173+
},
174+
"style": "primary",
175+
"action_id": "approve_delivery"
176+
},
177+
{
178+
"type": "button",
179+
"text": {
180+
"type": "plain_text",
181+
"text": "Not correct",
182+
"emoji": true
183+
},
184+
"style": "danger",
185+
"action_id": "deny_delivery"
186+
}
187+
]
188+
}
189+
]
146190

147-
```python
148-
{
149-
"type": "section",
150-
"text": {
151-
"type": "mrkdwn",
152-
"text": f"Confirm *{delivery_id}* is correct?", # place the "f" character here at the beginning of the string
153-
},
154-
},
155191
```
156192

157-
Place all of this in the `sample_message.py` file.
193+
Take the function below and place your blocks within the blocks dictionary `[]`.
158194

159195
```python
160196
def delivery_message_callback(context: BoltContext, say: Say, logger: Logger):
@@ -167,13 +203,28 @@ def delivery_message_callback(context: BoltContext, say: Say, logger: Logger):
167203
logger.error(e)
168204
```
169205

170-
Next, you’ll need to make some connections so that this function is called when a message is sent in the channel where your app is. Head to `messages/__init__.py` and add the line below to the register function. Don’t forget to add the import to the callback function as well!
206+
Update the payload:
207+
* Remove the initial blocks key and convert any boolean true values to `True` to fit with Python conventions.
208+
* If you see variables within `{}` brackets, this is part of an f-string, which allows you to insert variables within strings in a clean manner. Place the `f` character before these strings like this:
209+
210+
```python
211+
{
212+
"type": "section",
213+
"text": {
214+
"type": "mrkdwn",
215+
"text": f"Confirm *{delivery_id}* is correct?", # place the "f" character here at the beginning of the string
216+
},
217+
},
218+
```
219+
220+
Place all of this in the `sample_message.py` file.
221+
222+
Next, you’ll need to register this listener to respond when a message is sent in the channel with your app. Head to `messages/__init__.py` and overwrite the function there with the one below, which registers the function. Don’t forget to add the import to the callback function as well!
171223

172224
```python
173225
from .sample_message import delivery_message_callback # import the function to this file
174226

175227
def register(app: App):
176-
app.message(re.compile("(hi|hello|hey)"))(sample_message_callback) # This can be deleted!
177228
# This regex will capture any number letters followed by dash
178229
# and then any number of digits, our "confirmation number" e.g. ASDF-1234
179230
app.message(re.compile(r"[A-Za-z]+-\d+"))(delivery_message_callback) ## add this line!

0 commit comments

Comments
 (0)