Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(slack): identify own bot without app id

cyh166c29b84c89
diff --git a/modules/im/slack.py b/modules/im/slack.py
index c70f8dcd5..97f7df29b 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -77,6 +77,8 @@ class SlackBot(BaseIMClient):
self._user_info_cache: Dict[str, Dict[str, Any]] = {}
self._channel_info_cache: Dict[str, Dict[str, Any]] = {}
self._bot_user_id: Optional[str] = None
+ self._bot_id: Optional[str] = None
+ self._bot_identity_lookup_attempted = False
self._stop_event: Optional[asyncio.Event] = None
self._loop: Optional[asyncio.AbstractEventLoop] = None
self._on_ready: Optional[Callable] = None
@@ -283,27 +285,40 @@ class SlackBot(BaseIMClient):
payload_user_id = self._extract_bot_user_id_from_payload(payload or {})
if payload_user_id:
self._bot_user_id = payload_user_id
+ if not self._bot_id:
+ await self._hydrate_bot_identity()
return payload_user_id
if self._bot_user_id:
+ if not self._bot_id:
+ await self._hydrate_bot_identity()
return self._bot_user_id
+ await self._hydrate_bot_identity()
+ return self._bot_user_id
+
+ async def _hydrate_bot_identity(self) -> None:
+ if (self._bot_user_id and self._bot_id) or self._bot_identity_lookup_attempted:
+ return
+
self._ensure_clients()
auth_test = getattr(self.web_client, "auth_test", None)
if not callable(auth_test):
- return None
+ return
try:
response = await auth_test()
except Exception as exc:
- logger.debug("Failed to resolve Slack bot user id: %s", exc)
- return None
+ logger.debug("Failed to resolve Slack bot identity: %s", exc)
+ return
- user_id = response.get("user_id") if isinstance(response, dict) else None
+ self._bot_identity_lookup_attempted = True
+ user_id = self._slack_response_get(response, "user_id")
if isinstance(user_id, str) and user_id:
self._bot_user_id = user_id
- return user_id
- return None
+ bot_id = self._slack_response_get(response, "bot_id")
+ if isinstance(bot_id, str) and bot_id:
+ self._bot_id = bot_id
@staticmethod
def _has_specific_mention(text: str, user_id: Optional[str]) -> bool:
@@ -357,6 +372,8 @@ class SlackBot(BaseIMClient):
return True
if bot_user_id and bot_profile.get("user_id") == bot_user_id:
return True
+ if self._bot_id and event.get("bot_id") == self._bot_id:
+ return True
config_app_id = getattr(self.config, "app_id", None)
if config_app_id and event.get("app_id") == config_app_id:
return True
diff --git a/tests/test_slack_dm_mentions.py b/tests/test_slack_dm_mentions.py
index b107982b5..1dc9fb7fc 100644
--- a/tests/test_slack_dm_mentions.py
+++ b/tests/test_slack_dm_mentions.py
@@ -949,6 +949,37 @@ class SlackDmMentionTests(unittest.IsolatedAsyncioTestCase):
self.assertFalse(received["called"])
+ async def test_own_bot_message_with_auth_test_bot_id_is_ignored_without_app_id(self):
+ slack = SlackBot(SlackConfig(bot_token="xoxb-test"))
+ received = {"called": False}
+
+ class _WebClient:
+ async def auth_test(self):
+ return {"user_id": "U_BOT", "bot_id": "B_SELF"}
+
+ async def _on_message(_context, _text):
+ received["called"] = True
+
+ slack.web_client = _WebClient()
+ slack.register_callbacks(on_message=_on_message)
+
+ payload = {
+ "event_id": "evt-own-bot-auth-bot-id",
+ "team_id": "T1",
+ "authorizations": [{"user_id": "U_BOT"}],
+ "event": {
+ "type": "message",
+ "channel": "C_CONNECT",
+ "bot_id": "B_SELF",
+ "text": "<@U_BOT> loop",
+ "ts": "1710000000.000359",
+ },
+ }
+
+ await slack._handle_event(payload)
+
+ self.assertFalse(received["called"])
+
async def test_slack_connect_channel_mention_marks_thread_active(self):
slack = SlackBot(SlackConfig(bot_token="xoxb-test", require_mention=True))
marked = []