Skip to content

Commit eecb605

Browse files
committed
even more typing
1 parent 401010a commit eecb605

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

packages/slackBotFunction/app/services/bedrock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from typing import Any
23
import boto3
34
from mypy_boto3_bedrock_agent_runtime import AgentsforBedrockRuntimeClient
45
from mypy_boto3_bedrock_runtime.client import BedrockRuntimeClient
@@ -55,7 +56,7 @@ def query_bedrock(user_query: str, session_id: str = None) -> RetrieveAndGenerat
5556
return response
5657

5758

58-
def invoke_model(prompt: str, model_id: str, client: BedrockRuntimeClient):
59+
def invoke_model(prompt: str, model_id: str, client: BedrockRuntimeClient) -> dict[str, Any]:
5960
response = client.invoke_model(
6061
modelId=model_id,
6162
body=json.dumps(

packages/slackBotFunction/app/services/dynamo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_state_information(key: str) -> GetItemOutputTableTypeDef:
2929
return results
3030

3131

32-
def store_state_information(item: dict[str, Any], condition: str = None):
32+
def store_state_information(item: dict[str, Any], condition: str = None) -> None:
3333
start_time = time()
3434
table = get_slack_bot_state_table()
3535
is_success = True
@@ -54,7 +54,7 @@ def store_state_information(item: dict[str, Any], condition: str = None):
5454
)
5555

5656

57-
def update_state_information(key: str, update_expression: str, expression_attribute_values: dict[str, Any]):
57+
def update_state_information(key: str, update_expression: str, expression_attribute_values: dict[str, Any]) -> None:
5858
start_time = time()
5959
table = get_slack_bot_state_table()
6060
is_success = True
@@ -78,7 +78,7 @@ def update_state_information(key: str, update_expression: str, expression_attrib
7878
)
7979

8080

81-
def delete_state_information(pk: str, sk: str, condition: str):
81+
def delete_state_information(pk: str, sk: str, condition: str) -> None:
8282
start_time = time()
8383
table = get_slack_bot_state_table()
8484
is_success = True

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
# ================================================================
3535

3636

37-
def cleanup_previous_unfeedback_qa(conversation_key: str, current_message_ts: str, session_data: Dict[str, Any]):
37+
def cleanup_previous_unfeedback_qa(
38+
conversation_key: str, current_message_ts: str, session_data: Dict[str, Any]
39+
) -> None:
3840
"""Delete previous Q&A pair if no feedback received using atomic operation"""
3941
try:
4042
previous_message_ts = session_data.get("latest_message_ts")
@@ -59,7 +61,7 @@ def cleanup_previous_unfeedback_qa(conversation_key: str, current_message_ts: st
5961

6062
def store_qa_pair(
6163
conversation_key: str, user_query: str, bot_response: str, message_ts: str, session_id: str, user_id: str
62-
):
64+
) -> None:
6365
"""
6466
Store Q&A pair for feedback correlation
6567
"""
@@ -81,7 +83,7 @@ def store_qa_pair(
8183
logger.error("Failed to store Q&A pair", extra={"error": traceback.format_exc()})
8284

8385

84-
def _mark_qa_feedback_received(conversation_key: str, message_ts: str):
86+
def _mark_qa_feedback_received(conversation_key: str, message_ts: str) -> None:
8587
"""
8688
Mark Q&A record as having received feedback to prevent deletion
8789
"""
@@ -121,7 +123,7 @@ def _handle_session_management(
121123
thread_ts: str,
122124
context_type: str,
123125
message_ts: str,
124-
):
126+
) -> None:
125127
"""Handle Bedrock session creation and cleanup"""
126128
# Handle conversation session management
127129
if not session_id and "sessionId" in kb_response:
@@ -179,7 +181,7 @@ def _create_feedback_blocks(
179181
# ================================================================
180182

181183

182-
def process_async_slack_event(slack_event_data: Dict[str, Any]):
184+
def process_async_slack_event(slack_event_data: Dict[str, Any]) -> None:
183185
"""
184186
Process Slack events asynchronously after initial acknowledgment
185187
@@ -268,7 +270,7 @@ def process_async_slack_event(slack_event_data: Dict[str, Any]):
268270
logger.error("Failed to post error message", extra={"error": traceback.format_exc()})
269271

270272

271-
def log_query_stats(user_query: str, event: Dict[str, Any], channel: str, client: WebClient, thread_ts: str):
273+
def log_query_stats(user_query: str, event: Dict[str, Any], channel: str, client: WebClient, thread_ts: str) -> None:
272274
query_length = len(user_query)
273275
start_time = float(event["event_ts"])
274276
end_time = time.time()
@@ -301,7 +303,7 @@ def store_feedback(
301303
thread_ts: str = None,
302304
message_ts: str = None,
303305
feedback_text: str = None,
304-
):
306+
) -> None:
305307
"""
306308
Store user feedback with reference to Q&A record
307309
"""
@@ -429,7 +431,7 @@ def store_conversation_session(
429431
channel_id: str,
430432
thread_ts: str = None,
431433
latest_message_ts: str = None,
432-
):
434+
) -> None:
433435
"""
434436
Store new Bedrock session for conversation memory
435437
"""
@@ -457,7 +459,7 @@ def store_conversation_session(
457459
logger.error("Error storing session", extra={"error": traceback.format_exc()})
458460

459461

460-
def update_session_latest_message(conversation_key: str, message_ts: str):
462+
def update_session_latest_message(conversation_key: str, message_ts: str) -> None:
461463
"""
462464
Update session with latest message timestamp
463465
"""

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141

4242
@lru_cache
43-
def setup_handlers(app: App):
43+
def setup_handlers(app: App) -> None:
4444
"""Register handlers. Intentionally minimal—no branching here."""
4545
app.event("app_mention")(mention_handler)
4646
app.event("message")(unified_message_handler)
@@ -53,7 +53,7 @@ def setup_handlers(app: App):
5353
# ================================================================
5454

5555

56-
def mention_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any], client: WebClient):
56+
def mention_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any], client: WebClient) -> None:
5757
"""
5858
Channel interactions that mention the bot.
5959
- If text after the mention starts with 'feedback:', store it as additional feedback.
@@ -84,7 +84,7 @@ def mention_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any], clien
8484
)
8585

8686

87-
def dm_message_handler(event: Dict[str, Any], event_id, client: WebClient, body: Dict[str, Any]):
87+
def dm_message_handler(event: Dict[str, Any], event_id: str, client: WebClient, body: Dict[str, Any]) -> None:
8888
"""
8989
Direct messages:
9090
- 'feedback:' prefix -> store as conversation-scoped additional feedback (no model call).
@@ -108,7 +108,7 @@ def dm_message_handler(event: Dict[str, Any], event_id, client: WebClient, body:
108108
)
109109

110110

111-
def thread_message_handler(event: Dict[str, Any], event_id, client: WebClient, body: Dict[str, Any]):
111+
def thread_message_handler(event: Dict[str, Any], event_id: str, client: WebClient, body: Dict[str, Any]) -> None:
112112
"""
113113
Thread messages:
114114
- Ignore top-level messages (policy: require @mention to start).
@@ -150,7 +150,7 @@ def thread_message_handler(event: Dict[str, Any], event_id, client: WebClient, b
150150
)
151151

152152

153-
def unified_message_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any], client: WebClient):
153+
def unified_message_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any], client: WebClient) -> None:
154154
"""Handle all message events - DMs and channel messages"""
155155
logger.debug("Sending ack response")
156156
ack()
@@ -169,7 +169,7 @@ def unified_message_handler(event: Dict[str, Any], ack: Ack, body: Dict[str, Any
169169
thread_message_handler(event=event, event_id=event_id, client=client, body=body)
170170

171171

172-
def feedback_handler(ack: Ack, body: Dict[str, Any], client: WebClient):
172+
def feedback_handler(ack: Ack, body: Dict[str, Any], client: WebClient) -> None:
173173
"""Handle feedback button clicks (both positive and negative)."""
174174
logger.debug("Sending ack response")
175175
ack()
@@ -234,10 +234,10 @@ def _common_message_handler(
234234
thread_root: str,
235235
client: WebClient,
236236
event: Dict[str, Any],
237-
event_id,
237+
event_id: str,
238238
post_to_thread: bool,
239239
body: Dict[str, Any],
240-
):
240+
) -> None:
241241
channel_id = event["channel"]
242242
user_id = event.get("user", "unknown")
243243
if message_text.lower().startswith(constants.FEEDBACK_PREFIX):

packages/slackBotFunction/app/utils/handler_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def is_duplicate_event(event_id: str) -> bool:
4444
return False
4545

4646

47-
def trigger_async_processing(event: Dict[str, Any], event_id: str):
47+
def trigger_async_processing(event: Dict[str, Any], event_id: str) -> None:
4848
"""
4949
Trigger asynchronous Lambda invocation to process Slack events
5050
@@ -67,7 +67,7 @@ def trigger_async_processing(event: Dict[str, Any], event_id: str):
6767
logger.error("Failed to trigger async processing", extra={"error": traceback.format_exc()})
6868

6969

70-
def respond_with_eyes(bot_token: str, event: Dict[str, Any]):
70+
def respond_with_eyes(bot_token: str, event: Dict[str, Any]) -> None:
7171
client = WebClient(token=bot_token)
7272
channel = event["channel"]
7373
ts = event["ts"]
@@ -78,7 +78,7 @@ def respond_with_eyes(bot_token: str, event: Dict[str, Any]):
7878
logger.warning("Failed to respond with eyes", extra={"error": traceback.format_exc()})
7979

8080

81-
def trigger_pull_request_processing(pull_request_id: str, event: Dict[str, Any], event_id: str):
81+
def trigger_pull_request_processing(pull_request_id: str, event: Dict[str, Any], event_id: str) -> None:
8282
cloudformation_client: CloudFormationClient = boto3.client("cloudformation")
8383
lambda_client: LambdaClient = boto3.client("lambda")
8484
try:

packages/slackBotFunction/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def lambda_context():
4242

4343
@pytest.fixture
4444
def mock_get_parameter():
45-
def fake_get_parameter(name, *args, **kwargs):
45+
def fake_get_parameter(name: str, *args, **kwargs):
4646
return {
4747
"/test/bot-token": json.dumps({"token": "test-token"}),
4848
"/test/signing-secret": json.dumps({"secret": "test-secret"}),

0 commit comments

Comments
 (0)