Skip to content

Commit

Permalink
[INTPROD-9204] Allow Match By Bot User ID
Browse files Browse the repository at this point in the history
  • Loading branch information
colinsl committed Apr 4, 2024
1 parent def86ae commit 3613ae8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions omnibot/services/slack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,29 @@ def get_user(bot, user_id):
),
)
return {}


def get_auth(bot):
"""
Get the auth info for the bot.
"""
redis_client = omniredis.get_redis_client()
auth_info = redis_client.hget(f"auth:{bot.team.name}", bot.name)
if auth_info:
return json.loads(auth_info)
auth_info = client(bot).api_call("auth.test")
if auth_info["ok"]:
redis_client.hset(f"auth:{bot.team.name}", bot.id, json.dumps(auth_info))
return auth_info
else:
logger.warning(
"Failed to get auth info",
extra=merge_logging_context(
_get_failure_context(auth_info),
bot.logging_context,
),
)
return {}


def get_name_from_user(user):
Expand Down
10 changes: 10 additions & 0 deletions omnibot/services/slack/bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from omnibot import settings
from omnibot.services.slack import get_auth
from omnibot.services.slack.team import Team
from omnibot.utils import merge_logging_context

Expand Down Expand Up @@ -82,6 +83,15 @@ def name(self):
@property
def bot_id(self):
return self._bot_data.get("app_id")

@property
def user_id(self):
user_id = self._bot_data.get("user_id")
if not user_id:
user_id = get_auth(self).get("user_id")
if user_id:
self._bot_data["user_id"] = user_id
return user_id

@property
def verification_token(self):
Expand Down
2 changes: 2 additions & 0 deletions omnibot/services/slack/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def _parse_payload(self):
for user_id, user_name in self.users.items():
if self.bot.name == user_name:
self._payload["mentioned"] = True
if self.bot.user_id == f"<@{user_id}>":
self._payload["mentioned"] = True
try:
self._payload["command_text"] = parser.extract_command(
# Similar to mentions above, we find the command text
Expand Down

0 comments on commit 3613ae8

Please sign in to comment.