1- import logging
1+ from logging import Logger
22from typing import Dict , List
33
44from slack_bolt import Assistant , BoltContext , Say , SetStatus , SetSuggestedPrompts
55from slack_bolt .context .get_thread_context import GetThreadContext
66from slack_sdk import WebClient
77from slack_sdk .errors import SlackApiError
88
9- from ..views .feedback_block import create_feedback_block
109from ai .llm_caller import call_llm
1110
11+ from ..views .feedback_block import create_feedback_block
1212
1313# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details
1414assistant = Assistant ()
1515
1616
17- # This listener is invoked when a human user opened an assistant thread
1817@assistant .thread_started
1918def start_assistant_thread (
2019 say : Say ,
2120 get_thread_context : GetThreadContext ,
2221 set_suggested_prompts : SetSuggestedPrompts ,
23- logger : logging . Logger ,
22+ logger : Logger ,
2423):
24+ """
25+ Handle the assistant thread start event by greeting the user and setting suggested prompts.
26+
27+ Args:
28+ say: Function to send messages to the thread from the app
29+ get_thread_context: Function to retrieve thread context information
30+ set_suggested_prompts: Function to configure suggested prompt options
31+ logger: Logger instance for error tracking
32+ """
2533 try :
2634 say ("How can I help you?" )
2735
@@ -60,11 +68,23 @@ def respond_in_assistant_thread(
6068 client : WebClient ,
6169 context : BoltContext ,
6270 get_thread_context : GetThreadContext ,
63- logger : logging . Logger ,
71+ logger : Logger ,
6472 payload : dict ,
6573 say : Say ,
6674 set_status : SetStatus ,
6775):
76+ """
77+ Handles when users send messages or select a prompt in an assistant thread and generate AI responses:
78+
79+ Args:
80+ client: Slack WebClient for making API calls
81+ context: Bolt context containing channel and thread information
82+ get_thread_context: Function to retrieve thread context (e.g., referred channel)
83+ logger: Logger instance for error tracking
84+ payload: Event payload with message details (channel, user, text, etc.)
85+ say: Function to send messages to the thread
86+ set_status: Function to update the assistant's status
87+ """
6888 try :
6989 channel_id = payload ["channel" ]
7090 team_id = context .team_id
@@ -84,8 +104,6 @@ def respond_in_assistant_thread(
84104 )
85105
86106 if user_message == "Can you generate a brief summary of the referred channel?" :
87- # the logic here requires the additional bot scopes:
88- # channels:join, channels:history, groups:history
89107 thread_context = get_thread_context ()
90108 referred_channel_id = thread_context .get ("channel_id" )
91109 try :
0 commit comments