Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

New room: take a pasted channel id as meant, whatever its case or spacing

Simon Flackc07969fd419e
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx
index c54941406..1412254d9 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx
@@ -208,6 +208,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
serverId,
workspaceId: workspaceId as string,
bridgeId,
+ bridgeType: selectedBridge?.type,
name,
description,
instructions,
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts
index 39b93baf5..4016cb7a1 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.test.ts
@@ -1,5 +1,10 @@
import { describe, expect, it } from 'vitest';
-import { channelChoiceCards, optionsForBridge, channelIdProblem } from './room-channel-choices';
+import {
+ channelChoiceCards,
+ optionsForBridge,
+ channelIdProblem,
+ normalizedChannelId,
+} from './room-channel-choices';
import { DEFAULT_ROOM_OPTIONS } from './room-create-request';
// Mattermost's shape (26 lowercase letters and digits), kept low-entropy so it reads as made up.
@@ -80,6 +85,16 @@ describe('channelIdProblem', () => {
expect(channelIdProblem('teams', '19%3aabc%40thread.tacv2')).toMatch(/%3a/);
});
+ it('takes an id differing only in case or surrounding space as meant', () => {
+ expect(channelIdProblem('slack', ' c0123abcd ')).toBeNull();
+ expect(normalizedChannelId('slack', ' c0123abcd ')).toBe('C0123ABCD');
+ expect(normalizedChannelId('mattermost', MATTERMOST_ID.toUpperCase())).toBe(
+ MATTERMOST_ID
+ );
+ // Teams ids are left as pasted, but for the space around them.
+ expect(normalizedChannelId('teams', ' 19:[email protected] ')).toBe('19:[email protected]');
+ });
+
it('says nothing for a blank id or a platform it does not know', () => {
expect(channelIdProblem('slack', ' ')).toBeNull();
expect(channelIdProblem('zulip', 'anything')).toBeNull();
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts
index d11ece197..47f78f643 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-channel-choices.ts
@@ -91,15 +91,28 @@ export function optionsForBridge(
* say, fails as it is read.
*/
export function channelIdProblem(bridgeType: string, id: string): string | null {
- const value = id.trim();
+ const value = normalizedChannelId(bridgeType, id);
if (value === '') return null;
const shape = CHANNEL_ID_SHAPE[bridgeType];
return shape && !shape.pattern.test(value) ? shape.problem : null;
}
+/**
+ * `id` as its app writes it: trimmed, and in the one case its app uses where
+ * that is known (Slack ids are upper case, Mattermost's lower), so a pasted
+ * id differing only in case or surrounding space is taken as meant.
+ */
+export function normalizedChannelId(bridgeType: string, id: string): string {
+ const value = id.trim();
+ if (bridgeType === 'slack') return value.toUpperCase();
+ if (bridgeType === 'mattermost') return value.toLowerCase();
+ return value;
+}
+
const CHANNEL_ID_SHAPE: Record<string, { pattern: RegExp; problem: string }> = {
slack: {
- pattern: /^[CG][A-Z0-9]{6,}$/,
+ // Letters and digits, always some digits: so a channel's name (GENERAL) is not taken for one.
+ pattern: /^[CG](?=[A-Z0-9]*\d)[A-Z0-9]{6,}$/,
problem:
'A Slack channel id starts with C or G, like C0123ABCD. It is at the bottom of the channel’s details.',
},
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts
index 0be3c8076..b7fc7624f 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts
@@ -77,12 +77,13 @@ describe('roomCreateRequest', () => {
});
});
- it('binds an existing channel by its id, trimmed', () => {
+ it('binds an existing channel by its id, written as its app writes it', () => {
const request = roomCreateRequest({
...form,
bridgeId: 'b1',
+ bridgeType: 'slack',
options: {
- channel: { kind: 'existing', externalChannelId: ' C123 ' },
+ channel: { kind: 'existing', externalChannelId: ' c123 ' },
groupId: null,
access: null,
},
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts
index 5396a93b0..3fafd7946 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts
@@ -1,5 +1,5 @@
import type { NewRoomChannel, RoomAccess } from '@shared/core/switch-servers/switch-servers';
-import { channelIdProblem } from './room-channel-choices';
+import { channelIdProblem, normalizedChannelId } from './room-channel-choices';
/** What the New room dialog asks the server for: a Switch Console chat when no messaging app is chosen, else a room bridged to the chosen one. */
export type RoomCreateRequest =
@@ -51,6 +51,8 @@ export function roomCreateRequest(form: {
workspaceId: string;
/** Null for Switch Console. */
bridgeId: string | null;
+ /** The chosen app's platform, so an existing channel's id is sent as it writes it. */
+ bridgeType?: string;
name: string;
description: string;
instructions: string;
@@ -85,15 +87,18 @@ export function roomCreateRequest(form: {
instructions: form.instructions.trim() || undefined,
bridgeId: form.bridgeId,
agentIds,
- ...roomOptionsParams(form.options ?? DEFAULT_ROOM_OPTIONS),
+ ...roomOptionsParams(form.options ?? DEFAULT_ROOM_OPTIONS, form.bridgeType ?? ''),
},
};
}
-function roomOptionsParams(options: RoomCreateOptions) {
+function roomOptionsParams(options: RoomCreateOptions, bridgeType: string) {
const channel: NewRoomChannel =
options.channel.kind === 'existing'
- ? { kind: 'existing', externalChannelId: options.channel.externalChannelId.trim() }
+ ? {
+ kind: 'existing',
+ externalChannelId: normalizedChannelId(bridgeType, options.channel.externalChannelId),
+ }
: options.channel;
return {
channel,
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx
index 8a0f4faba..ac587c776 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/create-room-modal-wiring.test.tsx
@@ -179,7 +179,8 @@ describe('New room dialog', () => {
expect(createButton(host).disabled).toBe(true);
expect(host.textContent).toContain('starts with C or G');
- await typeInto(channelIdInput(host)!, 'C0123ABCD');
+ // Pasted in lower case with space around it: taken as meant, and sent as Slack writes it.
+ await typeInto(channelIdInput(host)!, ' c0123abcd ');
expect(createButton(host).disabled).toBe(false);
await act(async () => createButton(host).click());