Skip to content

Commit da6f066

Browse files
committed
respond with eyes
1 parent 1f6f318 commit da6f066

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import lru_cache
66
from slack_bolt import App
77
from app.core.config import get_bot_token, get_logger
8-
from app.utils.handler_utils import is_duplicate_event, trigger_async_processing
8+
from app.utils.handler_utils import is_duplicate_event, trigger_async_processing, respond_with_eyes
99

1010
logger = get_logger()
1111

@@ -30,6 +30,7 @@ def mention_handler(event, ack, body):
3030
logger.info("Processing @mention from user", extra={"user_id": user_id, "event_id": event_id})
3131

3232
bot_token = get_bot_token()
33+
respond_with_eyes(bot_token, event)
3334
trigger_async_processing({"event": event, "event_id": event_id, "bot_token": bot_token})
3435

3536

@@ -53,6 +54,7 @@ def dm_message_handler(event, ack, body):
5354
logger.info("Processing DM from user", extra={"user_id": user_id, "event_id": event_id})
5455

5556
bot_token = get_bot_token()
57+
respond_with_eyes(bot_token, event)
5658
trigger_async_processing({"event": event, "event_id": event_id, "bot_token": bot_token})
5759

5860

packages/slackBotFunction/app/utils/handler_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import traceback
88
import boto3
99
from botocore.exceptions import ClientError
10+
from slack_sdk import WebClient
1011
from app.core.config import get_slack_bot_state_table, get_logger
1112
import os
1213

@@ -54,3 +55,10 @@ def trigger_async_processing(event_data):
5455
logger.info("Async processing triggered successfully")
5556
except Exception:
5657
logger.error("Failed to trigger async processing", extra={"error": traceback.format_exc()})
58+
59+
60+
def respond_with_eyes(bot_token, event):
61+
client = WebClient(token=bot_token)
62+
channel = event["channel"]
63+
ts = event["ts"]
64+
client.reactions_add(channel=channel, timestamp=ts, name="eyes")

packages/slackBotFunction/tests/test_middleware.py

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44

55
@patch("app.utils.handler_utils.is_duplicate_event")
66
@patch("app.utils.handler_utils.trigger_async_processing")
7+
@patch("app.utils.handler_utils.respond_with_eyes")
78
def test_app_mention_handler_execution_simple(
8-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
9+
mock_respond_with_eyes,
10+
mock_trigger_async_processing,
11+
mock_is_duplicate_event,
12+
mock_slack_app,
13+
mock_env,
14+
mock_get_parameter,
15+
lambda_context,
916
):
1017
"""Test app mention handler execution by simulating the handler registration process"""
1118
# Create a mock app that captures the registered handlers
@@ -43,12 +50,20 @@ def decorator(func):
4350
mock_ack.assert_called()
4451
mock_trigger_async_processing.assert_called_once()
4552
mock_is_duplicate_event.assert_called()
53+
mock_respond_with_eyes.assert_called()
4654

4755

4856
@patch("app.utils.handler_utils.is_duplicate_event")
4957
@patch("app.utils.handler_utils.trigger_async_processing")
58+
@patch("app.utils.handler_utils.respond_with_eyes")
5059
def test_direct_message_handler_execution_simple(
51-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
60+
mock_respond_with_eyes,
61+
mock_trigger_async_processing,
62+
mock_is_duplicate_event,
63+
mock_slack_app,
64+
mock_env,
65+
mock_get_parameter,
66+
lambda_context,
5267
):
5368
"""Test direct message handler execution by simulating the handler registration process"""
5469
# Create a mock app that captures the registered handlers
@@ -85,12 +100,20 @@ def decorator(func):
85100
mock_ack.assert_called()
86101
mock_trigger_async_processing.assert_called_once()
87102
mock_is_duplicate_event.assert_called()
103+
mock_respond_with_eyes.assert_called()
88104

89105

90106
@patch("app.utils.handler_utils.is_duplicate_event")
91107
@patch("app.utils.handler_utils.trigger_async_processing")
108+
@patch("app.utils.handler_utils.respond_with_eyes")
92109
def test_app_mention_handler_duplicate_event(
93-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
110+
mock_respond_with_eyes,
111+
mock_trigger_async_processing,
112+
mock_is_duplicate_event,
113+
mock_slack_app,
114+
mock_env,
115+
mock_get_parameter,
116+
lambda_context,
94117
):
95118
"""Test app mention handler with duplicate event"""
96119
registered_handlers = {}
@@ -124,12 +147,20 @@ def decorator(func):
124147
mock_ack.assert_called()
125148
mock_is_duplicate_event.assert_called()
126149
mock_trigger_async_processing.assert_not_called()
150+
mock_respond_with_eyes.assert_not_called()
127151

128152

129153
@patch("app.utils.handler_utils.is_duplicate_event")
130154
@patch("app.utils.handler_utils.trigger_async_processing")
155+
@patch("app.utils.handler_utils.respond_with_eyes")
131156
def test_app_mention_handler_missing_event_id(
132-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
157+
mock_respond_with_eyes,
158+
mock_trigger_async_processing,
159+
mock_is_duplicate_event,
160+
mock_slack_app,
161+
mock_env,
162+
mock_get_parameter,
163+
lambda_context,
133164
):
134165
"""Test app mention handler with missing event ID"""
135166
# Create a mock app that captures the registered handlers
@@ -163,12 +194,20 @@ def decorator(func):
163194
mock_ack.assert_called()
164195
mock_trigger_async_processing.put_item.assert_not_called()
165196
mock_is_duplicate_event.invoke.assert_not_called()
197+
mock_respond_with_eyes.assert_not_called()
166198

167199

168200
@patch("app.utils.handler_utils.is_duplicate_event")
169201
@patch("app.utils.handler_utils.trigger_async_processing")
202+
@patch("app.utils.handler_utils.respond_with_eyes")
170203
def test_direct_message_handler_duplicate_event(
171-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
204+
mock_respond_with_eyes,
205+
mock_trigger_async_processing,
206+
mock_is_duplicate_event,
207+
mock_slack_app,
208+
mock_env,
209+
mock_get_parameter,
210+
lambda_context,
172211
):
173212
"""Test direct message handler with duplicate event"""
174213
registered_handlers = {}
@@ -202,12 +241,20 @@ def decorator(func):
202241
mock_ack.assert_called()
203242
mock_is_duplicate_event.assert_called()
204243
mock_trigger_async_processing.assert_called()
244+
mock_respond_with_eyes.assert_called()
205245

206246

207247
@patch("app.utils.handler_utils.is_duplicate_event")
208248
@patch("app.utils.handler_utils.trigger_async_processing")
249+
@patch("app.utils.handler_utils.respond_with_eyes")
209250
def test_direct_message_handler_missing_event_id(
210-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
251+
mock_respond_with_eyes,
252+
mock_trigger_async_processing,
253+
mock_is_duplicate_event,
254+
mock_slack_app,
255+
mock_env,
256+
mock_get_parameter,
257+
lambda_context,
211258
):
212259
"""Test direct message handler with missing event ID"""
213260
# Create a mock app that captures the registered handlers
@@ -242,12 +289,20 @@ def decorator(func):
242289
# No DynamoDB or Lambda calls should be made
243290
mock_is_duplicate_event.assert_not_called()
244291
mock_trigger_async_processing.assert_not_called()
292+
mock_respond_with_eyes.assert_not_called()
245293

246294

247295
@patch("app.utils.handler_utils.is_duplicate_event")
248296
@patch("app.utils.handler_utils.trigger_async_processing")
297+
@patch("app.utils.handler_utils.respond_with_eyes")
249298
def test_direct_message_handler_non_dm_channel(
250-
mock_trigger_async_processing, mock_is_duplicate_event, mock_slack_app, mock_env, mock_get_parameter, lambda_context
299+
mock_respond_with_eyes,
300+
mock_trigger_async_processing,
301+
mock_is_duplicate_event,
302+
mock_slack_app,
303+
mock_env,
304+
mock_get_parameter,
305+
lambda_context,
251306
):
252307
"""Test direct message handler ignores non-DM channels"""
253308
# Create a mock app that captures the registered handlers
@@ -284,3 +339,4 @@ def decorator(func):
284339
# No DynamoDB or Lambda calls should be made for non-DM messages
285340
mock_is_duplicate_event.assert_not_called()
286341
mock_trigger_async_processing.assert_not_called()
342+
mock_respond_with_eyes.assert_not_called()

0 commit comments

Comments
 (0)