Skip to content

Commit 007d278

Browse files
committed
Add a few adjustments
1 parent 79d80b0 commit 007d278

File tree

8 files changed

+84
-49
lines changed

8 files changed

+84
-49
lines changed

docs/_basic/authenticating_oauth.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ To learn more about the OAuth installation flow with Slack, [read the API docume
1818
</div>
1919

2020
```python
21+
import os
2122
from slack_bolt.oauth.oauth_settings import OAuthSettings
2223
from slack_sdk.oauth.installation_store import FileInstallationStore
2324
from slack_sdk.oauth.state_store import FileOAuthStateStore
@@ -26,12 +27,14 @@ oauth_settings = OAuthSettings(
2627
client_id=os.environ["SLACK_CLIENT_ID"],
2728
client_secret=os.environ["SLACK_CLIENT_SECRET"],
2829
scopes=["channels:read", "groups:read", "chat:write"],
29-
installation_store=FileInstallationStore(),
30-
state_store=FileOAuthStateStore(expiration_seconds=120)
30+
installation_store=FileInstallationStore(base_dir="./data"),
31+
state_store=FileOAuthStateStore(expiration_seconds=600, base_dir="./data")
3132
)
3233

33-
app = App(signing_secret=os.environ["SIGNING_SECRET"],
34-
oauth_settings=oauth_settings)
34+
app = App(
35+
signing_secret=os.environ["SIGNING_SECRET"],
36+
oauth_settings=oauth_settings
37+
)
3538
```
3639

3740
<details class="secondary-wrapper">
@@ -51,9 +54,29 @@ You can override the default OAuth using `oauth_settings`, which can be passed i
5154
</div>
5255

5356
```python
57+
from slack_bolt.oauth.callback_options import CallbackOptions, SuccessArgs, FailureArgs
58+
import slack_bolt.response.BoltResponse
59+
60+
def success(args: SuccessArgs) -> BoltResponse:
61+
assert args.request is not None
62+
return BoltResponse(
63+
status=200, # you can redirect users too
64+
body="Your own response to end-users here"
65+
)
66+
67+
def failure(args: FailureArgs) -> BoltResponse:
68+
assert args.request is not None
69+
assert args.reason is not None
70+
return BoltResponse(
71+
status=args.suggested_status_code,
72+
body="Your own response to end-users here"
73+
)
74+
75+
callback_options = CallbackOptions(success=success, failure=failure)
76+
5477
app = App(
5578
signing_secret=os.environ.get("SLACK_SIGNING_SECRET"),
56-
installation_store=FileInstallationStore(),
79+
installation_store=FileInstallationStore(base_dir="./data"),
5780
oauth_settings=OAuthSettings(
5881
client_id=os.environ.get("SLACK_CLIENT_ID"),
5982
client_secret=os.environ.get("SLACK_CLIENT_SECRET"),
@@ -62,9 +85,8 @@ app = App(
6285
redirect_uri=None,
6386
install_path="/slack/install",
6487
redirect_uri_path="/slack/oauth_redirect",
65-
state_store=FileOAuthStateStore(expiration_seconds=600),
66-
callback_options=CallbackOptions(success=success,
67-
failure=failure),
88+
state_store=FileOAuthStateStore(expiration_seconds=600, base_dir="./data"),
89+
callback_options=callback_options,
6890
),
6991
)
7092
```

docs/_basic/listening_events.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ You can filter on subtypes of events by passing in the additional key `subtype`.
3838

3939
```python
4040
# Matches all messages from bot users
41-
@app.message({"subtype": "message_changed"})
42-
def log_message_change(logger, message):
43-
logger.info(f"The user {message['user']} changed the message to {message['text']}")
41+
@app.event({"type": "message", "subtype": "message_changed"})
42+
def log_message_change(logger, event):
43+
logger.info(f"The user {event['user']} changed the message to {event['text']}")
4444
```
4545

4646
</details>

docs/_basic/listening_messages.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ order: 1
99

1010
To listen to messages that [your app has access to receive](https://api.slack.com/messaging/retrieving#permissions), you can use the `message()` method which filters out events that aren’t of type `message`.
1111

12-
`message()` accepts an argument of type `str` or `RegEx` object that filters out any messages that don’t match the pattern.
12+
`message()` accepts an argument of type `str` or `re.Pattern` object that filters out any messages that don’t match the pattern.
1313

1414
</div>
1515

@@ -23,7 +23,7 @@ def say_hello(message, say):
2323

2424
<details class="secondary-wrapper">
2525
<summary markdown="0">
26-
<h4 class="secondary-header">Using a RegEx pattern</h4>
26+
<h4 class="secondary-header">Using a regular expression pattern</h4>
2727
</summary>
2828

2929
<div class="secondary-content" markdown="0">
@@ -35,7 +35,7 @@ The `re.compile()` method can be used instead of a string for more granular matc
3535
```python
3636
@app.message(re.compile("(hi|hello|hey)"))
3737
def say_hello_regex(say, context):
38-
# RegEx matches are inside of context.matches
38+
# regular expression matches are inside of context.matches
3939
greeting = context['matches'][0]
4040
say(f"{greeting}, how are you?")
4141
```

docs/_basic/listening_modals.md

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,37 @@ Read more about view submissions in our <a href="https://api.slack.com/surfaces/
1717

1818
```python
1919
# Handle a view_submission event
20-
​​@app.view("view_b")
21-
​​def handle_submission(ack, body, client, view):
22-
​​ # Acknowledge the view_submission event
23-
​​ ack()
24-
​​
25-
​​ # Do whatever you want with the input data - here we're saving it to a DB
26-
# then sending the user a verifcation of their submission
27-
​​
28-
​​ # Assume there's an input block with `block_1` as the block_id and `input_a`
29-
​​ val = view["state"]["values"]["block_1"]["input_a"]
30-
​​ user = body["user"]["id"]
31-
​​
32-
​​ # Message to send user
33-
​​ msg = ""
34-
​​
35-
​​ try:
36-
​​ # Save to DB
37-
​​ msg = f"Your submission of {val} was successful"
38-
​​ except Exception as e:
39-
​​ # Handle error
40-
​​ msg = "There was an error with your submission"
41-
​​ finally:
42-
​​ # Message the user
43-
​​ client.chat_postMessage(channel=user, text=msg)
20+
@app.view("view_b")
21+
def handle_submission(ack, body, client, view):
22+
23+
# Assume there's an input block with `block_1` as the block_id and `input_a`
24+
val = view["state"]["values"]["block_1"]["input_a"]
25+
user = body["user"]["id"]
26+
27+
# Validate the inputs
28+
errors = {}
29+
if val is not None and len(val) <= 5:
30+
errors["block_1"] = "The value must be longer than 5 characters"
31+
if len(errors) > 0:
32+
ack(response_action="errors", errors=errors)
33+
return
34+
35+
# Acknowledge the view_submission event and close the modal
36+
ack()
37+
38+
# Do whatever you want with the input data - here we're saving it to a DB
39+
# then sending the user a verification of their submission
40+
41+
# Message to send user
42+
msg = ""
43+
44+
try:
45+
# Save to DB
46+
msg = f"Your submission of {val} was successful"
47+
except Exception as e:
48+
# Handle error
49+
msg = "There was an error with your submission"
50+
finally:
51+
# Message the user
52+
client.chat_postMessage(channel=user, text=msg)
4453
```

docs/_basic/listening_responding_shortcuts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def open_modal(ack, shortcut, client):
7575
```python
7676

7777
# Your middleware will only be called when the callback_id matches 'open_modal' AND the type matches 'message_action'
78-
@app.message_shortcut("open_modal")
78+
@app.shortcut({"callback_id": "open_modal", "type": "message_action"})
7979
def open_modal(ack, shortcut, client):
8080
# Acknowledge the shortcut request
8181
ack()

docs/_basic/sending_messages.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ To explore adding rich message layouts to your app, read through [the guide on o
3636
# Sends a section block with datepicker when someone reacts with a 📅 emoji
3737
@app.event("reaction_added")
3838
def show_datepicker(event, say):
39-
reaction = event["reaction"]
40-
if reaction == "calendar":
41-
blocks = [{
39+
reaction = event["reaction"]
40+
if reaction == "calendar":
41+
blocks = [{
4242
"type": "section",
4343
"text": {
4444
"type": "mrkdwn",
@@ -53,9 +53,11 @@ def show_datepicker(event, say):
5353
"text": "Select a date"
5454
}
5555
}
56-
}]
57-
58-
say(blocks=blocks)
56+
}]
57+
say(
58+
blocks=blocks,
59+
text="Pick a date for me to remind you"
60+
)
5961
```
6062

6163
</details>

docs/_basic/web_api.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def say_hello(client, message):
1818
# Unix Epoch time for September 30, 2020 11:59:59 PM
1919
when_september_ends = 1601510399
2020
channel_id = message["channel"]
21-
client.chat_scheduleMessage(channel=channel_id,
22-
post_at=when_september_ends,
23-
text="Summer has come and passed")
21+
client.chat_scheduleMessage(
22+
channel=channel_id,
23+
post_at=when_september_ends,
24+
text="Summer has come and passed"
25+
)
2426
```

docs/assets/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ span.beta {
241241
pre {
242242
background-color: var(--light-grey) !important;
243243
background-image: none;
244-
padding: 2em;
244+
padding: 1.5em;
245245
border: 1px solid #DDDDDD;
246246
}
247247

0 commit comments

Comments
 (0)