fix: strip variation selectors in Telegram emoji reactions (#499)

This commit is contained in:
Cameron
2026-03-06 09:34:18 -08:00
committed by GitHub
parent c018369cae
commit ef2302b2aa
2 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { TelegramAdapter } from './telegram.js';
describe('TelegramAdapter reactions', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('strips variation selectors before sending unicode heart reactions', async () => {
const adapter = new TelegramAdapter({ token: 'test-token' });
const setReaction = vi
.spyOn(adapter.getBot().api, 'setMessageReaction')
.mockImplementation(async () => true as any);
await adapter.addReaction('123', '456', '❤️');
expect(setReaction).toHaveBeenCalledWith('123', 456, [
{ type: 'emoji', emoji: '❤' },
]);
});
it("normalizes the heart alias to Telegram's bare-heart reaction", async () => {
const adapter = new TelegramAdapter({ token: 'test-token' });
const setReaction = vi
.spyOn(adapter.getBot().api, 'setMessageReaction')
.mockImplementation(async () => true as any);
await adapter.addReaction('123', '456', 'heart');
expect(setReaction).toHaveBeenCalledWith('123', 456, [
{ type: 'emoji', emoji: '❤' },
]);
});
});

View File

@@ -617,7 +617,7 @@ export class TelegramAdapter implements ChannelAdapter {
}
async addReaction(chatId: string, messageId: string, emoji: string): Promise<void> {
const resolved = resolveEmoji(emoji);
const resolved = resolveTelegramEmoji(emoji);
if (!TELEGRAM_REACTION_SET.has(resolved)) {
throw new Error(`Unsupported Telegram reaction emoji: ${resolved}`);
}
@@ -810,6 +810,13 @@ function extractTelegramReaction(reaction?: {
return null;
}
function resolveTelegramEmoji(input: string): string {
const resolved = resolveEmoji(input);
// Strip variation selectors (U+FE0E / U+FE0F). Telegram's reaction API
// expects bare emoji without them (e.g. ❤ not ❤️).
return resolved.replace(/[\uFE0E\uFE0F]/g, '');
}
const TELEGRAM_REACTION_EMOJIS = [
'👍', '👎', '❤', '🔥', '🥰', '👏', '😁', '🤔', '🤯', '😱', '🤬', '😢',
'🎉', '🤩', '🤮', '💩', '🙏', '👌', '🕊', '🤡', '🥱', '🥴', '😍', '🐳',