mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 21:40:53 +00:00
Merged via squash.
Prepared head SHA: 8a25e60872
Co-authored-by: tonydehnke <36720180+tonydehnke@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
51 lines
1.7 KiB
TypeScript
51 lines
1.7 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 ? `@${id}` : undefined;
|
|
}
|
|
if (trimmed.startsWith("#")) {
|
|
// Strip # prefix and fall through to directory lookup (same as bare names).
|
|
// The core's resolveMessagingTarget will use the directory adapter to
|
|
// resolve the channel name to its Mattermost ID.
|
|
return undefined;
|
|
}
|
|
// Bare name without prefix — return undefined to allow directory lookup
|
|
return undefined;
|
|
}
|
|
|
|
export function looksLikeMattermostTargetId(raw: string, normalized?: string): boolean {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return false;
|
|
}
|
|
if (/^(user|channel|group|mattermost):/i.test(trimmed)) {
|
|
return true;
|
|
}
|
|
if (trimmed.startsWith("@")) {
|
|
return true;
|
|
}
|
|
// Mattermost IDs: 26-char alnum, or DM channels like "abc123__xyz789" (53 chars)
|
|
return /^[a-z0-9]{26}$/i.test(trimmed) || /^[a-z0-9]{26}__[a-z0-9]{26}$/i.test(trimmed);
|
|
}
|