Skip to content

Commit f4dced3

Browse files
authored
Merge pull request #69 from odefun/feat/slack-settings-launcher-sync-17705642
feat: improve settings launcher and workspace sync
2 parents 098fce0 + 36752d5 commit f4dced3

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ode",
3-
"version": "0.0.41",
3+
"version": "0.0.42",
44
"description": "Ode - OpenCode chat controller for Slack",
55
"module": "packages/core/index.ts",
66
"type": "module",

packages/ims/slack/client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ async function postGeneralSettingsLauncher(
285285
await client.chat.postEphemeral({
286286
channel: channelId,
287287
user: userId,
288-
text: "Open general settings",
288+
text: "Open settings",
289289
blocks: [
290290
{
291291
type: "section",
292292
text: {
293293
type: "mrkdwn",
294-
text: "Open general settings for status message format and git strategy.",
294+
text: "Choose which settings page to open.",
295295
},
296296
},
297297
{
@@ -300,7 +300,13 @@ async function postGeneralSettingsLauncher(
300300
{
301301
type: "button",
302302
action_id: "open_general_settings_modal",
303-
text: { type: "plain_text", text: "Open settings" },
303+
text: { type: "plain_text", text: "general setting" },
304+
value: channelId,
305+
},
306+
{
307+
type: "button",
308+
action_id: "open_settings_modal",
309+
text: { type: "plain_text", text: "channel setting" },
304310
value: channelId,
305311
},
306312
],

packages/ims/slack/commands.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
getChannelAgentProvider,
44
getChannelModel,
55
resolveChannelCwd,
6+
getWorkspaces,
67
getEnabledAgentProviders,
78
getOpenCodeModels,
89
getCodexModels,
@@ -18,14 +19,17 @@ import {
1819
setGitHubInfoForUser,
1920
getUserGeneralSettings,
2021
setUserGeneralSettings,
22+
invalidateOdeConfigCache,
2123
} from "@/config";
2224
import { startServer as startOpenCodeServer } from "@/agents/opencode";
2325
import { startServer as startCodexServer } from "@/agents/codex";
26+
import { syncSlackWorkspace } from "@/core/web/local-settings";
2427

2528
const SETTINGS_LAUNCH_ACTION = "open_settings_modal";
2629
const SETTINGS_MODAL_ID = "settings_modal";
2730
const GENERAL_SETTINGS_LAUNCH_ACTION = "open_general_settings_modal";
2831
const GENERAL_SETTINGS_MODAL_ID = "general_settings_modal";
32+
const GENERAL_SYNC_WORKSPACE_ACTION = "general_sync_workspace";
2933
const GITHUB_LAUNCH_ACTION = "open_github_token_modal";
3034
const GITHUB_MODAL_ID = "github_token_modal";
3135
const GITHUB_TOKEN_BLOCK = "github_token";
@@ -361,6 +365,18 @@ function buildGeneralSettingsModal(params: {
361365
?? gitStrategyOptions[0],
362366
},
363367
},
368+
{
369+
type: "actions" as const,
370+
elements: [
371+
{
372+
type: "button" as const,
373+
action_id: GENERAL_SYNC_WORKSPACE_ACTION,
374+
text: { type: "plain_text" as const, text: "Sync Workspace" },
375+
style: "primary" as const,
376+
value: channelId,
377+
},
378+
],
379+
},
364380
],
365381
};
366382
}
@@ -447,6 +463,40 @@ export function setupInteractiveHandlers(): void {
447463
});
448464
});
449465

466+
slackApp.action(GENERAL_SYNC_WORKSPACE_ACTION, async ({ ack, body, client }) => {
467+
await ack();
468+
469+
const channelId = (body as any).actions?.[0]?.value
470+
?? (body as any).view?.private_metadata
471+
?? (body as any).channel?.id;
472+
const userId = (body as any).user?.id;
473+
if (!channelId || !userId) return;
474+
475+
const workspaces = getWorkspaces();
476+
const syncResults = await Promise.allSettled(
477+
workspaces.map(async (workspace) => syncSlackWorkspace(workspace.id))
478+
);
479+
480+
const successful = syncResults
481+
.filter((result): result is PromiseFulfilledResult<Awaited<ReturnType<typeof syncSlackWorkspace>>> => result.status === "fulfilled")
482+
.map((result) => result.value);
483+
const syncedWorkspaces = successful.length;
484+
const syncedChannels = successful.reduce((sum, workspace) => sum + (workspace.channels ?? workspace.channelDetails.length), 0);
485+
const failedWorkspaces = syncResults.length - syncedWorkspaces;
486+
487+
invalidateOdeConfigCache();
488+
489+
const message = failedWorkspaces > 0
490+
? `Synced ${syncedWorkspaces} workspaces with ${syncedChannels} channels in total. Failed to sync ${failedWorkspaces} workspaces.`
491+
: `Synced ${syncedWorkspaces} workspaces with ${syncedChannels} channels in total.`;
492+
493+
await client.chat.postEphemeral({
494+
channel: channelId,
495+
user: userId,
496+
text: message,
497+
});
498+
});
499+
450500
slackApp.action(PROVIDER_ACTION, async ({ ack, body, client }) => {
451501
await ack();
452502

0 commit comments

Comments
 (0)