import type { ReactionTypeEmoji } from "@grammyjs/types"; import { DEFAULT_EMOJIS, type StatusReactionEmojis } from "openclaw/plugin-sdk/channel-feedback"; import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime"; import type { TelegramChatDetails, TelegramGetChat } from "./bot/types.js";
type StatusReactionEmojiKey = keyof Required<StatusReactionEmojis>;
export type TelegramReactionEmoji = ReactionTypeEmoji["emoji"];
const TELEGRAM_GENERIC_REACTION_FALLBACKS = ["", "", ""] as const;
export function buildTelegramStatusReactionVariants(
emojis: Required<StatusReactionEmojis>,
): Map<string, string[]> { const variantsByRequested = new Map<string, string[]>(); for (const key of STATUS_REACTION_EMOJI_KEYS) { const requested = normalizeOptionalString(emojis[key]); if (!requested) { continue;
} const fallbackVariants = TELEGRAM_STATUS_REACTION_VARIANTS[key] ?? []; const candidates = toUniqueNonEmpty([requested, ...fallbackVariants]);
variantsByRequested.set(requested, candidates);
} return variantsByRequested;
}
export function isTelegramSupportedReactionEmoji(emoji: string): emoji is TelegramReactionEmoji { return TELEGRAM_SUPPORTED_REACTION_EMOJIS.has(emoji as TelegramReactionEmoji);
}
export function extractTelegramAllowedEmojiReactions(
chat: TelegramChatDetails | null | undefined,
): Set<TelegramReactionEmoji> | null | undefined { if (!chat) { return undefined;
} const availableReactions = chat.available_reactions; if (availableReactions === undefined) { return undefined;
} if (availableReactions == null) { // Explicitly omitted/null => all emoji reactions are allowed in this chat. returnnull;
} if (!Array.isArray(availableReactions)) { returnnew Set<TelegramReactionEmoji>();
}
const allowed = new Set<TelegramReactionEmoji>(); for (const reaction of availableReactions) { if (reaction.type !== "emoji") { continue;
} const emoji = reaction.emoji.trim(); if (emoji && isTelegramSupportedReactionEmoji(emoji)) {
allowed.add(emoji);
}
} return allowed;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.