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): read sdk response objects

cyhc16c098a8996
diff --git a/modules/im/slack.py b/modules/im/slack.py
index 5ef0bc672..1649e5ef9 100644
--- a/modules/im/slack.py
+++ b/modules/im/slack.py
@@ -351,6 +351,16 @@ class SlackBot(BaseIMClient):
return True
return self._channel_looks_like_dm(context.channel_id)
+ @staticmethod
+ def _slack_response_get(response: Any, key: str) -> Any:
+ getter = getattr(response, "get", None)
+ if callable(getter):
+ return getter(key)
+ try:
+ return response[key]
+ except Exception:
+ return None
+
async def _get_channel_info_cached(self, channel_id: Optional[str]) -> Dict[str, Any]:
if not channel_id:
return {}
@@ -365,7 +375,7 @@ class SlackBot(BaseIMClient):
try:
response = await conversations_info(channel=channel_id)
- channel = response.get("channel") if isinstance(response, dict) else None
+ channel = self._slack_response_get(response, "channel")
if isinstance(channel, dict):
self._channel_info_cache[channel_id] = channel
return channel
@@ -740,7 +750,7 @@ class SlackBot(BaseIMClient):
try:
response = await self.web_client.files_info(file=file_id)
- slack_file = response.get("file") if isinstance(response, dict) else None
+ slack_file = self._slack_response_get(response, "file")
if not isinstance(slack_file, dict) or not slack_file:
return file_info
resolved = {**file_info, **slack_file}
diff --git a/tests/test_slack_app_mention_empty.py b/tests/test_slack_app_mention_empty.py
index e884bf7b4..14158d8d2 100644
--- a/tests/test_slack_app_mention_empty.py
+++ b/tests/test_slack_app_mention_empty.py
@@ -104,6 +104,14 @@ _install_slack_stubs()
SlackBot = _load_local_slack_bot()
+class _ResponseLike:
+ def __init__(self, data):
+ self._data = data
+
+ def get(self, key, default=None):
+ return self._data.get(key, default)
+
+
class SlackAppMentionEmptyTests(unittest.IsolatedAsyncioTestCase):
async def test_empty_app_mention_does_not_activate_or_dispatch(self):
slack = SlackBot(SlackConfig(bot_token="xoxb-test"))
@@ -152,13 +160,13 @@ class SlackFileAttachmentTests(unittest.IsolatedAsyncioTestCase):
slack = SlackBot(SlackConfig(bot_token="xoxb-test"))
slack.web_client = SimpleNamespace(
files_info=AsyncMock(
- return_value={
+ return_value=_ResponseLike({
"file": {
"id": "F123",
"name": "report.pdf",
"url_private_download": "https://files.slack.test/report.pdf",
}
- }
+ })
)
)
diff --git a/tests/test_slack_dm_mentions.py b/tests/test_slack_dm_mentions.py
index d4c8a9946..28eafd2eb 100644
--- a/tests/test_slack_dm_mentions.py
+++ b/tests/test_slack_dm_mentions.py
@@ -116,6 +116,14 @@ _install_slack_stubs()
from modules.im.slack import SlackBot
+class _ResponseLike:
+ def __init__(self, data):
+ self._data = data
+
+ def get(self, key, default=None):
+ return self._data.get(key, default)
+
+
class SlackDmMentionTests(unittest.IsolatedAsyncioTestCase):
async def test_send_message_recovers_dm_channel_after_channel_not_found(self):
slack = SlackBot(SlackConfig(bot_token="xoxb-test"))
@@ -789,7 +797,7 @@ class SlackDmMentionTests(unittest.IsolatedAsyncioTestCase):
class _WebClient:
async def conversations_info(self, channel):
- return {"channel": {"id": channel, "is_ext_shared": True}}
+ return _ResponseLike({"channel": {"id": channel, "is_ext_shared": True}})
async def _on_message(context, text):
received["text"] = text