@@ -177,9 +177,10 @@ def _create_feedback_blocks(
177177 button = {
178178 "type" : "button" ,
179179 "text" : {"type" : "plain_text" , "text" : title },
180- "action_id" : f"cite_ { i } " ,
180+ "action_id" : "cite " ,
181181 "value" : json .dumps (
182- {** feedback_data , "title" : title , "body" : body , "link" : citation_link }, separators = ("," , ":" )
182+ {** feedback_data , "title" : title , "body" : body , "link" : citation_link },
183+ separators = ("," , ":" ),
183184 ),
184185 }
185186 action_buttons .append (button )
@@ -270,7 +271,9 @@ def process_feedback_event(
270271def process_async_slack_action (body : Dict [str , Any ], client : WebClient ) -> None :
271272 try :
272273 # Extract necessary information from the action payload
273- message = body ["message" ]
274+ message = body [
275+ "message"
276+ ] # The original message object is sent back on an action, so we don't need to fetch it again
274277 action = body ["actions" ][0 ]
275278 action_id = action ["action_id" ]
276279 action_data = json .loads (action ["value" ])
@@ -287,6 +290,7 @@ def process_async_slack_action(body: Dict[str, Any], client: WebClient) -> None:
287290 if (action_id or "" ).startswith ("cite_" ):
288291 params = json .loads (action_data )
289292
293+ # Update message to include citation content
290294 open_citation (channel_id , timestamp , message , params , client )
291295 return
292296
@@ -587,7 +591,7 @@ def store_feedback(
587591
588592def open_citation (channel : str , timestamp : str , message : Any , params : Dict [str , Any ], client ) -> None :
589593 """
590- Open citation - placeholder for actual implementation
594+ Open citation - update/ replace message to include citation content
591595 """
592596 logger .info ("Opening citation" , extra = {"channel" : channel , "timestamp" : timestamp })
593597 # Get Message
@@ -598,8 +602,10 @@ def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str,
598602 link = params .get ("link" , "" )
599603
600604 blocks = message .get ("blocks" , [])
605+
601606 # Remove citation block (and divider), if it exists
602607 blocks = [block for block in blocks if block .get ("block_id" ) not in ["citation_block" , "citation_divider" ]]
608+
603609 # Add citation content before feedback block
604610 citation_block = {
605611 "type" : "section" ,
@@ -610,6 +616,7 @@ def open_citation(channel: str, timestamp: str, message: Any, params: Dict[str,
610616 "block_id" : "citation_block" ,
611617 }
612618
619+ # Find index of feedback block to insert before it
613620 feedback_block_index = next (
614621 (i for i , block in enumerate (blocks ) if block .get ("block_id" ) == "feedback_block" ), len (blocks )
615622 )
0 commit comments