Skip to content

Commit 88358f6

Browse files
committed
more formatting tweaks
1 parent 08ef2df commit 88358f6

File tree

1 file changed

+105
-121
lines changed

1 file changed

+105
-121
lines changed

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

Lines changed: 105 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ We'll make four changes to the app:
134134
* Handle when the correct delivery IDs are sent and bring up a modal for more information
135135
* Send the information to all of the places needed when the form is submitted (including third-party locations)
136136

137-
All of these steps require you to use [Block Kit Builder](https://app.slack.com/block-kit-builder), a tool that helps you create messages, modals and other surfaces within Slack. Open [Block Kit Builder](https://app.slack.com/block-kit-builder), take a look and play around! We’ll create some views next.
137+
For all of these steps, we will use [Block Kit Builder](https://app.slack.com/block-kit-builder), a tool that helps you create messages, modals and other surfaces within Slack. Open [Block Kit Builder](https://app.slack.com/block-kit-builder), take a look, and play around! We’ll create some views next.
138138

139139
### Updating the "hi" message
140140

@@ -170,15 +170,13 @@ def delivery_message_callback(context: BoltContext, say: Say, logger: Logger):
170170
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!
171171

172172
```python
173-
174173
from .sample_message import delivery_message_callback # import the function to this file
175174

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

184182
Now, restart your server to bring in the new code and test that your function works by sending an order confirmation ID, like `HWOA-1524`, in your testing channel. Your app should respond with the message you created within Block Kit Builder.
@@ -190,15 +188,15 @@ Notice that if you try to click on either of the buttons within your message, no
190188
1. Head to Block Kit Builder once again. We want to build a message that lets the user know that the wrong order ID has been submitted. Here's a [section](/reference/block-kit/blocks/section-block) block to get you started:
191189

192190
```json
193-
"blocks": [
194-
{
195-
"type": "section",
196-
"text": {
197-
"type": "mrkdwn",
198-
"text": "Delivery *{delivery_id}* was incorrect ❌"
199-
}
200-
}
201-
]
191+
"blocks": [
192+
{
193+
"type": "section",
194+
"text": {
195+
"type": "mrkdwn",
196+
"text": "Delivery *{delivery_id}* was incorrect ❌"
197+
}
198+
}
199+
]
202200
```
203201

204202
View this block in Block Kit Builder [here](https://app.slack.com/block-kit-builder/#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22Delivery%20*%7Bdelivery_id%7D*%20was%20incorrect%20%E2%9D%8C%22%7D%7D%5D%7D).
@@ -229,15 +227,13 @@ This function will call the [`chat.update`](/reference/methods/chat.update) Web
229227
3. Make the connection to this function again within the `actions/__init__.py` folder with the following code:
230228

231229
```python
232-
233230
from slack_bolt import App
234231
from .sample_action import sample_action_callback # This can be deleted
235232
from .sample_action import deny_delivery_callback
236233

237234
def register(app: App):
238235
app.action("sample_action_id")(sample_action_callback) # This can be deleted
239236
app.action("deny_delivery")(deny_delivery_callback) # Add this line
240-
241237
```
242238

243239
Test out your app by sending in a confirmation number into your channel and clicking the `Not correct` button. If the message is updated, then you’re good to go onto the next step.
@@ -250,78 +246,78 @@ The next step is to handle the `Confirm` button. In this case, we’re going to
250246

251247
```json
252248
{
253-
"title": {
254-
"type": "plain_text",
255-
"text": "Approve Delivery"
256-
},
257-
"submit": {
258-
"type": "plain_text",
259-
"text": "Approve"
260-
},
261-
"type": "modal",
262-
"callback_id": "approve_delivery_view",
263-
"private_metadata": "{delivery_id}",
264-
"blocks": [
265-
{
266-
"type": "section",
267-
"text": {
268-
"type": "mrkdwn",
269-
"text": "Approving delivery *{delivery_id}*"
270-
}
271-
},
272-
{
273-
"type": "input",
274-
"block_id": "notes",
275-
"label": {
276-
"type": "plain_text",
277-
"text": "Additional delivery notes"
278-
},
279-
"element": {
280-
"type": "plain_text_input",
281-
"action_id": "notes_input",
282-
"multiline": true,
283-
"placeholder": {
284-
"type": "plain_text",
285-
"text": "Add notes..."
286-
}
287-
},
288-
"optional": true
289-
},
290-
{
291-
"type": "input",
292-
"block_id": "location",
293-
"label": {
294-
"type": "plain_text",
295-
"text": "Delivery Location"
296-
},
297-
"element": {
298-
"type": "plain_text_input",
299-
"action_id": "location_input",
300-
"placeholder": {
301-
"type": "plain_text",
302-
"text": "Enter the location details..."
303-
}
304-
},
305-
"optional": true
306-
},
307-
{
308-
"type": "input",
309-
"block_id": "channel",
310-
"label": {
311-
"type": "plain_text",
312-
"text": "Notification Channel"
313-
},
314-
"element": {
315-
"type": "channels_select",
316-
"action_id": "channel_select",
317-
"placeholder": {
318-
"type": "plain_text",
319-
"text": "Select channel for notifications"
320-
}
321-
},
322-
"optional": false
323-
}
324-
]
249+
"title": {
250+
"type": "plain_text",
251+
"text": "Approve Delivery"
252+
},
253+
"submit": {
254+
"type": "plain_text",
255+
"text": "Approve"
256+
},
257+
"type": "modal",
258+
"callback_id": "approve_delivery_view",
259+
"private_metadata": "{delivery_id}",
260+
"blocks": [
261+
{
262+
"type": "section",
263+
"text": {
264+
"type": "mrkdwn",
265+
"text": "Approving delivery *{delivery_id}*"
266+
}
267+
},
268+
{
269+
"type": "input",
270+
"block_id": "notes",
271+
"label": {
272+
"type": "plain_text",
273+
"text": "Additional delivery notes"
274+
},
275+
"element": {
276+
"type": "plain_text_input",
277+
"action_id": "notes_input",
278+
"multiline": true,
279+
"placeholder": {
280+
"type": "plain_text",
281+
"text": "Add notes..."
282+
}
283+
},
284+
"optional": true
285+
},
286+
{
287+
"type": "input",
288+
"block_id": "location",
289+
"label": {
290+
"type": "plain_text",
291+
"text": "Delivery Location"
292+
},
293+
"element": {
294+
"type": "plain_text_input",
295+
"action_id": "location_input",
296+
"placeholder": {
297+
"type": "plain_text",
298+
"text": "Enter the location details..."
299+
}
300+
},
301+
"optional": true
302+
},
303+
{
304+
"type": "input",
305+
"block_id": "channel",
306+
"label": {
307+
"type": "plain_text",
308+
"text": "Notification Channel"
309+
},
310+
"element": {
311+
"type": "channels_select",
312+
"action_id": "channel_select",
313+
"placeholder": {
314+
"type": "plain_text",
315+
"text": "Select channel for notifications"
316+
}
317+
},
318+
"optional": false
319+
}
320+
]
325321
}
326322
```
327323

@@ -330,7 +326,6 @@ View this modal in Block Kit Builder [here](https://app.slack.com/block-kit-buil
330326
2. Within the `actions/sample_action.py` file, add the following function, replacing the view with the one you created above. Again, any strings with variables will be updated to f-strings and also any booleans will need to be capitalized.
331327

332328
```python
333-
334329
def approve_delivery_callback(ack, body, client, logger: Logger):
335330
try:
336331
ack()
@@ -360,13 +355,11 @@ def approve_delivery_callback(ack, body, client, logger: Logger):
360355
logger.info(f"Approval modal opened by user {body['user']['id']}")
361356
except Exception as e:
362357
logger.error(e)
363-
364358
```
365359

366360
Similar to the `deny` button, we need to hook up all the connections. Your `actions/__init__.py` should look something like this:
367361

368362
```python
369-
370363
from slack_bolt import App
371364
from .sample_action import deny_delivery_callback
372365
from .sample_action import approve_delivery_callback
@@ -375,7 +368,6 @@ from .sample_action import approve_delivery_callback
375368
def register(app: App):
376369
app.action("approve_delivery")(approve_delivery_callback)
377370
app.action("deny_delivery")(deny_delivery_callback)
378-
379371
```
380372

381373
Test your app by typing in a confirmation number in channel, click the confirm button and see if the modal comes up and you are able to capture information from the user.
@@ -387,35 +379,34 @@ Lastly, we’ll handle the submission of the form, which will trigger two things
387379
1. Here’s a simple example of a message that you can use to present the information in channel.
388380

389381
```json
390-
"blocks": [
391-
{
392-
"type": "section",
393-
"text": {
394-
"type": "mrkdwn",
395-
"text": "✅ Delivery *{delivery_id}* approved:"
396-
}
397-
},
398-
{
399-
"type": "section",
400-
"text": {
401-
"type": "mrkdwn",
402-
"text": "*Delivery Notes:*\n{notes or 'None'}"
403-
}
404-
},
405-
{
406-
"type": "section",
407-
"text": {
408-
"type": "mrkdwn",
409-
"text": "*Delivery Location:*\n{loc or 'None'}"
410-
}
411-
}
412-
]
382+
"blocks": [
383+
{
384+
"type": "section",
385+
"text": {
386+
"type": "mrkdwn",
387+
"text": "✅ Delivery *{delivery_id}* approved:"
388+
}
389+
},
390+
{
391+
"type": "section",
392+
"text": {
393+
"type": "mrkdwn",
394+
"text": "*Delivery Notes:*\n{notes or 'None'}"
395+
}
396+
},
397+
{
398+
"type": "section",
399+
"text": {
400+
"type": "mrkdwn",
401+
"text": "*Delivery Location:*\n{loc or 'None'}"
402+
}
403+
}
404+
]
413405
```
414406

415407
View this in Block Kit Builder [here](https://app.slack.com/block-kit-builder/?1#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22%E2%9C%85%20Delivery%20*%7Bdelivery_id%7D*%20approved:%22%7D%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Delivery%20Notes:*%5Cn%7Bnotes%20or%20'None'%7D%22%7D%7D,%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*Delivery%20Location:*%5Cn%7Bloc%20or%20'None'%7D%22%7D%7D%5D%7D). Modify it however you like and then place it within the code below in the `/views/sample_views.py` file.
416408

417409
```python
418-
419410
def handle_approve_delivery_view(ack, client, view, logger: Logger):
420411
try:
421412
ack()
@@ -433,36 +424,30 @@ def handle_approve_delivery_view(ack, client, view, logger: Logger):
433424

434425
except Exception as e:
435426
logger.error(f"Error in approve_delivery_view: {e}")
436-
437427
```
438428

439429
2. Making the connections in the `/views/__init__.py `file, we can test that this works by sending a message once again in our test channel.
440430

441431
```python
442-
443432
from slack_bolt import App
444433
from .sample_view import handle_approve_delivery_view
445434

446435
def register(app: App):
447436
app.view("sample_view_id")(sample_view_callback) # This can be deleted
448437
app.view("approve_delivery_view")(handle_approve_delivery_view) ## Add this line
449-
450438
```
451439

452440
3. Let’s also send the information to Salesforce. There are [several ways](https://github.com/simple-salesforce/simple-salesforce?tab=readme-ov-file#examples) for you to access Salesforce through its API, but in this example, we’ve utilized `username`, `password` and `token` parameters. If you need help with getting your API token for Salesforce, take a look at [this article](https://help.salesforce.com/s/articleView?id=xcloud.user_security_token.htm&type=5). You’ll need to add these values as environment variables like we did earlier with our Slack tokens. You can use the following commands:
453441

454442
```bash
455-
456443
export SF_USERNAME=<YOUR-USERNAME>
457444
export SF_PASSWORD=<YOUR-PASSWORD>
458445
export SF_TOKEN=<YOUR-SFDC-TOKEN>
459-
460446
```
461447

462448
4. We’re going to use assume that order information is stored in the Order object and that the confirmation IDs map to the 8-digit Order numbers within Salesforce. Given that assumption, we need to make a query to find the correct object, add the inputted information, and we’re done. Place this functionality before the last excerpt within the `/views/sample_views.py` file.
463449

464450
```python
465-
466451
# Extract just the numeric portion from delivery_id
467452
delivery_number = "".join(filter(str.isdigit, delivery_id))
468453

@@ -493,7 +478,6 @@ export SF_TOKEN=<YOUR-SFDC-TOKEN>
493478
except Exception as sf_error:
494479
logger.error(f"Update failed for order {delivery_id}: {sf_error}")
495480
# Continue execution even if Salesforce update fails
496-
497481
```
498482

499483
You’ll also need to add the two imports that are found within this code to the top of the file.

0 commit comments

Comments
 (0)