Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions backend/danswer/danswerbot/slack/handlers/handle_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ def remove_scheduled_feedback_reminder(
"Unable to delete the scheduled message. It must have already been posted"
)

def contains_questionmark_outside_links(message: str) -> bool:
"""
Checks if the message contains a question mark outside of URLs.
"""
url_pattern = r"<https?://[^\s>]+>|https?://\S+"

message_without_links = re.sub(url_pattern, "", message)

return "?" in message_without_links


def contains_questionmark_outside_links(message: str) -> bool:
"""
Expand Down Expand Up @@ -352,9 +362,10 @@ def handle_message(
if not bypass_filters and "answer_filters" in channel_conf:
reflexion = "well_answered_postfilter" in channel_conf["answer_filters"]

if "questionmark_prefilter" in channel_conf[
"answer_filters"
] and not contains_questionmark_outside_links(messages[-1].message):
if (
"questionmark_prefilter" in channel_conf["answer_filters"]
and not contains_questionmark_outside_links(messages[-1].message)
):
logger.info(
"Skipping message since it does not contain a question mark"
)
Expand Down
15 changes: 15 additions & 0 deletions backend/danswer/danswerbot/slack/listener.py

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that the bot does not reply to messages tagged with channel

Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool
"Cannot respond to DanswerBot command without sender to respond to."
)
return False

payload = req.payload
event = payload.get("event", {})
blocks = event.get("blocks", [])
for block in blocks:
if block.get("type") == "rich_text":
for element in block.get("elements", []):
if element.get("type") == "rich_text_section":
for sub_element in element.get("elements", []):
if (
sub_element.get("type") == "broadcast"
and sub_element.get("range") == "channel"
):
logger.info("Broadcast message detected; skipping reply.")
return False

# Do not respond to messages if the channel is tagged
payload = req.payload
Expand Down