Skip to content

Commit d452206

Browse files
Update: [AEA-6218] - Update document upload Slack notification content (#502)
## Summary - Routine Change ### Details tightens up the Slack sync message so it’s clearer what’s actually happening (per D298)
1 parent e097bd4 commit d452206

4 files changed

Lines changed: 102 additions & 53 deletions

File tree

packages/syncKnowledgeBaseFunction/app/handler.py

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111
import traceback
1212
import uuid
13+
from urllib.parse import unquote_plus
1314
import boto3
1415
from typing import Literal
1516
from app.config.config import (
@@ -361,7 +362,9 @@ def initialise_slack(self):
361362
logger.warning("SKIPPING - Bot is not in any channels. No messages sent.")
362363
return []
363364

364-
message_default_text = "I am currently syncing changes to my knowledge base.\n This may take a few minutes."
365+
message_default_text = (
366+
"The documents I use to answer your questions are being updated. " "This will be completed in 10 minutes."
367+
)
365368

366369
# Build blocks for Slack message
367370
blocks = [
@@ -375,28 +378,17 @@ def initialise_slack(self):
375378
{
376379
"type": "plan",
377380
"plan_id": uuid.uuid4().hex,
378-
"title": "Processing File Changes...",
381+
"title": "Processing file updates...",
379382
"tasks": [
380-
self.create_task(
381-
id=self.fetching_block_id,
382-
title="Fetching changes",
383-
details=[],
384-
outputs=["Searching"],
385-
status="complete",
386-
),
387383
self.create_task(
388384
id=self.update_block_id,
389-
title="Processing File Changes",
385+
title="Processing file updates...",
390386
details=[],
391387
outputs=["Initialising"],
392388
status="in_progress",
393389
),
394390
],
395391
},
396-
{
397-
"type": "context",
398-
"elements": [{"type": "plain_text", "text": "Please wait up-to 10 minutes for changes to take effect"}],
399-
},
400392
]
401393

402394
return blocks
@@ -477,6 +469,7 @@ def __init__(self):
477469
self.created = 0
478470
self.modified = 0
479471
self.deleted = 0
472+
self.document_names = []
480473

481474
@staticmethod
482475
def is_supported_file_type(file_key):
@@ -513,27 +506,30 @@ def process_multiple_s3_events(self, records: list, slack_handler: SlackHandler)
513506
self.modified += len([r for r in records if "ObjectModified" in r.get("eventName", "")])
514507
self.deleted += len([r for r in records if "ObjectRemoved" in r.get("eventName", "")])
515508

516-
total = self.created + self.modified + self.deleted
509+
# Extract document names from records
510+
for r in records:
511+
object_key = r.get("s3", {}).get("object", {}).get("key", "")
512+
if object_key:
513+
decoded_key = unquote_plus(object_key)
514+
file_name = decoded_key.split("/")[-1]
515+
if file_name and file_name not in self.document_names:
516+
self.document_names.append(file_name)
517517

518-
counts = [
519-
("created", self.created),
520-
("modified", self.modified),
521-
("deleted", self.deleted),
522-
]
523-
524-
# Generate the list only for non-zero values
525-
message_list = [f"{count} files {action}" for action, count in counts if count > 0]
526-
527-
if message_list and len(message_list) > 0:
518+
if self.document_names:
528519
slack_handler.update_task(
529520
id=slack_handler.update_block_id, message="Update pending", output_message="Processing...", replace=True
530521
)
531-
for i, message in enumerate(message_list):
532-
output_message = f"Processed a total of {total} record(s)" if (i + 1 == len(message_list)) else None
522+
for i, name in enumerate(self.document_names):
523+
total = self.created + self.modified + self.deleted
524+
output_message = (
525+
f"Processed {total} file {'update' if total == 1 else 'updates'}"
526+
if (i + 1 == len(self.document_names))
527+
else None
528+
)
533529
slack_handler.update_task(
534-
id=slack_handler.update_block_id, message=message, output_message=output_message, replace=(i == 0)
530+
id=slack_handler.update_block_id, message=name, output_message=output_message, replace=(i == 0)
535531
)
536-
slack_handler.update_task_db(created=self.created, modified=self.modified, deleted=self.deleted)
532+
slack_handler.update_task_db(created=self.created, modified=self.modified, deleted=self.deleted)
537533

538534
@staticmethod
539535
def start_ingestion_job():
@@ -587,13 +583,6 @@ def process_batched_queue_events(self, slack_handler: SlackHandler, events: list
587583
continue
588584

589585
logger.info(f"Processing {len(sqs_records)} record(s)")
590-
output_message = "Search Complete" if (i + 1 == len(events)) else None
591-
slack_handler.update_task(
592-
id=slack_handler.fetching_block_id,
593-
message=f"Found {len(sqs_records)} events",
594-
output_message=output_message,
595-
replace=True,
596-
)
597586

598587
self.process_multiple_sqs_events(slack_handler, sqs_records)
599588

packages/syncKnowledgeBaseFunction/tests/test_app.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ def mock_post_message_side_effect(**kwargs):
510510

511511
# Assert Messages were posted and updated
512512
mock_slack_client.chat_postMessage.assert_called_once()
513-
assert mock_slack_client.chat_update.call_count == 4 # Update details, update tasks (+ clear), close
513+
# Update pending (replace), update with doc name, complete_plan
514+
assert mock_slack_client.chat_update.call_count == 3
514515

515516

516517
@patch("app.config.config.get_bot_active")
@@ -923,9 +924,9 @@ def mock_post_message_side_effect(**kwargs):
923924
calls = mock_slack_client.chat_update.call_args_list
924925
assert len(calls) > 0, "Expected chat_update to be called."
925926

926-
# Verify the formatted message made its way into the blocks sent to chat_update
927+
# Verify the document names made their way into the blocks sent to chat_update
927928
last_call_blocks_str = str(calls[-1].kwargs.get("blocks", []))
928-
assert "2 files created" in last_call_blocks_str
929+
assert "test-file.pdf" in last_call_blocks_str
929930

930931

931932
@patch("slack_sdk.WebClient")
@@ -1012,11 +1013,13 @@ def mock_post_message_side_effect(**kwargs):
10121013
calls = mock_slack_client.chat_update.call_args_list
10131014
assert len(calls) > 0, "Expected chat_update to be called."
10141015

1015-
# Verify the formatted message made its way into the blocks sent to chat_update
1016+
# Verify the document names made their way into the blocks sent to chat_update
10161017
last_call_blocks_str = str(calls[-1].kwargs.get("blocks", []))
1017-
assert "4 files created" in last_call_blocks_str # +1 in initial call
1018-
assert "3 files modified" in last_call_blocks_str
1019-
assert "6 files deleted" in last_call_blocks_str
1018+
assert "test-file.pdf" in last_call_blocks_str
1019+
assert "file1.pdf" in last_call_blocks_str
1020+
assert "file4.pdf" in last_call_blocks_str
1021+
assert "file2.pdf" in last_call_blocks_str
1022+
assert "file3.pdf" in last_call_blocks_str
10201023

10211024

10221025
@patch("slack_sdk.WebClient")
@@ -1106,11 +1109,13 @@ def mock_post_message_side_effect(**kwargs):
11061109
calls = mock_slack_client.chat_update.call_args_list
11071110
assert len(calls) > 0, "Expected chat_update to be called."
11081111

1109-
# Verify the formatted message made its way into the blocks sent to chat_update
1112+
# Verify the document names made their way into the blocks sent to chat_update
11101113
last_call_blocks_str = str(calls[-1].kwargs.get("blocks", []))
1111-
assert "6 files created" in last_call_blocks_str # +1 initial call
1112-
assert "5 files modified" in last_call_blocks_str
1113-
assert "10 files deleted" in last_call_blocks_str
1114+
assert "test-file.pdf" in last_call_blocks_str
1115+
assert "file1.pdf" in last_call_blocks_str
1116+
assert "file4.pdf" in last_call_blocks_str
1117+
assert "file2.pdf" in last_call_blocks_str
1118+
assert "file3.pdf" in last_call_blocks_str
11141119

11151120

11161121
@patch("boto3.client")

poetry.lock

Lines changed: 60 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ aws-lambda-powertools = "^3.26.0"
5757

5858

5959
[tool.poetry.group.preprocessingFunction.dependencies]
60+
botocore = {extras = ["crt"], version = "^1.42.73"}
6061
boto3 = "^1.42.78"
6162
aws-lambda-powertools = "^3.26.0"
6263
markitdown = {extras = ["pdf", "docx", "xlsx"], version = "^0.0.1a12"}

0 commit comments

Comments
 (0)