Ignore messages from Slack's official bot (#1703)

* Ignore messages from Slack's official bot

* re-added message filter
This commit is contained in:
hagen-danswer 2024-06-25 20:33:36 -07:00 committed by GitHub
parent 5d552705aa
commit 8c6cd661f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -56,7 +56,6 @@ from shared_configs.configs import MODEL_SERVER_PORT
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.
@ -70,6 +69,9 @@ _SLACK_GREETINGS_TO_IGNORE = {
":wave:",
}
# this is always (currently) the user id of Slack's official slackbot
_OFFICIAL_SLACKBOT_USER_ID = "USLACKBOT"
def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool:
"""True to keep going, False to ignore this Slack request"""
@ -92,6 +94,15 @@ def prefilter_requests(req: SocketModeRequest, client: SocketModeClient) -> bool
channel_specific_logger.error("Cannot respond to empty message - skipping")
return False
if (
req.payload.setdefault("event", {}).get("user", "")
== _OFFICIAL_SLACKBOT_USER_ID
):
channel_specific_logger.info(
"Ignoring messages from Slack's official Slackbot"
)
return False
if (
msg in _SLACK_GREETINGS_TO_IGNORE
or remove_danswer_bot_tag(msg, client=client.web_client)