fix: strip variation selectors in Telegram emoji reactions (#499)
This commit is contained in:
34
src/channels/telegram.test.ts
Normal file
34
src/channels/telegram.test.ts
Normal 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: '❤' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -617,7 +617,7 @@ export class TelegramAdapter implements ChannelAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async addReaction(chatId: string, messageId: string, emoji: string): Promise<void> {
|
async addReaction(chatId: string, messageId: string, emoji: string): Promise<void> {
|
||||||
const resolved = resolveEmoji(emoji);
|
const resolved = resolveTelegramEmoji(emoji);
|
||||||
if (!TELEGRAM_REACTION_SET.has(resolved)) {
|
if (!TELEGRAM_REACTION_SET.has(resolved)) {
|
||||||
throw new Error(`Unsupported Telegram reaction emoji: ${resolved}`);
|
throw new Error(`Unsupported Telegram reaction emoji: ${resolved}`);
|
||||||
}
|
}
|
||||||
@@ -810,6 +810,13 @@ function extractTelegramReaction(reaction?: {
|
|||||||
return null;
|
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 = [
|
const TELEGRAM_REACTION_EMOJIS = [
|
||||||
'👍', '👎', '❤', '🔥', '🥰', '👏', '😁', '🤔', '🤯', '😱', '🤬', '😢',
|
'👍', '👎', '❤', '🔥', '🥰', '👏', '😁', '🤔', '🤯', '😱', '🤬', '😢',
|
||||||
'🎉', '🤩', '🤮', '💩', '🙏', '👌', '🕊', '🤡', '🥱', '🥴', '😍', '🐳',
|
'🎉', '🤩', '🤮', '💩', '🙏', '👌', '🕊', '🤡', '🥱', '🥴', '😍', '🐳',
|
||||||
|
|||||||
Reference in New Issue
Block a user