28
28
from camel .utils import dependencies_required
29
29
30
30
if TYPE_CHECKING :
31
+ from slack_bolt .app .async_app import AsyncApp
31
32
from slack_bolt .context .async_context import AsyncBoltContext
32
33
from slack_bolt .context .say .async_say import AsyncSay
33
34
from slack_sdk .web .async_client import AsyncWebClient
@@ -40,7 +41,7 @@ class SlackApp:
40
41
r"""Represents a Slack app that is powered by a Slack Bolt `AsyncApp`.
41
42
This class is responsible for initializing and managing the Slack
42
43
application by setting up event handlers, running the app server, runting
43
- socket mode client, and handling events such as messages and mentions
44
+ socket mode client, and handling events such as messages and mentions
44
45
from Slack.
45
46
"""
46
47
@@ -64,20 +65,23 @@ def __init__(
64
65
Args:
65
66
oauth_token (str): Slack API token for authentication.
66
67
app_token (str, optional): Slack app token for authentication.
68
+ (default: :obj:`None`)
67
69
scopes (str, optional): Slack app scopes for permissions.
70
+ (default: :obj:`None`)
68
71
signing_secret (str, optional): Signing secret for verifying Slack
69
- requests.
70
- client_id (str, optional): Slack app client ID.
72
+ requests. (default: :obj:`None`)
73
+ client_id (str, optional): Slack app client ID. (default: :obj:`None`)
71
74
client_secret (str, optional): Slack app client secret.
72
- redirect_uri_path (str, optional): The URI path for OAuth redirect.
73
- (default: :str:"/slack/oauth_redirect")
75
+ (default: :obj:`None`)
76
+ redirect_uri_path (str, optional): The URI path for OAuth redirect.
77
+ (default: :str:`/slack/oauth_redirect`)
74
78
installation_store (AsyncInstallationStore, optional): The installation
75
- store for handling OAuth installations.
79
+ store for handling OAuth installations. (default: :obj:`None`)
76
80
socket_mode (bool): A flag to enable socket mode for the Slack app
77
- (default: :bool:False).
81
+ (default: :bool:` False` ).
78
82
oauth_mode (bool): A flag to enable OAuth mode for the Slack app
79
- (default: :bool:False).
80
-
83
+ (default: :bool:` False` ).
84
+
81
85
Raises:
82
86
ValueError: If the `SLACK_OAUTH_TOKEN` and other required
83
87
parameters are not provided.
@@ -140,18 +144,19 @@ def _initialize_app(
140
144
self ,
141
145
installation_store : Optional [AsyncInstallationStore ] = None ,
142
146
redirect_uri_path : str = "/slack/oauth_redirect" ,
143
- ) -> Any :
147
+ ) -> 'AsyncApp' :
144
148
r"""Initializes the Slack Bolt app with the given installation store
145
149
and OAuth settings.
146
150
147
151
Args:
148
152
installation_store (AsyncInstallationStore, optional): The
149
153
installation store for handling OAuth installations.
154
+ (default: :obj:`None`)
150
155
redirect_uri_path (str): The URI path for handling OAuth redirects
151
- (default: :str:" /slack/oauth_redirect" ).
156
+ (default: :str:` /slack/oauth_redirect` ).
152
157
153
158
Returns:
154
- Any : The initialized Slack Bolt app.
159
+ AsyncApp : The initialized Slack Bolt app.
155
160
"""
156
161
from slack_bolt .app .async_app import AsyncApp
157
162
from slack_bolt .oauth .async_oauth_settings import AsyncOAuthSettings
@@ -176,7 +181,7 @@ def _initialize_app(
176
181
token = self .oauth_token ,
177
182
)
178
183
179
- def setup_handlers (self ) -> None :
184
+ def setup_handlers (self ):
180
185
r"""Sets up the event handlers for Slack events, such as `app_mention`
181
186
and `message`.
182
187
@@ -186,7 +191,7 @@ def setup_handlers(self) -> None:
186
191
self ._app .event ("app_mention" )(self .app_mention )
187
192
self ._app .event ("message" )(self .on_message )
188
193
189
- async def start (self ) -> None :
194
+ async def start (self ):
190
195
r"""Starts the Slack Bolt app asynchronously."""
191
196
from slack_bolt .adapter .socket_mode .async_handler import (
192
197
AsyncSocketModeHandler ,
@@ -211,16 +216,17 @@ def run(
211
216
port : int = 3000 ,
212
217
path : str = "/slack/events" ,
213
218
host : Optional [str ] = None ,
214
- ) -> None :
219
+ ):
215
220
r"""Starts the Slack Bolt app server to listen for incoming Slack
216
221
events.
217
222
218
223
Args:
219
224
port (int): The port on which the server should run.
220
- (default: :int:3000).
225
+ (default: :int:` 3000` ).
221
226
path (str): The endpoint path for receiving Slack events.
222
- (default: :str:/slack/events).
227
+ (default: :str:` /slack/events` ).
223
228
host (str, optional): The hostname to bind the server.
229
+ (default: :obj:`None`)
224
230
"""
225
231
self ._app .start (port = port , path = path , host = host )
226
232
@@ -231,7 +237,7 @@ async def app_mention(
231
237
event : Dict [str , Any ],
232
238
body : Dict [str , Any ],
233
239
say : "AsyncSay" ,
234
- ) -> None :
240
+ ):
235
241
r"""Event handler for `app_mention` events.
236
242
237
243
This method is triggered when someone mentions the app in Slack.
@@ -272,7 +278,7 @@ async def on_message(
272
278
event : Dict [str , Any ],
273
279
body : Dict [str , Any ],
274
280
say : "AsyncSay" ,
275
- ) -> None :
281
+ ):
276
282
r"""Event handler for `message` events.
277
283
278
284
This method is triggered when the app receives a message in Slack.
@@ -325,7 +331,7 @@ def mention_me(
325
331
mention = f"<@{ bot_user_id } >"
326
332
return mention in message
327
333
328
- async def stop (self ) -> None :
334
+ async def stop (self ):
329
335
r"""Stops the Slack Bolt app asynchronously."""
330
336
from slack_bolt .adapter .socket_mode .async_handler import (
331
337
AsyncSocketModeHandler ,
@@ -373,11 +379,11 @@ def set_custom_handler(
373
379
handler function should accept two arguments: the event profile
374
380
and the event body and return the response message or a tuple
375
381
containing the response message and the thread_ts.
376
- message_type (Optional[str]): The specific message type to handle
377
- (e.g., 'mention', 'message', etc.).
378
- Defaults to 'default' if not specified.
382
+ message_type (str, optional): The specific message type to handle
383
+ (e.g., 'mention', 'message', etc.). (default: :str:`default`)
379
384
380
- Returns: None
385
+ Returns:
386
+ None
381
387
"""
382
388
message_type = message_type or 'default'
383
389
self ._custom_handlers [message_type ] = handler
0 commit comments