@@ -554,6 +554,63 @@ async def test_telegram_mentions_use_original_utf16_offsets(
554554 )
555555
556556
557+ @pytest .mark .asyncio
558+ @pytest .mark .parametrize ("in_caption" , [False , True ], ids = ["text" , "photo-caption" ])
559+ @pytest .mark .parametrize (
560+ "name" , ["ExampleBot" , "examplebot" , "EXAMPLEBOT" , "eXaMpLeBoT" , "OtherBot" ]
561+ )
562+ async def test_telegram_self_mention_is_case_insensitive (in_caption , name ):
563+ """Normalize self-mention IDs while preserving the original display name.
564+
565+ Args:
566+ in_caption: Whether the mention appears in a photo caption.
567+ name: Username spelling used in the incoming mention.
568+ """
569+ adapter = _load_telegram_adapter ()(
570+ make_platform_config ("telegram" ), {}, asyncio .Queue ()
571+ )
572+ context = _build_context ()
573+ context .bot .username = "ExampleBot"
574+ text = f"😀 @{ name } hello"
575+ sdk_message = Message .de_json (
576+ {
577+ "message_id" : 1 ,
578+ "date" : 0 ,
579+ "chat" : {"id" : - 100123 , "type" : "supergroup" },
580+ "caption" if in_caption else "text" : text ,
581+ "caption_entities" if in_caption else "entities" : [
582+ {"type" : "mention" , "offset" : 3 , "length" : len (name ) + 1 }
583+ ],
584+ },
585+ bot = None ,
586+ )
587+ if in_caption :
588+ update = create_mock_update (
589+ message_text = None ,
590+ chat_type = "supergroup" ,
591+ photo = [create_mock_file ()],
592+ caption = text ,
593+ caption_entities = sdk_message .caption_entities ,
594+ )
595+ update .message .parse_caption_entity = sdk_message .parse_caption_entity
596+ else :
597+ update = create_mock_update (
598+ message_text = text , chat_type = "supergroup" , entities = sdk_message .entities
599+ )
600+ update .message .parse_entity = sdk_message .parse_entity
601+
602+ result = await adapter .convert_message (update , context )
603+
604+ assert result is not None
605+ mentions = [part for part in result .message if isinstance (part , Comp .At )]
606+ assert len (mentions ) == 1
607+ is_self = name != "OtherBot"
608+ assert mentions [0 ].qq == ("ExampleBot" if is_self else name )
609+ assert mentions [0 ].name == name
610+ assert (mentions [0 ].qq == result .self_id ) is is_self
611+ assert result .message_str == (text if in_caption or not is_self else "😀 hello" )
612+
613+
557614@pytest .mark .asyncio
558615@pytest .mark .parametrize ("media_type" , ["photo" , "document" , "video" ])
559616async def test_telegram_media_caption_mention_uses_utf16_offsets (media_type ):
0 commit comments