Move mattermost channel implementation from core to extensions/mattermost plugin. Extract config schema, group mentions, normalize utilities, and all mattermost-specific logic (accounts, client, monitor, probe, send) into the extension. Update imports to use plugin SDK and local modules. Add channel metadata directly in plugin definition instead of using getChatChannelMeta. Update package.json with channel and install configuration.
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
export function normalizeMattermostMessagingTarget(raw: string): string | undefined {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) return undefined;
|
|
const lower = trimmed.toLowerCase();
|
|
if (lower.startsWith("channel:")) {
|
|
const id = trimmed.slice("channel:".length).trim();
|
|
return id ? `channel:${id}` : undefined;
|
|
}
|
|
if (lower.startsWith("group:")) {
|
|
const id = trimmed.slice("group:".length).trim();
|
|
return id ? `channel:${id}` : undefined;
|
|
}
|
|
if (lower.startsWith("user:")) {
|
|
const id = trimmed.slice("user:".length).trim();
|
|
return id ? `user:${id}` : undefined;
|
|
}
|
|
if (lower.startsWith("mattermost:")) {
|
|
const id = trimmed.slice("mattermost:".length).trim();
|
|
return id ? `user:${id}` : undefined;
|
|
}
|
|
if (trimmed.startsWith("@")) {
|
|
const id = trimmed.slice(1).trim();
|
|
return id ? `user:${id}` : undefined;
|
|
}
|
|
if (trimmed.startsWith("#")) {
|
|
const id = trimmed.slice(1).trim();
|
|
return id ? `channel:${id}` : undefined;
|
|
}
|
|
return `channel:${trimmed}`;
|
|
}
|
|
|
|
export function looksLikeMattermostTargetId(raw: string): boolean {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) return false;
|
|
if (/^(user|channel|group|mattermost):/i.test(trimmed)) return true;
|
|
if (/^[@#]/.test(trimmed)) return true;
|
|
return /^[a-z0-9]{8,}$/i.test(trimmed);
|
|
}
|