Catch Slack Greeting Msgs Generic (#1633)

This commit is contained in:
Yuhong Sun
2024-06-13 09:41:01 -07:00
committed by GitHub
parent 428439447e
commit 26fee36ed4

View File

@@ -57,6 +57,20 @@ from shared_configs.configs import MODEL_SERVER_PORT
logger = setup_logger() 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: def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool:
"""True to keep going, False to ignore this Slack request""" """True to keep going, False to ignore this Slack request"""
if req.type == "events_api": if req.type == "events_api":
@@ -78,6 +92,19 @@ def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool
channel_specific_logger.error("Cannot respond to empty message - skipping") channel_specific_logger.error("Cannot respond to empty message - skipping")
return False 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 # Ensure that the message is a new message of expected type
event_type = event.get("type") event_type = event.get("type")
if event_type not in ["app_mention", "message"]: if event_type not in ["app_mention", "message"]: