33from slack_bolt import Assistant , BoltContext , Say , SetSuggestedPrompts
44from slack_bolt .context .get_thread_context import GetThreadContext
55from slack_sdk import WebClient
6- from slack_sdk .models .blocks import FeedbackButtonsElement , FeedbackButtonObject , ContextActionsBlock
6+ from slack_sdk .models .blocks import Block , ContextActionsBlock , FeedbackButtonsElement , FeedbackButtonObject
77
88from ..llm_caller import call_llm
99
1010# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details
1111assistant = Assistant ()
1212
1313
14- def create_feedback_block (user_id : str ) -> ContextActionsBlock :
14+ def create_feedback_block () -> List [ Block ] :
1515 """
1616 Create feedback block with thumbs up/down buttons
1717
18- Args:
19- user_id: User ID for user-specific controls
20-
2118 Returns:
2219 Block Kit context_actions block
2320 """
24- block = [
21+ blocks : List [ Block ] = [
2522 ContextActionsBlock (
2623 elements = [
2724 FeedbackButtonsElement (
@@ -40,7 +37,7 @@ def create_feedback_block(user_id: str) -> ContextActionsBlock:
4037 ]
4138 )
4239 ]
43- return block
40+ return blocks
4441
4542
4643# This listener is invoked when a human user opened an assistant thread
@@ -93,7 +90,6 @@ def respond_in_assistant_thread(
9390 say : Say ,
9491):
9592 try :
96- user_id = payload ["user" ]
9793 channel_id = payload ["channel" ]
9894 thread_ts = payload ["thread_ts" ]
9995
@@ -135,38 +131,9 @@ def respond_in_assistant_thread(
135131 else :
136132 continue
137133
138- feedback_block = create_feedback_block (user_id = user_id )
134+ feedback_block = create_feedback_block ()
139135 client .chat_stopStream (channel = channel_id , ts = stream_ts , blocks = feedback_block )
140136
141137 except Exception as e :
142138 logger .exception (f"Failed to handle a user message event: { e } " )
143139 say (f":warning: Something went wrong! ({ e } )" )
144-
145-
146- # Handle feedback buttons (thumbs up/down)
147- def handle_feedback (ack , body , client , logger ):
148- ack ()
149- try :
150- message_ts = body ["message" ]["ts" ]
151- channel_id = body ["channel" ]["id" ]
152- feedback_type = body ["actions" ][0 ]["value" ]
153- is_positive = feedback_type == "good-feedback"
154-
155- if is_positive :
156- client .chat_postEphemeral (
157- channel = channel_id ,
158- user = body ["user" ]["id" ],
159- thread_ts = message_ts ,
160- text = "We're glad you found this useful." ,
161- )
162- else :
163- client .chat_postEphemeral (
164- channel = channel_id ,
165- user = body ["user" ]["id" ],
166- thread_ts = message_ts ,
167- text = "Sorry to hear that response wasn't up to par :slightly_frowning_face: Starting a new chat may help with AI mistakes and hallucinations." ,
168- )
169-
170- logger .debug (f"Handled feedback: type={ feedback_type } , message_ts={ message_ts } " )
171- except Exception as error :
172- logger .error (f":warning: Something went wrong! { error } " )
0 commit comments