You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -134,7 +134,7 @@ We'll make four changes to the app:
134
134
* Handle when the correct delivery IDs are sent and bring up a modal for more information
135
135
* Send the information to all of the places needed when the form is submitted (including third-party locations)
136
136
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.
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!
171
171
172
172
```python
173
-
174
173
from .sample_message import delivery_message_callback # import the function to this file
175
174
176
175
defregister(app: App):
177
176
app.message(re.compile("(hi|hello|hey)"))(sample_message_callback) # This can be deleted!
178
177
# This regex will capture any number letters followed by dash
179
178
# and then any number of digits, our "confirmation number" e.g. ASDF-1234
180
179
app.message(re.compile(r"[A-Za-z]+-\d+"))(delivery_message_callback) ## add this line!
181
-
182
180
```
183
181
184
182
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
190
188
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:
191
189
192
190
```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
+
]
202
200
```
203
201
204
202
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
229
227
3. Make the connection to this function again within the `actions/__init__.py` folder with the following code:
230
228
231
229
```python
232
-
233
230
from slack_bolt import App
234
231
from .sample_action import sample_action_callback # This can be deleted
235
232
from .sample_action import deny_delivery_callback
236
233
237
234
defregister(app: App):
238
235
app.action("sample_action_id")(sample_action_callback) # This can be deleted
239
236
app.action("deny_delivery")(deny_delivery_callback) # Add this line
240
-
241
237
```
242
238
243
239
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
250
246
251
247
```json
252
248
{
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
+
]
325
321
}
326
322
```
327
323
@@ -330,7 +326,6 @@ View this modal in Block Kit Builder [here](https://app.slack.com/block-kit-buil
330
326
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.
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
387
379
1. Here’s a simple example of a message that you can use to present the information in channel.
388
380
389
381
```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
+
]
413
405
```
414
406
415
407
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.
logger.error(f"Error in approve_delivery_view: {e}")
436
-
437
427
```
438
428
439
429
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.
440
430
441
431
```python
442
-
443
432
from slack_bolt import App
444
433
from .sample_view import handle_approve_delivery_view
445
434
446
435
defregister(app: App):
447
436
app.view("sample_view_id")(sample_view_callback) # This can be deleted
448
437
app.view("approve_delivery_view")(handle_approve_delivery_view) ## Add this line
449
-
450
438
```
451
439
452
440
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:
453
441
454
442
```bash
455
-
456
443
export SF_USERNAME=<YOUR-USERNAME>
457
444
export SF_PASSWORD=<YOUR-PASSWORD>
458
445
export SF_TOKEN=<YOUR-SFDC-TOKEN>
459
-
460
446
```
461
447
462
448
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.
463
449
464
450
```python
465
-
466
451
# Extract just the numeric portion from delivery_id
0 commit comments