mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-07-12 14:12:53 +02:00
Slack fixes
This commit is contained in:
@ -264,24 +264,6 @@ class SlackTextCleaner:
|
||||
message = message.replace("<!everyone>", "@everyone")
|
||||
return message
|
||||
|
||||
@staticmethod
|
||||
def replace_links(message: str) -> str:
|
||||
"""Replaces slack links e.g. `<URL>` -> `URL` and `<URL|DISPLAY>` -> `DISPLAY`"""
|
||||
# Find user IDs in the message
|
||||
possible_link_matches = re.findall(r"<(.*?)>", message)
|
||||
for possible_link in possible_link_matches:
|
||||
if not possible_link:
|
||||
continue
|
||||
# Special slack patterns that aren't for links
|
||||
if possible_link[0] not in ["#", "@", "!"]:
|
||||
link_display = (
|
||||
possible_link
|
||||
if "|" not in possible_link
|
||||
else possible_link.split("|")[1]
|
||||
)
|
||||
message = message.replace(f"<{possible_link}>", link_display)
|
||||
return message
|
||||
|
||||
@staticmethod
|
||||
def replace_special_catchall(message: str) -> str:
|
||||
"""Replaces pattern of <!something|another-thing> with another-thing
|
||||
|
@ -1,6 +1,4 @@
|
||||
import re
|
||||
from datetime import datetime
|
||||
from re import Match
|
||||
|
||||
import pytz
|
||||
import timeago # type: ignore
|
||||
@ -59,33 +57,6 @@ def get_feedback_reminder_blocks(thread_link: str, include_followup: bool) -> Bl
|
||||
return SectionBlock(text=text)
|
||||
|
||||
|
||||
def _process_citations_for_slack(text: str) -> str:
|
||||
"""
|
||||
Converts instances of [[x]](LINK) in the input text to Slack's link format <LINK|[x]>.
|
||||
|
||||
Args:
|
||||
- text (str): The input string containing markdown links.
|
||||
|
||||
Returns:
|
||||
- str: The string with markdown links converted to Slack format.
|
||||
"""
|
||||
# Regular expression to find all instances of [[x]](LINK)
|
||||
pattern = r"\[\[(.*?)\]\]\((.*?)\)"
|
||||
|
||||
# Function to replace each found instance with Slack's format
|
||||
def slack_link_format(match: Match) -> str:
|
||||
link_text = match.group(1)
|
||||
link_url = match.group(2)
|
||||
|
||||
# Account for empty link citations
|
||||
if link_url == "":
|
||||
return f"[{link_text}]"
|
||||
return f"<{link_url}|[{link_text}]>"
|
||||
|
||||
# Substitute all matches in the input text
|
||||
return re.sub(pattern, slack_link_format, text)
|
||||
|
||||
|
||||
def _split_text(text: str, limit: int = 3000) -> list[str]:
|
||||
if len(text) <= limit:
|
||||
return [text]
|
||||
@ -369,15 +340,12 @@ def _build_citations_blocks(
|
||||
|
||||
def _build_qa_response_blocks(
|
||||
answer: ChatOnyxBotResponse,
|
||||
process_message_for_citations: bool = False,
|
||||
) -> list[Block]:
|
||||
retrieval_info = answer.docs
|
||||
if not retrieval_info:
|
||||
# This should not happen, even with no docs retrieved, there is still info returned
|
||||
raise RuntimeError("Failed to retrieve docs, cannot answer question.")
|
||||
|
||||
formatted_answer = format_slack_message(answer.answer) if answer.answer else None
|
||||
|
||||
if DISABLE_GENERATIVE_AI:
|
||||
return []
|
||||
|
||||
@ -408,18 +376,18 @@ def _build_qa_response_blocks(
|
||||
|
||||
filter_block = SectionBlock(text=f"_{filter_text}_")
|
||||
|
||||
if not formatted_answer:
|
||||
if not answer.answer:
|
||||
answer_blocks = [
|
||||
SectionBlock(
|
||||
text="Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓"
|
||||
)
|
||||
]
|
||||
else:
|
||||
# replaces markdown links with slack format links
|
||||
formatted_answer = format_slack_message(answer.answer)
|
||||
answer_processed = decode_escapes(
|
||||
remove_slack_text_interactions(formatted_answer)
|
||||
)
|
||||
if process_message_for_citations:
|
||||
answer_processed = _process_citations_for_slack(answer_processed)
|
||||
answer_blocks = [
|
||||
SectionBlock(text=text) for text in _split_text(answer_processed)
|
||||
]
|
||||
@ -525,7 +493,6 @@ def build_slack_response_blocks(
|
||||
|
||||
answer_blocks = _build_qa_response_blocks(
|
||||
answer=answer,
|
||||
process_message_for_citations=use_citations,
|
||||
)
|
||||
|
||||
web_follow_up_block = []
|
||||
|
@ -4,73 +4,55 @@ from onyx.configs.constants import DocumentSource
|
||||
def source_to_github_img_link(source: DocumentSource) -> str | None:
|
||||
# TODO: store these images somewhere better
|
||||
if source == DocumentSource.WEB.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/Web.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/Web.png"
|
||||
if source == DocumentSource.FILE.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/File.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/File.png"
|
||||
if source == DocumentSource.GOOGLE_SITES.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/GoogleSites.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/GoogleSites.png"
|
||||
if source == DocumentSource.SLACK.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Slack.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Slack.png"
|
||||
if source == DocumentSource.GMAIL.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Gmail.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Gmail.png"
|
||||
if source == DocumentSource.GOOGLE_DRIVE.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/GoogleDrive.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/GoogleDrive.png"
|
||||
if source == DocumentSource.GITHUB.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Github.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Github.png"
|
||||
if source == DocumentSource.GITLAB.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Gitlab.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Gitlab.png"
|
||||
if source == DocumentSource.CONFLUENCE.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/Confluence.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/Confluence.png"
|
||||
if source == DocumentSource.JIRA.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/Jira.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/Jira.png"
|
||||
if source == DocumentSource.NOTION.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Notion.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Notion.png"
|
||||
if source == DocumentSource.ZENDESK.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/Zendesk.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/Zendesk.png"
|
||||
if source == DocumentSource.GONG.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Gong.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Gong.png"
|
||||
if source == DocumentSource.LINEAR.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Linear.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Linear.png"
|
||||
if source == DocumentSource.PRODUCTBOARD.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Productboard.webp"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Productboard.webp"
|
||||
if source == DocumentSource.SLAB.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/SlabLogo.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/SlabLogo.png"
|
||||
if source == DocumentSource.ZULIP.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Zulip.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Zulip.png"
|
||||
if source == DocumentSource.GURU.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/Guru.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/Guru.png"
|
||||
if source == DocumentSource.HUBSPOT.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/HubSpot.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/HubSpot.png"
|
||||
if source == DocumentSource.DOCUMENT360.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Document360.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Document360.png"
|
||||
if source == DocumentSource.BOOKSTACK.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Bookstack.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Bookstack.png"
|
||||
if source == DocumentSource.LOOPIO.value:
|
||||
return (
|
||||
"https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Loopio.png"
|
||||
)
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Loopio.png"
|
||||
if source == DocumentSource.SHAREPOINT.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/web/public/Sharepoint.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/web/public/Sharepoint.png"
|
||||
if source == DocumentSource.REQUESTTRACKER.value:
|
||||
# just use file icon for now
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/File.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/File.png"
|
||||
if source == DocumentSource.INGESTION_API.value:
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/File.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/File.png"
|
||||
|
||||
return "https://raw.githubusercontent.com/onyx-ai/onyx/main/backend/slackbot_images/File.png"
|
||||
return "https://raw.githubusercontent.com/onyx-dot-app/onyx/main/backend/slackbot_images/File.png"
|
||||
|
@ -375,7 +375,6 @@ def remove_slack_text_interactions(slack_str: str) -> str:
|
||||
slack_str = SlackTextCleaner.replace_tags_basic(slack_str)
|
||||
slack_str = SlackTextCleaner.replace_channels_basic(slack_str)
|
||||
slack_str = SlackTextCleaner.replace_special_mentions(slack_str)
|
||||
slack_str = SlackTextCleaner.replace_links(slack_str)
|
||||
slack_str = SlackTextCleaner.replace_special_catchall(slack_str)
|
||||
slack_str = SlackTextCleaner.add_zero_width_whitespace_after_tag(slack_str)
|
||||
return slack_str
|
||||
|
Reference in New Issue
Block a user