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): avoid rate-limit by defaulting to bot-member channels

yh c0ecfa2dc6dd9
diff --git a/ui/src/components/steps/ChannelList.tsx b/ui/src/components/steps/ChannelList.tsx
index 75e06032f..d73e06aad 100644
--- a/ui/src/components/steps/ChannelList.tsx
+++ b/ui/src/components/steps/ChannelList.tsx
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
-import { Hash, CheckSquare, Square, RefreshCw, HelpCircle } from 'lucide-react';
+import { Hash, CheckSquare, Square, RefreshCw, HelpCircle, Globe } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { useApi } from '../../context/ApiContext';
import { useToast } from '../../context/ToastContext';
@@ -54,6 +54,8 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
const { showToast } = useToast();
const [loading, setLoading] = useState(false);
const [channels, setChannels] = useState<any[]>([]);
+ const [browseAll, setBrowseAll] = useState(false);
+ const [loadingAll, setLoadingAll] = useState(false);
const [configs, setConfigs] = useState<Record<string, ChannelConfig>>(data.channelConfigs || {});
const [config, setConfig] = useState<any>(data);
const [opencodeOptionsByCwd, setOpencodeOptionsByCwd] = useState<Record<string, any>>({});
@@ -81,18 +83,25 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
const botToken = config.slack?.bot_token || config.slackBotToken || '';
- const loadChannels = async () => {
+ const loadChannels = async (all?: boolean) => {
if (!botToken) return;
- setLoading(true);
+ const isAll = all ?? browseAll;
+ if (isAll) {
+ setLoadingAll(true);
+ } else {
+ setLoading(true);
+ }
try {
- const result = await api.slackChannels(botToken);
+ const result = await api.slackChannels(botToken, isAll);
if (result.ok) {
setChannels(result.channels || []);
+ if (isAll) setBrowseAll(true);
}
} catch (e) {
console.error('Failed to load channels:', e);
} finally {
setLoading(false);
+ setLoadingAll(false);
}
};
@@ -290,11 +299,24 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<button
- onClick={loadChannels}
+ onClick={() => loadChannels(browseAll)}
className="flex items-center gap-2 px-3 py-1.5 bg-neutral-100 hover:bg-neutral-200 text-text rounded text-sm font-medium transition-colors"
>
<RefreshCw size={14} className={loading ? 'animate-spin' : ''} /> {t('channelList.refreshList')}
</button>
+ {!browseAll && (
+ <button
+ onClick={() => loadChannels(true)}
+ disabled={loadingAll}
+ className="flex items-center gap-2 px-3 py-1.5 bg-neutral-100 hover:bg-neutral-200 text-text rounded text-sm font-medium transition-colors disabled:opacity-50"
+ >
+ <Globe size={14} className={loadingAll ? 'animate-spin' : ''} />
+ {loadingAll ? t('common.loading') : t('channelList.browseAll')}
+ </button>
+ )}
+ {browseAll && (
+ <span className="text-xs text-muted">{t('channelList.showingAll')}</span>
+ )}
<span className="relative group">
<span className="flex items-center gap-1 text-sm text-muted cursor-help">
<HelpCircle size={14} />
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index 4cfa9e816..3fc03897b 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -9,7 +9,7 @@ export type ApiContextType = {
detectCli: (binary: string) => Promise<any>;
installAgent: (name: string) => Promise<InstallResult>;
slackAuthTest: (botToken: string) => Promise<any>;
- slackChannels: (botToken: string) => Promise<any>;
+ slackChannels: (botToken: string, browseAll?: boolean) => Promise<any>;
slackManifest: () => Promise<{ ok: boolean; manifest?: string; manifest_compact?: string; error?: string }>;
doctor: () => Promise<any>;
opencodeOptions: (cwd: string) => Promise<any>;
@@ -116,7 +116,7 @@ export const ApiProvider: React.FC<{ children: React.ReactNode }> = ({ children
detectCli: (binary) => getJson(`/cli/detect?binary=${encodeURIComponent(binary)}`),
installAgent: (name) => postJson(`/agent/${encodeURIComponent(name)}/install`, {}),
slackAuthTest: (botToken) => postJson('/slack/auth_test', { bot_token: botToken }),
- slackChannels: (botToken) => postJson('/slack/channels', { bot_token: botToken }),
+ slackChannels: (botToken, browseAll) => postJson('/slack/channels', { bot_token: botToken, browse_all: browseAll || false }),
slackManifest: () => getJson('/slack/manifest'),
doctor: () => postJson('/doctor', {}),
opencodeOptions: (cwd) => postJson('/opencode/options', { cwd }),
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index bb2ecd7df..24218b3ff 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -128,6 +128,8 @@
"title": "Channel Settings",
"subtitle": "Enable channels and configure per-channel routing.",
"refreshList": "Refresh List",
+ "browseAll": "Browse All Channels",
+ "showingAll": "Showing all workspace channels",
"cantFindChannel": "Can't find your channel?",
"inviteBotHint": "Invite the bot to your channel first:\n1. Open the channel, click ⚙️ Settings → Integrations → Add apps\n2. Or type /invite @YourBotName in the channel",
"enabledCount": "{{count}} enabled",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index ad167f387..6aebe71e6 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -128,6 +128,8 @@
"title": "频道设置",
"subtitle": "启用频道并配置每个频道的路由",
"refreshList": "刷新列表",
+ "browseAll": "浏览所有频道",
+ "showingAll": "已显示工作区所有频道",
"cantFindChannel": "找不到你想要的频道?",
"inviteBotHint": "请先将 Bot 邀请到频道:\n1. 打开频道,点击 ⚙️ 设置 → 集成 → 添加应用\n2. 或在频道中输入 /invite @你的Bot名称",
"enabledCount": "已启用 {{count}} 个",
diff --git a/vibe/api.py b/vibe/api.py
index 20a326bf2..364bae3d6 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -132,19 +132,64 @@ def slack_auth_test(bot_token: str) -> dict:
return {"ok": False, "error": str(exc)}
-def list_channels(bot_token: str) -> dict:
- try:
- from slack_sdk.web import WebClient
+def list_channels(bot_token: str, browse_all: bool = False) -> dict:
+ """List Slack channels.
- client = WebClient(token=bot_token)
- channels = []
- cursor = None
+ When *browse_all* is False (default), only channels the bot has joined are
+ returned via ``users_conversations``. This is very fast and avoids hitting
+ Slack rate-limits even in large workspaces.
+
+ When *browse_all* is True, all visible channels in the workspace are
+ returned via ``conversations_list``. Rate-limit retries with exponential
+ back-off are applied automatically.
+ """
+ import time
+
+ from slack_sdk.errors import SlackApiError
+ from slack_sdk.web import WebClient
+
+ client = WebClient(token=bot_token)
+ channels: list[dict] = []
+ cursor = None
+
+ try:
while True:
- response = client.conversations_list(
- types="public_channel,private_channel",
- limit=200,
- cursor=cursor,
- )
+ for attempt in range(5):
+ try:
+ if browse_all:
+ response = client.conversations_list(
+ types="public_channel,private_channel",
+ exclude_archived=True,
+ limit=200,
+ cursor=cursor,
+ )
+ else:
+ response = client.users_conversations(
+ types="public_channel,private_channel",
+ exclude_archived=True,
+ limit=200,
+ cursor=cursor,
+ )
+ break # success
+ except SlackApiError as e:
+ if e.response.status_code == 429:
+ retry_after = int(e.response.headers.get("Retry-After", 1))
+ wait = max(retry_after, 2**attempt)
+ logger.warning(
+ "Slack rate-limited (429), retrying after %ds (attempt %d/5)",
+ wait,
+ attempt + 1,
+ )
+ time.sleep(wait)
+ else:
+ raise
+ else:
+ # Exhausted retries
+ return {
+ "ok": False,
+ "error": "Slack rate-limit exceeded after 5 retries",
+ }
+
for channel in response.get("channels", []):
channels.append(
{
@@ -156,7 +201,8 @@ def list_channels(bot_token: str) -> dict:
cursor = response.get("response_metadata", {}).get("next_cursor")
if not cursor:
break
- return {"ok": True, "channels": channels}
+
+ return {"ok": True, "channels": channels, "is_member_only": not browse_all}
except Exception as exc:
return {"ok": False, "error": str(exc)}
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index e6983a6ea..ecea3c41a 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -263,7 +263,12 @@ def slack_channels():
from vibe import api
payload = request.json or {}
- return jsonify(api.list_channels(payload.get("bot_token", "")))
+ return jsonify(
+ api.list_channels(
+ payload.get("bot_token", ""),
+ browse_all=payload.get("browse_all", False),
+ )
+ )
@app.route("/doctor", methods=["POST"])