Skip to content

๐Ÿคฏ LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

4.4 KB
Raw Blame
/**
 * Feishu/Lark reactions are a **named enum**, not unicode.
 *
 * `POST /im/v1/messages/{id}/reactions` takes `reaction_type.emoji_type`
 * values like `OK` / `MUSCLE` / `FIRE` and rejects anything else with
 * `231001 reaction type is invalid`. Every other platform we support takes
 * unicode, so callers speak unicode โ€” this module is the single translation
 * point between them. Without it every reaction on Feishu/Lark fails, and
 * because both call sites swallow reaction errors the only symptom is that the
 * bot never appears to acknowledge anything.
 *
 * It lives in the adapter package, next to `LarkApiClient`, for the same reason
 * `decodeLarkThreadId` does: `LarkAdapter` and the server-side bot platform
 * client both need it, and two copies of an enum this fiddly would drift.
 *
 * Only enum names taken from Feishu's published emoji list appear here (the
 * `ๅธธ็”จๅ€ผ` table in `protocol-spec.md` ยง5.1, plus the full list it links to at
 * https://open.feishu.cn/document/server-docs/im-v1/message-reaction/emojis-introduce).
 * Do NOT add a value guessed from Feishu's UI โ€” an undocumented `emoji_type` is
 * just another `231001`. The casing is Feishu's own and is inconsistent on
 * purpose (`THUMBSUP` but `ThumbsDown`, `OnIt`, `CheckMark`, `Trophy`).
 */
const FEISHU_EMOJI_TYPES = [
  // ๆญฃ้ข / ่ฎคๅฏ
  'OK',
  'THUMBSUP',
  'THANKS',
  'MUSCLE',
  'APPLAUSE',
  'FISTBUMP',
  'JIAYI',
  'DONE',
  'LGTM',
  // ็ฌ‘่„ธ
  'SMILE',
  'LAUGH',
  'LOL',
  'LOVE',
  'WINK',
  'JOYFUL',
  'WOW',
  'YEAH',
  // ๆ‚ฒไผค
  'SOB',
  'CRY',
  'FROWN',
  'SPEECHLESS',
  // ๆ‰‹ๅŠฟ
  'ThumbsDown',
  'HIGHFIVE',
  'WAVE',
  'SALUTE',
  // ็‰ฉๅ“
  'HEART',
  'ROSE',
  'FIRE',
  'PARTY',
  'BEER',
  'CAKE',
  'GIFT',
  'Trophy',
  // ่ฟ›่กŒไธญ โ€” the states the bot bridge cycles through
  'OnIt',
  'THINKING',
  'Typing',
  'OneSecond',
  // ็ฌฆๅท
  'POOP',
  'HEARTBROKEN',
  'CheckMark',
  'CrossMark',
  'Hundred',
] as const;

/** Lower-cased enum name โ†’ the exact-cased value Feishu expects. */
const CANONICAL_BY_LOWERCASE = new Map(
  FEISHU_EMOJI_TYPES.map((name) => [name.toLowerCase(), name]),
);

/**
 * Unicode โ†’ Feishu `emoji_type`.
 *
 * The first three entries are what the bot bridge actually sends on every run
 * (`RECEIVED_REACTION_EMOJI` / `THINKING_REACTION_EMOJI` /
 * `WORKING_REACTION_EMOJI` in `../const.ts`) โ€” keep them mapped or the
 * progress reactions go dark again. The rest cover what an agent plausibly
 * passes to the `reactToMessage` tool, whose schema asks for unicode.
 */
const EMOJI_TYPE_BY_UNICODE: Record<string, (typeof FEISHU_EMOJI_TYPES)[number]> = {
  'โค': 'HEART',
  'โค๏ธ': 'HEART',
  'โšก': 'OnIt', // bridge: a tool call is running โ€” ใ€Œๅค„็†ไธญใ€
  'โœ…': 'CheckMark',
  'โŒ': 'CrossMark',
  '๐ŸŒน': 'ROSE',
  '๐ŸŽ': 'GIFT',
  '๐ŸŽ‚': 'CAKE',
  '๐ŸŽ‰': 'PARTY',
  '๐Ÿบ': 'BEER',
  '๐Ÿ‘€': 'OK', // bridge: the bot has picked the message up โ€” ใ€Œๅฅฝ็š„ใ€
  '๐Ÿ‘‹': 'WAVE',
  '๐Ÿ‘Œ': 'OK',
  '๐Ÿ‘': 'THUMBSUP',
  '๐Ÿ‘Ž': 'ThumbsDown',
  '๐Ÿ‘': 'APPLAUSE',
  '๐Ÿ‘Š': 'FISTBUMP',
  '๐Ÿ’”': 'HEARTBROKEN',
  '๐Ÿ’ฉ': 'POOP',
  '๐Ÿ’ช': 'MUSCLE',
  '๐Ÿ’ฏ': 'Hundred',
  '๐Ÿ”ฅ': 'FIRE',
  '๐Ÿ™': 'FROWN',
  '๐Ÿ™Œ': 'HIGHFIVE',
  '๐Ÿ™': 'THANKS',
  '๐Ÿค”': 'THINKING', // bridge: the agent is reasoning โ€” ใ€Œๆ€่€ƒใ€
  '๐Ÿคฃ': 'LOL',
  '๐Ÿฅณ': 'PARTY',
  '๐Ÿซก': 'SALUTE',
  '๐Ÿ˜€': 'SMILE',
  '๐Ÿ˜‚': 'LOL',
  '๐Ÿ˜„': 'SMILE',
  '๐Ÿ˜†': 'LAUGH',
  '๐Ÿ˜Š': 'SMILE',
  '๐Ÿ˜‰': 'WINK',
  '๐Ÿ˜': 'LOVE',
  '๐Ÿ˜ฎ': 'WOW',
  '๐Ÿ˜ฒ': 'WOW',
  '๐Ÿ˜ถ': 'SPEECHLESS',
  '๐Ÿ˜ข': 'CRY',
  '๐Ÿ˜ญ': 'SOB',
  '๐Ÿ†—': 'OK',
};

/**
 * Resolve a Feishu/Lark `emoji_type` from what a caller supplied.
 *
 * Accepts either a unicode emoji (what the bridge and the tool schema use) or
 * an `emoji_type` name the caller already knows, in any casing. Returns
 * `undefined` when there is no documented equivalent โ€” callers decide what
 * that means for them, but nobody may pass the raw input through: doing so is
 * a guaranteed `231001`.
 */
export const toFeishuEmojiType = (emoji: string | null | undefined): string | undefined => {
  if (!emoji) return undefined;
  const trimmed = emoji.trim();
  if (!trimmed) return undefined;
  return EMOJI_TYPE_BY_UNICODE[trimmed] ?? CANONICAL_BY_LOWERCASE.get(trimmed.toLowerCase());
};

/** Every `emoji_type` this module can produce, for error messages. */
export const supportedFeishuEmojiTypes = (): string[] => [...FEISHU_EMOJI_TYPES];