|
18 | 18 | Section, |
19 | 19 | UsersSelect, |
20 | 20 | ) |
21 | | -from slack_bolt import Ack, BoltContext, Respond |
| 21 | +from slack_bolt import Ack, BoltContext, Respond, BoltRequest |
22 | 22 | from slack_sdk.errors import SlackApiError |
23 | 23 | from slack_sdk.web.client import WebClient |
24 | 24 | from sqlalchemy.exc import IntegrityError |
|
100 | 100 | shortcut_context_middleware, |
101 | 101 | subject_middleware, |
102 | 102 | user_middleware, |
| 103 | + is_bot, |
103 | 104 | ) |
104 | 105 | from dispatch.plugins.dispatch_slack.modals.common import send_success_modal |
105 | 106 | from dispatch.plugins.dispatch_slack.models import ( |
@@ -1379,6 +1380,35 @@ def handle_case_after_hours_message( |
1379 | 1380 | ) |
1380 | 1381 |
|
1381 | 1382 |
|
| 1383 | +@message_dispatcher.add(subject=CaseSubjects.case) |
| 1384 | +def handle_thread_creation( |
| 1385 | + ack: Ack, |
| 1386 | + client: WebClient, |
| 1387 | + payload: dict, |
| 1388 | + db_session: Session, |
| 1389 | + context: BoltContext, |
| 1390 | + request: BoltRequest, |
| 1391 | +) -> None: |
| 1392 | + """Sends the user an ephemeral message if they use threads in a dedicated case channel.""" |
| 1393 | + ack() |
| 1394 | + |
| 1395 | + if not context["config"].ban_threads: |
| 1396 | + return |
| 1397 | + |
| 1398 | + case = case_service.get(db_session=db_session, case_id=context["subject"].id) |
| 1399 | + if not case.dedicated_channel: |
| 1400 | + return |
| 1401 | + |
| 1402 | + if payload.get("thread_ts") and not is_bot(request): |
| 1403 | + message = "Please refrain from using threads in case channels. Threads make it harder for case participants to maintain context." |
| 1404 | + client.chat_postEphemeral( |
| 1405 | + text=message, |
| 1406 | + channel=payload["channel"], |
| 1407 | + thread_ts=payload["thread_ts"], |
| 1408 | + user=payload["user"], |
| 1409 | + ) |
| 1410 | + |
| 1411 | + |
1382 | 1412 | @app.action("button-link") |
1383 | 1413 | def ack_button_link(ack: Ack): |
1384 | 1414 | """Handles noop button link action.""" |
|
0 commit comments