X Tutup
Skip to content

Commit 4958dab

Browse files
misscodedseratch
authored andcommitted
update docs > basics with kaz feedback
1 parent f07628d commit 4958dab

11 files changed

+54
-48
lines changed

docs/_basic/acknowledging_events.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ We recommend calling `ack()` right away before sending a new message or fetching
1616
</div>
1717

1818
```python
19+
import re
20+
1921
# Listen for dialog submissions with a callback_id of ticket_submit
2022
@app.action("ticket_submit")
2123
def process_submission(ack, action):
@@ -31,5 +33,5 @@ def process_submission(ack, action):
3133
"name": "email_address",
3234
"error": "Sorry, this isn’t a valid email"
3335
}]
34-
ack({"errors": errors})
36+
ack(errors=errors)
3537
```

docs/_basic/authenticating_oauth.md

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

2020
```python
21+
from slack_bolt.oauth.oauth_settings import OAuthSettings
22+
from slack_sdk.oauth.installation_store import FileInstallationStore
23+
from slack_sdk.oauth.state_store import FileOAuthStateStore
24+
2125
oauth_settings = OAuthSettings(
2226
client_id=os.environ["SLACK_CLIENT_ID"],
2327
client_secret=os.environ["SLACK_CLIENT_SECRET"],
@@ -38,29 +42,31 @@ app = App(signing_secret=os.environ["SIGNING_SECRET"],
3842
<div class="secondary-content" markdown="0">
3943
You can override the default OAuth using `oauth_settings`, which can be passed in during the initialization of App. You can override the following:
4044

41-
- `authorization_url`: Used to toggle between new Slack Apps and Classic Slack Apps
4245
- `install_path`: Override default path for "Add to Slack" button
4346
- `redirect_uri`: Override default redirect url path
4447
- `callback_options`: Provide custom success and failure pages at the end of the OAuth flow
45-
- `state_store`: Provide a custom state store instead of using the built in `OAuthStateStore`
48+
- `state_store`: Provide a custom state store instead of using the built in `FileOAuthStateStore`
49+
- `installation_store`: Provide a custom installation store instead of the built-in `FileInstallationStore`
4650

4751
</div>
4852

4953
```python
50-
oauth_settings = OAuthSettings(
51-
client_id=os.environ["SLACK_CLIENT_ID"],
52-
client_secret=os.environ["SLACK_CLIENT_SECRET"],
53-
scopes=["channels:read", "groups:read", "chat:write", "incoming-webhook"],
54+
app = App(
55+
signing_secret=os.environ.get("SLACK_SIGNING_SECRET"),
5456
installation_store=FileInstallationStore(),
55-
state_store=FileOAuthStateStore(expiration_seconds=120),
56-
install_path="/slack/install_app",
57-
redirect_uri_path="/slack/redirect",
58-
callback_options=CallbackOptions(success=success_handler,
59-
failure=failure_handler)
57+
oauth_settings=OAuthSettings(
58+
client_id=os.environ.get("SLACK_CLIENT_ID"),
59+
client_secret=os.environ.get("SLACK_CLIENT_SECRET"),
60+
scopes=["app_mentions:read", "channels:history", "im:history", "chat:write"],
61+
user_scopes=[],
62+
redirect_uri=None,
63+
install_path="/slack/install",
64+
redirect_uri_path="/slack/oauth_redirect",
65+
state_store=FileOAuthStateStore(expiration_seconds=600),
66+
callback_options=CallbackOptions(success=success,
67+
failure=failure),
68+
),
6069
)
61-
62-
app = App(signing_secret=os.environ["SIGNING_SECRET"],
63-
oauth_settings=oauth_settings)
6470
```
6571

6672
</details>

docs/_basic/listening_actions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ order: 5
88
<div class="section-content">
99
Your app can listen to user actions like button clicks, and menu selects, using the `action` method.
1010

11-
Actions can be filtered on an `action_id` of type `str` or `RegExp` object. `action_id`s act as unique identifiers for interactive components on the Slack platform.
11+
Actions can be filtered on an `action_id` of type `str` or `re.Pattern`. `action_id`s act as unique identifiers for interactive components on the Slack platform.
1212

1313
You’ll notice in all `action()` examples, `ack()` is used. It is required to call the `ack()` function within an action listener to acknowledge that the event was received from Slack. This is discussed in the [acknowledging events section](#acknowledge).
1414

@@ -29,18 +29,18 @@ def update_message(ack):
2929

3030
<div class="secondary-content" markdown="0">
3131

32-
You can use a constraints object to listen to `callback_id`s, `block_id`s, and `action_id`s (or any combination of them). Constraints in the object can be of type `str` or `RegExp` object.
32+
You can use a constraints object to listen to `callback_id`s, `block_id`s, and `action_id`s (or any combination of them). Constraints in the object can be of type `str` or `re.Pattern`.
3333

3434
</div>
3535

3636
```python
3737
# Your function will only be called when the action_id matches 'select_user' AND the block_id matches 'assign_ticket'
3838
@app.action({"action_id": "select_user", "block_id": "assign_ticket"})
39-
def update_message(ack, action, client):
39+
def update_message(ack, action, body, client):
4040
ack()
4141
client.reactions_add(name='white_check_mark',
42-
timestamp=action['ts'],
43-
channel=action['channel'])
42+
timestamp=action['action_ts'],
43+
channel=body['channel']['id'])
4444
```
4545

4646
</details>

docs/_basic/listening_events.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ The `event()` method requires an `eventType` of type `str`.
1616
```python
1717
# When a user joins the team, send a message in a predefined channel asking them to introduce themselves
1818
@app.event("team_join")
19-
def ask_for_introduction(payload, say):
19+
def ask_for_introduction(event, say):
2020
welcome_channel_id = "C12345";
21-
user_id = payload["event"]["user"]
21+
user_id = event["user"]["id"]
2222
text = f"Welcome to the team, <@{user_id}>! 🎉 You can introduce yourself in this channel."
2323
say(text=text, channel=welcome_channel_id)
2424
```
@@ -39,8 +39,7 @@ You can filter on subtypes of events by passing in the additional key `subtype`.
3939
```python
4040
# Matches all messages from bot users
4141
@app.message({"subtype": "message_changed"})
42-
def log_message_change(logger, payload):
43-
message = payload["event"]
42+
def log_message_change(logger, message):
4443
logger.info(f"The user {message['user']} changed the message to {message['text']}")
4544
```
4645

docs/_basic/listening_messages.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ To listen to messages that [your app has access to receive](https://api.slack.co
1616
```python
1717
# This will match any message that contains 👋
1818
@app.message(":wave:")
19-
def say_hello(payload, say):
20-
user = payload['event']['user']
19+
def say_hello(message, say):
20+
user = message['user']
2121
say(f"Hi there, <@{user}>!")
2222
```
2323

@@ -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-
# RegExp matches are inside of context.matches
38+
# RegEx 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ order: 12
77

88
<div class="section-content">
99

10-
If a <a href="https://api.slack.com/reference/block-kit/views">view payload</a> contains any input blocks, you must listen to `view_submission` events to receive their values. To listen to `view_submission` events, you can use the built-in `view()` method. `view()` requires a `callback_id` of type `str` or `RegExp`.
10+
If a <a href="https://api.slack.com/reference/block-kit/views">view payload</a> contains any input blocks, you must listen to `view_submission` events to receive their values. To listen to `view_submission` events, you can use the built-in `view()` method. `view()` requires a `callback_id` of type `str` or `re.Pattern`.
1111

1212
You can access the value of the `input` blocks by accessing the `state` object. `state` contains a `values` object that uses the `block_id` and unique `action_id` to store the input values.
1313

docs/_basic/listening_responding_options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ def show_options(ack):
3030
},
3131
]
3232

33-
ack({"options": options})
33+
ack(options=options)
3434
```

docs/_basic/listening_responding_shortcuts.md

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

1010
The `shortcut()` method supports both [global shortcuts](https://api.slack.com/interactivity/shortcuts/using#global_shortcuts) and [message shortcuts](https://api.slack.com/interactivity/shortcuts/using#message_shortcuts).
1111

12-
Shortcuts are invokable entry points to apps. Global shortcuts are available from within search in Slack. Message shortcuts are available in the context menus of messages. Your app can use the `shortcut()` method to listen to incoming shortcut events. The method requires a `callback_id` parameter of type `str` or `RegExp`.
12+
Shortcuts are invokable entry points to apps. Global shortcuts are available from within search in Slack. Message shortcuts are available in the context menus of messages. Your app can use the `shortcut()` method to listen to incoming shortcut events. The method requires a `callback_id` parameter of type `str` or `re.Pattern`.
1313

1414
Shortcuts must be acknowledged with `ack()` to inform Slack that your app has received the event.
1515

@@ -25,12 +25,12 @@ When configuring shortcuts within your app configuration, you'll continue to app
2525

2626
# The open_modal shortcut opens a plain old modal
2727
@app.shortcut("open_modal")
28-
def open_modal(ack, client):
28+
def open_modal(ack, shortcut, client):
2929
# Acknowledge the shortcut request
3030
ack()
3131
# Call the views_open method using one of the built-in WebClients
3232
client.views_open(
33-
trigger_id=payload["trigger_id"],
33+
trigger_id=shortcut["trigger_id"],
3434
view={
3535
"type": "modal",
3636
"title": {
@@ -69,19 +69,19 @@ def open_modal(ack, client):
6969
</summary>
7070

7171
<div class="secondary-content" markdown="0">
72-
You can use a constraints object to listen to `callback_id`s, and `type`s. Constraints in the object can be of type `str` or `RegExp` object.
72+
You can use a constraints object to listen to `callback_id`s, and `type`s. Constraints in the object can be of type `str` or `re.Pattern`.
7373
</div>
7474

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.shortcut({"callback_id": "open_modal", "type": "message_action"})
79-
def open_modal(ack, client):
80-
# acknowledge the shortcut request
78+
@app.message_shortcut("open_modal")
79+
def open_modal(ack, shortcut, client):
80+
# Acknowledge the shortcut request
8181
ack()
82-
# call the views_open method using one of the built-in WebClients
82+
# Call the views_open method using one of the built-in WebClients
8383
client.views_open(
84-
trigger_id=payload["trigger_id"],
84+
trigger_id=shortcut["trigger_id"],
8585
view={
8686
"type": "modal",
8787
"title": {

docs/_basic/opening_modals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Read more about modal composition in the <a href="https://api.slack.com/surfaces
1717
```python
1818
# Listen for a slash command invocation
1919
@app.command("/ticket")
20-
def open_modal(ack, payload, client):
20+
def open_modal(ack, body, client):
2121
# Acknowledge the command request
2222
ack();
2323

2424
# Call views_open with the built-in client
2525
client.views_open({
2626
# Pass a valid trigger_id within 3 seconds of receiving it
27-
trigger_id=payload["trigger_id"],
27+
trigger_id=body["trigger_id"],
2828
# View payload
2929
view={
3030
"type": "modal",

docs/_basic/sending_messages.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ In the case that you’d like to send a message outside of a listener or you wan
1616
```python
1717
# Listens for messages containing "knock knock" and responds with an italicized "who's there?"
1818
@app.message("knock knock")
19-
def ask_who(logger, payload, say):
19+
def ask_who(message, say):
2020
say("_Who's there?_")
2121
```
2222

@@ -35,8 +35,8 @@ To explore adding rich message layouts to your app, read through [the guide on o
3535
```python
3636
# Sends a section block with datepicker when someone reacts with a 📅 emoji
3737
@app.event("reaction_added")
38-
def show_datepicker(logger, payload, say):
39-
reaction = payload["event"]["reaction"]
38+
def show_datepicker(event, say):
39+
reaction = event["reaction"]
4040
if reaction == "calendar":
4141
blocks = [{
4242
"type": "section",
@@ -55,8 +55,7 @@ def show_datepicker(logger, payload, say):
5555
}
5656
}]
5757

58-
channel_id = payload["event"]["item"]["channel"]
59-
say(blocks=blocks, channel=channel_id)
58+
say(blocks=blocks)
6059
```
6160

6261
</details>

0 commit comments

Comments
 (0)
X Tutup