Skip to content

Commit

Permalink
Catch Slack Greeting Msgs Generic (onyx-dot-app#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhongsun96 authored Jun 13, 2024
1 parent 4284394 commit 26fee36
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/danswer/danswerbot/slack/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
logger = setup_logger()


# In rare cases, some users have been experiencing a massive amount of trivial messages coming through
# to the Slack Bot with trivial messages. Adding this to avoid exploding LLM costs while we track down
# the cause.
_SLACK_GREETINGS_TO_IGNORE = {
"Welcome back!",
"It's going to be a great day.",
"Salutations!",
"Greetings!",
"Feeling great!",
"Hi there",
":wave:",
}


def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool:
"""True to keep going, False to ignore this Slack request"""
if req.type == "events_api":
Expand All @@ -78,6 +92,19 @@ def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool
channel_specific_logger.error("Cannot respond to empty message - skipping")
return False

if (
msg in _SLACK_GREETINGS_TO_IGNORE
or remove_danswer_bot_tag(msg, client=client.web_client)
in _SLACK_GREETINGS_TO_IGNORE
):
channel_specific_logger.error(
f"Ignoring weird Slack greeting message: '{msg}'"
)
channel_specific_logger.error(
f"Weird Slack greeting message payload: '{req.payload}'"
)
return False

# Ensure that the message is a new message of expected type
event_type = event.get("type")
if event_type not in ["app_mention", "message"]:
Expand Down

0 comments on commit 26fee36

Please sign in to comment.