Skip to content

Commit 0bd7aad

Browse files
committed
Rename handlers for clarity
1 parent 4789dd9 commit 0bd7aad

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _conversation_key_and_root(event):
9090
# ================================================================
9191

9292

93-
def app_mention_handler(event, ack, body, client):
93+
def mention_handler(event, ack, body, client):
9494
"""
9595
Channel interactions that mention the bot.
9696
- If text after the mention starts with 'feedback:', store it as additional feedback.
@@ -179,9 +179,9 @@ def dm_message_handler(event, event_id, client):
179179
_trigger_async_processing({"event": event, "event_id": event_id, "bot_token": bot_token})
180180

181181

182-
def channel_message_handler(event, event_id, client):
182+
def thread_message_handler(event, event_id, client):
183183
"""
184-
Channel messages:
184+
Thread messages:
185185
- Ignore top-level messages (policy: require @mention to start).
186186
- For replies inside a thread the bot owns (session exists):
187187
* 'feedback:' prefix -> store additional feedback.
@@ -250,7 +250,7 @@ def unified_message_handler(event, ack, body, client):
250250
dm_message_handler(event, event_id, client)
251251
else:
252252
# Channel message handling
253-
channel_message_handler(event, event_id, client)
253+
thread_message_handler(event, event_id, client)
254254

255255

256256
def feedback_handler(ack, body, client):
@@ -313,7 +313,7 @@ def feedback_handler(ack, body, client):
313313

314314
def setup_handlers(app):
315315
"""Register handlers. Intentionally minimal—no branching here."""
316-
app.event("app_mention")(app_mention_handler)
316+
app.event("app_mention")(mention_handler)
317317
app.event("message")(unified_message_handler)
318318
app.action("feedback_yes")(feedback_handler)
319319
app.action("feedback_no")(feedback_handler)

packages/slackBotFunction/tests/test_slack_handlers.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def decorator(func):
345345

346346
def test_app_mention_feedback_error_handling(mock_env):
347347
"""Test app mention feedback error handling"""
348-
from app.slack.slack_handlers import app_mention_handler
348+
from app.slack.slack_handlers import mention_handler
349349

350350
mock_ack = Mock()
351351
mock_client = Mock()
@@ -354,7 +354,7 @@ def test_app_mention_feedback_error_handling(mock_env):
354354

355355
with patch("app.slack.slack_handlers.store_feedback") as mock_store:
356356
mock_store.side_effect = Exception("Storage failed")
357-
app_mention_handler(mock_event, mock_ack, mock_body, mock_client)
357+
mention_handler(mock_event, mock_ack, mock_body, mock_client)
358358
# Should still try to post message
359359
mock_client.chat_postMessage.assert_called_once()
360360

@@ -363,7 +363,7 @@ def test_app_mention_feedback_error_handling(mock_env):
363363
mock_client.chat_postMessage.side_effect = Exception("Post failed")
364364

365365
with patch("app.slack.slack_handlers.store_feedback"):
366-
app_mention_handler(mock_event, mock_ack, mock_body, mock_client)
366+
mention_handler(mock_event, mock_ack, mock_body, mock_client)
367367
# Should not raise exception
368368

369369

@@ -380,17 +380,17 @@ def test_dm_message_handler_feedback_error_handling(mock_env):
380380
mock_client.chat_postMessage.assert_called_once()
381381

382382

383-
def test_channel_message_handler_session_check_error(mock_env):
384-
"""Test channel_message_handler session check error"""
385-
from app.slack.slack_handlers import channel_message_handler
383+
def test_thread_message_handler_session_check_error(mock_env):
384+
"""Test thread_message_handler session check error"""
385+
from app.slack.slack_handlers import thread_message_handler
386386

387387
mock_client = Mock()
388388
mock_event = {"text": "follow up", "channel": "C789", "thread_ts": "123", "user": "U456"}
389389

390390
with patch("app.core.config.table") as mock_table:
391391
mock_table.get_item.side_effect = Exception("DB error")
392392
# Should return early due to error
393-
channel_message_handler(mock_event, "evt123", mock_client)
393+
thread_message_handler(mock_event, "evt123", mock_client)
394394

395395

396396
def test_feedback_handler_unknown_action(mock_env):
@@ -418,29 +418,29 @@ def test_feedback_handler_not_latest_message(mock_env):
418418
mock_ack.assert_called_once()
419419

420420

421-
def test_channel_message_handler_no_session(mock_env):
422-
"""Test channel_message_handler when no session found"""
423-
from app.slack.slack_handlers import channel_message_handler
421+
def test_thread_message_handler_no_session(mock_env):
422+
"""Test thread_message_handler when no session found"""
423+
from app.slack.slack_handlers import thread_message_handler
424424

425425
mock_client = Mock()
426426
mock_event = {"text": "follow up", "channel": "C789", "thread_ts": "123", "user": "U456"}
427427

428428
with patch("app.core.config.table") as mock_table:
429429
mock_table.get_item.return_value = {} # No session
430-
channel_message_handler(mock_event, "evt123", mock_client)
430+
thread_message_handler(mock_event, "evt123", mock_client)
431431

432432

433-
def test_channel_message_handler_feedback_path(mock_env):
434-
"""Test channel_message_handler feedback path"""
435-
from app.slack.slack_handlers import channel_message_handler
433+
def test_thread_message_handler_feedback_path(mock_env):
434+
"""Test thread_message_handler feedback path"""
435+
from app.slack.slack_handlers import thread_message_handler
436436

437437
mock_client = Mock()
438438
mock_event = {"text": "feedback: channel feedback", "channel": "C789", "thread_ts": "123", "user": "U456"}
439439

440440
with patch("app.core.config.table") as mock_table:
441441
mock_table.get_item.return_value = {"Item": {"session_id": "session123"}}
442442
# Just test that the function runs without error
443-
channel_message_handler(mock_event, "evt123", mock_client)
443+
thread_message_handler(mock_event, "evt123", mock_client)
444444

445445

446446
def test_dm_message_handler_normal_message(mock_env):
@@ -455,9 +455,9 @@ def test_dm_message_handler_normal_message(mock_env):
455455
mock_trigger.assert_called_once()
456456

457457

458-
def test_app_mention_handler_normal_mention(mock_env):
459-
"""Test app_mention_handler with normal mention"""
460-
from app.slack.slack_handlers import app_mention_handler
458+
def test_mention_handler_normal_mention(mock_env):
459+
"""Test mention_handler with normal mention"""
460+
from app.slack.slack_handlers import mention_handler
461461

462462
mock_ack = Mock()
463463
mock_client = Mock()
@@ -467,7 +467,7 @@ def test_app_mention_handler_normal_mention(mock_env):
467467
with patch("app.slack.slack_handlers._is_duplicate_event", return_value=False), patch(
468468
"app.slack.slack_handlers._trigger_async_processing"
469469
) as mock_trigger:
470-
app_mention_handler(mock_event, mock_ack, mock_body, mock_client)
470+
mention_handler(mock_event, mock_ack, mock_body, mock_client)
471471
mock_trigger.assert_called_once()
472472

473473

0 commit comments

Comments
 (0)