@@ -1700,6 +1700,41 @@ def test_telegram_webhook_non_command_message_is_ignored(self):
17001700 conn .close ()
17011701 self .assertEqual (total , 0 )
17021702
1703+ def test_telegram_webhook_command_reply_stays_in_forum_topic (self ):
1704+ from app .web .routes import main_routes
1705+
1706+ clients = []
1707+
1708+ def _fake_send_message (client , message ):
1709+ clients .append ((client .chat_id , client .thread_id , message ))
1710+ return True
1711+
1712+ old_secret = main_routes .TELEGRAM_WEBHOOK_SECRET
1713+ old_token = main_routes .TELEGRAM_BOT_TOKEN
1714+ main_routes .TELEGRAM_WEBHOOK_SECRET = "hook-secret"
1715+ main_routes .TELEGRAM_BOT_TOKEN = "bot-token"
1716+ try :
1717+ with patch .object (main_routes .TelegramClient , "send_message" , new = _fake_send_message ):
1718+ response = self .client .post (
1719+ "/telegram/webhook/hook-secret" ,
1720+ json = {
1721+ "message" : {
1722+ "text" : "/help" ,
1723+ "from" : {"username" : "admin" },
1724+ "chat" : {"id" : - 100123 , "type" : "supergroup" },
1725+ "message_thread_id" : 42 ,
1726+ }
1727+ },
1728+ )
1729+ finally :
1730+ main_routes .TELEGRAM_WEBHOOK_SECRET = old_secret
1731+ main_routes .TELEGRAM_BOT_TOKEN = old_token
1732+
1733+ self .assertEqual (response .status_code , 200 )
1734+ self .assertEqual (len (clients ), 1 )
1735+ self .assertEqual (clients [0 ][:2 ], ("-100123" , "42" ))
1736+ self .assertIn ("ManaVote bot is running" , clients [0 ][2 ])
1737+
17031738 def test_telegram_webhook_supports_edited_message_payload (self ):
17041739 poll_id = self ._latest_poll_id ()
17051740 from app .web .routes import main_routes
0 commit comments