Skip to content

Commit be68283

Browse files
committed
more types
1 parent 9d34500 commit be68283

File tree

6 files changed

+28
-29
lines changed

6 files changed

+28
-29
lines changed

packages/slackBotFunction/app/handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def handler(event: dict, context: LambdaContext) -> dict:
3535
logger.error("Async processing requested but no slack_event provided")
3636
return {"statusCode": 400}
3737

38-
process_async_slack_event(slack_event_data)
38+
process_async_slack_event(slack_event_data=slack_event_data)
3939
return {"statusCode": 200}
4040

4141
# handle async processing requests
@@ -45,9 +45,9 @@ def handler(event: dict, context: LambdaContext) -> dict:
4545
logger.error("Async processing requested but no slack_event provided")
4646
return {"statusCode": 400}
4747

48-
process_pull_request_slack_event(slack_event_data)
48+
process_pull_request_slack_event(slack_event_data=slack_event_data)
4949
return {"statusCode": 200}
5050

5151
# handle Slack webhook requests
5252
slack_handler = SlackRequestHandler(app=app)
53-
return slack_handler.handle(event, context)
53+
return slack_handler.handle(event=event, context=context)

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def store_feedback(
333333

334334
# Get latest bot message timestamp for feedback linking
335335
if not message_ts:
336-
message_ts = get_latest_message_ts(conversation_key)
336+
message_ts = get_latest_message_ts(conversation_key=conversation_key)
337337

338338
if message_ts and feedback_type in ["positive", "negative"]:
339339
# Per-message feedback with deduplication for button votes only
@@ -375,7 +375,7 @@ def store_feedback(
375375

376376
# Mark Q&A as having received feedback to prevent deletion
377377
if message_ts:
378-
_mark_qa_feedback_received(conversation_key, message_ts)
378+
_mark_qa_feedback_received(conversation_key=conversation_key, message_ts=message_ts)
379379

380380
logger.info(
381381
"Stored feedback",
@@ -403,7 +403,7 @@ def get_conversation_session(conversation_key: str) -> str | None:
403403
"""
404404
Get existing Bedrock session for this conversation
405405
"""
406-
session_data = get_conversation_session_data(conversation_key)
406+
session_data = get_conversation_session_data(conversation_key=conversation_key)
407407
return session_data.get("session_id") if session_data else None
408408

409409

@@ -412,7 +412,7 @@ def get_conversation_session_data(conversation_key: str) -> Dict[str, Any]:
412412
Get full session data for this conversation
413413
"""
414414
try:
415-
response = get_state_information({"pk": conversation_key, "sk": "session"})
415+
response = get_state_information(key={"pk": conversation_key, "sk": "session"})
416416
if "Item" in response:
417417
logger.info("Found existing session", extra={"conversation_key": conversation_key})
418418
return response["Item"]
@@ -427,7 +427,7 @@ def get_latest_message_ts(conversation_key: str) -> str | None:
427427
Get latest message timestamp from session
428428
"""
429429
try:
430-
response = get_state_information({"pk": conversation_key, "sk": constants.SESSION_SK})
430+
response = get_state_information(key={"pk": conversation_key, "sk": constants.SESSION_SK})
431431
if "Item" in response:
432432
return response["Item"].get("latest_message_ts")
433433
return None
@@ -477,9 +477,9 @@ def update_session_latest_message(conversation_key: str, message_ts: str) -> Non
477477
"""
478478
try:
479479
update_state_information(
480-
{"pk": conversation_key, "sk": constants.SESSION_SK},
481-
"SET latest_message_ts = :ts",
482-
{":ts": message_ts},
480+
key={"pk": conversation_key, "sk": constants.SESSION_SK},
481+
update_expression="SET latest_message_ts = :ts",
482+
expression_attribute_values={":ts": message_ts},
483483
)
484484
except Exception:
485485
logger.error("Error updating session latest message", extra={"error": traceback.format_exc()})

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from slack_sdk import WebClient
1717
from app.core.config import (
1818
BOT_MESSAGES,
19-
get_bot_token,
2019
get_logger,
2120
constants,
2221
)
@@ -60,18 +59,17 @@ def mention_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any], clien
6059
- If text after the mention starts with 'feedback:', store it as additional feedback.
6160
- Otherwise, forward to the async processing pipeline (Q&A).
6261
"""
63-
bot_token = get_bot_token()
6462
logger.debug("Sending ack response in mention_handler")
6563
ack()
66-
respond_with_eyes(bot_token, event)
67-
event_id = gate_common(event, body)
64+
respond_with_eyes(event=event)
65+
event_id = gate_common(event=event, body=body)
6866
if not event_id:
6967
return
7068
original_message_text = (event.get("text") or "").strip()
7169
user_id = event.get("user", "unknown")
72-
conversation_key, thread_root = conversation_key_and_root(event)
70+
conversation_key, thread_root = conversation_key_and_root(event=event)
7371

74-
message_text = strip_mentions(original_message_text)
72+
message_text = strip_mentions(message_text=original_message_text)
7573
logger.info(f"Processing @mention from user {user_id}", extra={"event_id": event_id})
7674
_common_message_handler(
7775
message_text=message_text,
@@ -94,7 +92,7 @@ def dm_message_handler(event: Dict[str, Any], event_id: str, client: WebClient,
9492
return # not a DM; the channel handler will evaluate it
9593
message_text = (event.get("text") or "").strip()
9694
user_id = event.get("user", "unknown")
97-
conversation_key, thread_root = conversation_key_and_root(event)
95+
conversation_key, thread_root = conversation_key_and_root(event=event)
9896
logger.info(f"Processing DM from user {user_id}", extra={"event_id": event_id})
9997
_common_message_handler(
10098
message_text=message_text,
@@ -127,7 +125,7 @@ def thread_message_handler(event: Dict[str, Any], event_id: str, client: WebClie
127125

128126
conversation_key = f"{constants.THREAD_PREFIX}{channel_id}#{thread_root}"
129127
try:
130-
resp = get_state_information({"pk": conversation_key, "sk": constants.SESSION_SK})
128+
resp = get_state_information(key={"pk": conversation_key, "sk": constants.SESSION_SK})
131129
if "Item" not in resp:
132130
logger.info(f"No session found for thread: {conversation_key}")
133131
return # not a bot-owned thread; ignore
@@ -152,9 +150,8 @@ def unified_message_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any
152150
"""Handle all message events - DMs and channel messages"""
153151
logger.debug("Sending ack response")
154152
ack()
155-
bot_token = get_bot_token()
156-
respond_with_eyes(bot_token, event)
157-
event_id = gate_common(event, body)
153+
respond_with_eyes(event=event)
154+
event_id = gate_common(event=event, body=body)
158155
if not event_id:
159156
return
160157

@@ -179,7 +176,7 @@ def feedback_handler(ack: Ack, body: Dict[str, Any], client: WebClient) -> None:
179176
conversation_key = feedback_data["ck"]
180177
message_ts = feedback_data.get("mt")
181178

182-
if message_ts and not is_latest_message(conversation_key, message_ts):
179+
if message_ts and not is_latest_message(conversation_key=conversation_key, message_ts=message_ts):
183180
logger.info(f"Feedback ignored - not latest message: {message_ts}")
184181
return
185182

packages/slackBotFunction/app/utils/handler_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from app.services.dynamo import get_state_information, store_state_information
1818
from app.core.config import (
19+
get_bot_token,
1920
get_logger,
2021
constants,
2122
)
@@ -67,7 +68,8 @@ def trigger_async_processing(event: Dict[str, Any], event_id: str) -> None:
6768
logger.error("Failed to trigger async processing", extra={"error": traceback.format_exc()})
6869

6970

70-
def respond_with_eyes(bot_token: str, event: Dict[str, Any]) -> None:
71+
def respond_with_eyes(event: Dict[str, Any]) -> None:
72+
bot_token = get_bot_token()
7173
client = WebClient(token=bot_token)
7274
channel = event["channel"]
7375
ts = event["ts"]
@@ -137,9 +139,9 @@ def gate_common(event: Dict[str, Any], body: Dict[str, Any]) -> str | None:
137139
return event_id
138140

139141

140-
def strip_mentions(text: str) -> str:
142+
def strip_mentions(message_text: str) -> str:
141143
"""Remove Slack user mentions like <@U123> or <@U123|alias> from text."""
142-
return re.sub(r"<@[UW][A-Z0-9]+(\|[^>]+)?>", "", text or "").strip()
144+
return re.sub(r"<@[UW][A-Z0-9]+(\|[^>]+)?>", "", message_text or "").strip()
143145

144146

145147
def extract_pull_request_id(text: str) -> str:

packages/slackBotFunction/tests/test_handler_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_respond_with_eyes_on_success(mock_webclient: Mock, mock_env: Mock):
230230

231231
# perform operation
232232
event = {"channel": "D123", "ts": "456", "channel_type": "im"}
233-
respond_with_eyes("dummy_token", event)
233+
respond_with_eyes(event)
234234

235235
# assertions
236236
# just need to make sure it does not error
@@ -251,7 +251,7 @@ def test_respond_with_eyes_on_failure(mock_webclient: Mock, mock_env: Mock):
251251

252252
# perform operation
253253
event = {"channel": "D123", "ts": "456", "channel_type": "im"}
254-
respond_with_eyes("dummy_token", event)
254+
respond_with_eyes(event)
255255

256256
# assertions
257257
# just need to make sure it does not error

packages/slackBotFunction/tests/test_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_handler_normal_event(
2222
result = handler(event, lambda_context)
2323

2424
# assertions
25-
mock_handler.handle.assert_called_once_with(event, lambda_context)
25+
mock_handler.handle.assert_called_once_with(event=event, context=lambda_context)
2626
assert result["statusCode"] == 200
2727

2828

0 commit comments

Comments
 (0)