Skip to content

Commit 9bf1fea

Browse files
feat: add cite action to handlers
1 parent f824d2e commit 9bf1fea

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/slackBotFunction/app/slack/slack_events.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
270271
def 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

588592
def 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
)

packages/slackBotFunction/app/slack/slack_handlers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def setup_handlers(app: App) -> None:
4141
app.event("message")(ack=respond_to_events, lazy=[unified_message_handler])
4242
app.action("feedback_yes")(ack=respond_to_action, lazy=[feedback_handler])
4343
app.action("feedback_no")(ack=respond_to_action, lazy=[feedback_handler])
44+
app.action("cite")(ack=respond_to_action, lazy=[feedback_handler])
4445

4546

4647
# ================================================================

0 commit comments

Comments
 (0)