Fix Slackbot Tagging people or groups (#473)

This commit is contained in:
Yuhong Sun
2023-09-21 21:44:35 -07:00
committed by GitHub
parent 5cc17d39f0
commit 3c65317538
3 changed files with 17 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ from slack_sdk.models.blocks import SectionBlock
from danswer.bots.slack.constants import DISLIKE_BLOCK_ACTION_ID
from danswer.bots.slack.constants import LIKE_BLOCK_ACTION_ID
from danswer.bots.slack.utils import build_feedback_block_id
from danswer.bots.slack.utils import remove_slack_text_interactions
from danswer.bots.slack.utils import translate_vespa_highlight_to_slack
from danswer.configs.app_configs import DANSWER_BOT_NUM_DOCS_TO_DISPLAY
from danswer.configs.app_configs import ENABLE_SLACK_DOC_FEEDBACK
@@ -95,9 +96,7 @@ def build_documents_blocks(
section_blocks.append(
SectionBlock(
fields=[
f"<{d.link}|{doc_sem_id}>:\n>{match_str}",
]
text=f"<{d.link}|{doc_sem_id}>:\n>{remove_slack_text_interactions(match_str)}"
),
)
@@ -134,7 +133,11 @@ def build_quotes_block(
if doc_id not in doc_to_quotes:
doc_to_quotes[doc_id] = [quote]
doc_to_link[doc_id] = doc_link
doc_to_sem_id[doc_id] = doc_name
doc_to_sem_id[doc_id] = (
doc_name
if q.source_type != DocumentSource.SLACK.value
else "#" + doc_name
)
else:
doc_to_quotes[doc_id].append(quote)
@@ -146,7 +149,9 @@ def build_quotes_block(
single_quote_str = "\n".join([f"```{q_str}```" for q_str in longest_quotes])
link = doc_to_link[doc_id]
sem_id = doc_to_sem_id[doc_id]
quote_lines.append(f"<{link}|{sem_id}>:\n{single_quote_str}")
quote_lines.append(
f"<{link}|{sem_id}>:\n{remove_slack_text_interactions(single_quote_str)}"
)
if not doc_to_quotes:
return []
@@ -168,7 +173,7 @@ def build_qa_response_blocks(
text="Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓"
)
else:
answer_block = SectionBlock(text=answer)
answer_block = SectionBlock(text=remove_slack_text_interactions(answer))
if quotes:
quotes_blocks = build_quotes_block(quotes)

View File

@@ -117,4 +117,5 @@ def remove_slack_text_interactions(slack_str: str) -> str:
slack_str = UserIdReplacer.replace_channels_basic(slack_str)
slack_str = UserIdReplacer.replace_special_mentions(slack_str)
slack_str = UserIdReplacer.replace_links(slack_str)
slack_str = UserIdReplacer.add_zero_width_whitespace_after_tag(slack_str)
return slack_str

View File

@@ -196,3 +196,8 @@ class UserIdReplacer:
)
message = message.replace(f"<{possible_link}>", link_display)
return message
@staticmethod
def add_zero_width_whitespace_after_tag(message: str) -> str:
"""Add a 0 width whitespace after every @"""
return message.replace("@", "@\u200B")