From 2ba92bc7abb9e9ad334036a31f30927749449c1a Mon Sep 17 00:00:00 2001 From: Ale Mercado Date: Mon, 6 Oct 2025 12:02:40 -0400 Subject: [PATCH 1/6] docs: improve readability with docstrings --- listeners/actions/actions.py | 10 +++++++++- listeners/assistant/assistant.py | 24 +++++++++++++++++++++--- listeners/events/app_mentioned.py | 14 ++++++++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/listeners/actions/actions.py b/listeners/actions/actions.py index 8dd151c..be42113 100644 --- a/listeners/actions/actions.py +++ b/listeners/actions/actions.py @@ -1,8 +1,16 @@ import logging -# Handle feedback buttons (thumbs up/down) def handle_feedback(ack, body, client, logger: logging.Logger): + """ + Handles user feedback on AI-generated responses via thumbs up/down buttons. + + Args: + ack: Function to acknowledge the action request + body: Action payload containing feedback details (message, channel, user, action value) + client: Slack WebClient for making API calls + logger: Logger instance for debugging and error tracking + """ try: ack() message_ts = body["message"]["ts"] diff --git a/listeners/assistant/assistant.py b/listeners/assistant/assistant.py index 320d41f..c5ec7b3 100644 --- a/listeners/assistant/assistant.py +++ b/listeners/assistant/assistant.py @@ -14,7 +14,6 @@ assistant = Assistant() -# This listener is invoked when a human user opened an assistant thread @assistant.thread_started def start_assistant_thread( say: Say, @@ -22,6 +21,15 @@ def start_assistant_thread( set_suggested_prompts: SetSuggestedPrompts, logger: logging.Logger, ): + """ + Handle the assistant thread start event by greeting the user and setting suggested prompts. + + Args: + say: Function to send messages to the thread from the app + get_thread_context: Function to retrieve thread context information + set_suggested_prompts: Function to configure suggested prompt options + logger: Logger instance for error tracking + """ try: say("How can I help you?") @@ -65,6 +73,18 @@ def respond_in_assistant_thread( say: Say, set_status: SetStatus, ): + """ + Handles when users send messages or select a prompt in an assistant thread and generate AI responses: + + Args: + client: Slack WebClient for making API calls + context: Bolt context containing channel and thread information + get_thread_context: Function to retrieve thread context (e.g., referred channel) + logger: Logger instance for error tracking + payload: Event payload with message details (channel, user, text, etc.) + say: Function to send messages to the thread + set_status: Function to update the assistant's status + """ try: channel_id = payload["channel"] team_id = payload["team"] @@ -84,8 +104,6 @@ def respond_in_assistant_thread( ) if user_message == "Can you generate a brief summary of the referred channel?": - # the logic here requires the additional bot scopes: - # channels:join, channels:history, groups:history thread_context = get_thread_context() referred_channel_id = thread_context.get("channel_id") try: diff --git a/listeners/events/app_mentioned.py b/listeners/events/app_mentioned.py index ea34c38..7320a5c 100644 --- a/listeners/events/app_mentioned.py +++ b/listeners/events/app_mentioned.py @@ -5,13 +5,19 @@ from ..llm_caller import call_llm from ..views.feedback_block import create_feedback_block -""" -Handles the event when the app is mentioned in a Slack conversation -and generates an AI response. -""" def app_mentioned_callback(client: WebClient, event: dict, logger: Logger, say: Say): + """ + Handles the event when the app is mentioned in a Slack conversation + and generates an AI response. + + Args: + client: Slack WebClient for making API calls + event: Event payload containing mention details (channel, user, text, etc.) + logger: Logger instance for error tracking + say: Function to send messages to the thread from the app + """ try: channel_id = event.get("channel") team_id = event.get("team") From 99b38888409e7528fd23b0b2d74c42f566a72b53 Mon Sep 17 00:00:00 2001 From: Ale Mercado Date: Mon, 6 Oct 2025 13:34:39 -0400 Subject: [PATCH 2/6] fix: linter errors --- listeners/actions/actions.py | 2 +- listeners/events/app_mentioned.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/listeners/actions/actions.py b/listeners/actions/actions.py index be42113..160ce21 100644 --- a/listeners/actions/actions.py +++ b/listeners/actions/actions.py @@ -8,7 +8,7 @@ def handle_feedback(ack, body, client, logger: logging.Logger): Args: ack: Function to acknowledge the action request body: Action payload containing feedback details (message, channel, user, action value) - client: Slack WebClient for making API calls + client: Slack WebClient for making API calls logger: Logger instance for debugging and error tracking """ try: diff --git a/listeners/events/app_mentioned.py b/listeners/events/app_mentioned.py index 7320a5c..404262f 100644 --- a/listeners/events/app_mentioned.py +++ b/listeners/events/app_mentioned.py @@ -6,7 +6,6 @@ from ..views.feedback_block import create_feedback_block - def app_mentioned_callback(client: WebClient, event: dict, logger: Logger, say: Say): """ Handles the event when the app is mentioned in a Slack conversation From 66cdd6de9ff43196a8ce2b85e0eeeb0082e03806 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Mon, 6 Oct 2025 13:45:40 -0700 Subject: [PATCH 3/6] chore: order imports with parameter typings --- app.py | 2 +- app_oauth.py | 4 ++-- listeners/__init__.py | 8 ++++---- listeners/actions/__init__.py | 1 + listeners/actions/actions.py | 7 +++++-- listeners/assistant/__init__.py | 1 + listeners/assistant/assistant.py | 3 +-- listeners/events/__init__.py | 1 + listeners/events/app_mentioned.py | 3 ++- listeners/llm_caller.py | 3 +-- listeners/views/feedback_block.py | 3 ++- 11 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index fb7bccf..73a3031 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ -import os import logging +import os from slack_bolt import App from slack_bolt.adapter.socket_mode import SocketModeHandler diff --git a/app_oauth.py b/app_oauth.py index 043b1ee..1a641c4 100644 --- a/app_oauth.py +++ b/app_oauth.py @@ -1,9 +1,9 @@ import logging import os + from slack_bolt import App, BoltResponse -from slack_bolt.oauth.callback_options import CallbackOptions, SuccessArgs, FailureArgs +from slack_bolt.oauth.callback_options import CallbackOptions, FailureArgs, SuccessArgs from slack_bolt.oauth.oauth_settings import OAuthSettings - from slack_sdk.oauth.installation_store import FileInstallationStore from slack_sdk.oauth.state_store import FileOAuthStateStore diff --git a/listeners/__init__.py b/listeners/__init__.py index 4a53dc3..42e53ef 100644 --- a/listeners/__init__.py +++ b/listeners/__init__.py @@ -1,9 +1,9 @@ -from listeners import actions -from listeners import assistant -from listeners import events +from slack_bolt import App +from listeners import actions, assistant, events -def register_listeners(app): + +def register_listeners(app: App): actions.register(app) assistant.register(app) events.register(app) diff --git a/listeners/actions/__init__.py b/listeners/actions/__init__.py index e42fd04..f743f44 100644 --- a/listeners/actions/__init__.py +++ b/listeners/actions/__init__.py @@ -1,4 +1,5 @@ from slack_bolt import App + from .actions import handle_feedback diff --git a/listeners/actions/actions.py b/listeners/actions/actions.py index 160ce21..b55c0cd 100644 --- a/listeners/actions/actions.py +++ b/listeners/actions/actions.py @@ -1,7 +1,10 @@ -import logging +from logging import Logger +from slack_bolt import Ack +from slack_sdk import WebClient -def handle_feedback(ack, body, client, logger: logging.Logger): + +def handle_feedback(ack: Ack, body: dict, client: WebClient, logger: Logger): """ Handles user feedback on AI-generated responses via thumbs up/down buttons. diff --git a/listeners/assistant/__init__.py b/listeners/assistant/__init__.py index 7457ba6..f0235ac 100644 --- a/listeners/assistant/__init__.py +++ b/listeners/assistant/__init__.py @@ -1,4 +1,5 @@ from slack_bolt import App + from .assistant import assistant diff --git a/listeners/assistant/assistant.py b/listeners/assistant/assistant.py index c5ec7b3..61e5fb2 100644 --- a/listeners/assistant/assistant.py +++ b/listeners/assistant/assistant.py @@ -6,9 +6,8 @@ from slack_sdk import WebClient from slack_sdk.errors import SlackApiError -from ..views.feedback_block import create_feedback_block from ..llm_caller import call_llm - +from ..views.feedback_block import create_feedback_block # Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details assistant = Assistant() diff --git a/listeners/events/__init__.py b/listeners/events/__init__.py index d962ec5..f78d888 100644 --- a/listeners/events/__init__.py +++ b/listeners/events/__init__.py @@ -1,4 +1,5 @@ from slack_bolt import App + from .app_mentioned import app_mentioned_callback diff --git a/listeners/events/app_mentioned.py b/listeners/events/app_mentioned.py index 404262f..d26ab10 100644 --- a/listeners/events/app_mentioned.py +++ b/listeners/events/app_mentioned.py @@ -1,6 +1,7 @@ from logging import Logger -from slack_sdk import WebClient + from slack_bolt import Say +from slack_sdk import WebClient from ..llm_caller import call_llm from ..views.feedback_block import create_feedback_block diff --git a/listeners/llm_caller.py b/listeners/llm_caller.py index e808068..a1b9fc5 100644 --- a/listeners/llm_caller.py +++ b/listeners/llm_caller.py @@ -1,11 +1,10 @@ import os -from typing import List, Dict +from typing import Dict, List import openai from openai import Stream from openai.types.responses import ResponseStreamEvent - DEFAULT_SYSTEM_CONTENT = """ You're an assistant in a Slack workspace. Users in the workspace will ask you to help them write something or to think better about a specific topic. diff --git a/listeners/views/feedback_block.py b/listeners/views/feedback_block.py index 2064490..48028be 100644 --- a/listeners/views/feedback_block.py +++ b/listeners/views/feedback_block.py @@ -1,5 +1,6 @@ from typing import List -from slack_sdk.models.blocks import Block, ContextActionsBlock, FeedbackButtonsElement, FeedbackButtonObject + +from slack_sdk.models.blocks import Block, ContextActionsBlock, FeedbackButtonObject, FeedbackButtonsElement def create_feedback_block() -> List[Block]: From 9fb532bd7cc87c6d75c8b386d7b9b2deafc27bfc Mon Sep 17 00:00:00 2001 From: Ale Mercado Date: Mon, 6 Oct 2025 16:56:26 -0400 Subject: [PATCH 4/6] chore: merge w main --- app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.py b/app.py index 73a3031..a92fba7 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,18 @@ import logging import os +from dotenv import load_dotenv + from slack_bolt import App from slack_bolt.adapter.socket_mode import SocketModeHandler from slack_sdk import WebClient from listeners import register_listeners + +# Load environment variables +load_dotenv() + # Initialization logging.basicConfig(level=logging.DEBUG) From 65b37fa3de896b1fc851b63eea7783b1aa892c2c Mon Sep 17 00:00:00 2001 From: Ale Mercado Date: Mon, 6 Oct 2025 17:12:01 -0400 Subject: [PATCH 5/6] fix: linter errors --- listeners/assistant/assistant.py | 1 - 1 file changed, 1 deletion(-) diff --git a/listeners/assistant/assistant.py b/listeners/assistant/assistant.py index 7c93222..6b168ba 100644 --- a/listeners/assistant/assistant.py +++ b/listeners/assistant/assistant.py @@ -6,7 +6,6 @@ from slack_sdk import WebClient from slack_sdk.errors import SlackApiError -from ..llm_caller import call_llm from ..views.feedback_block import create_feedback_block from ai.llm_caller import call_llm From 0400cc89b3f5ed3f670bace2e8a48310b6fbd499 Mon Sep 17 00:00:00 2001 From: Eden Zimbelman Date: Mon, 6 Oct 2025 14:14:44 -0700 Subject: [PATCH 6/6] refactor: import logger from logging --- listeners/assistant/assistant.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/listeners/assistant/assistant.py b/listeners/assistant/assistant.py index 6b168ba..b818019 100644 --- a/listeners/assistant/assistant.py +++ b/listeners/assistant/assistant.py @@ -1,4 +1,4 @@ -import logging +from logging import Logger from typing import Dict, List from slack_bolt import Assistant, BoltContext, Say, SetStatus, SetSuggestedPrompts @@ -6,9 +6,9 @@ from slack_sdk import WebClient from slack_sdk.errors import SlackApiError -from ..views.feedback_block import create_feedback_block from ai.llm_caller import call_llm +from ..views.feedback_block import create_feedback_block # Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details assistant = Assistant() @@ -19,7 +19,7 @@ def start_assistant_thread( say: Say, get_thread_context: GetThreadContext, set_suggested_prompts: SetSuggestedPrompts, - logger: logging.Logger, + logger: Logger, ): """ Handle the assistant thread start event by greeting the user and setting suggested prompts. @@ -68,7 +68,7 @@ def respond_in_assistant_thread( client: WebClient, context: BoltContext, get_thread_context: GetThreadContext, - logger: logging.Logger, + logger: Logger, payload: dict, say: Say, set_status: SetStatus,