diff --git a/contact/message_handlers/bot_handler.py b/contact/message_handlers/bot_handler.py index a180d9c..0c76f84 100644 --- a/contact/message_handlers/bot_handler.py +++ b/contact/message_handlers/bot_handler.py @@ -6,6 +6,7 @@ from typing import Any, Dict import contact.ui.default_config as config from contact.utilities.singleton import app_state, interface_state +from contact.utilities.utils import get_reply_context from contact.message_handlers.tx_handler import send_message BOT_RESPONSE_DELAY_SECONDS = 2.3 @@ -81,7 +82,13 @@ def bot_respond(packet: Dict[str, Any], message: str, send_channel: int) -> bool # Use the triggering packet's ID so Meshtastic clients render this # automatic response as a native reply when that ID is available. - send_message(response_data_string, channel=send_channel, reply_id=packet_id) + reply_context = get_reply_context(packet_id) if packet_id is not None else "" + send_message( + response_data_string, + channel=send_channel, + reply_id=packet_id, + reply_context=reply_context, + ) # Import locally to avoid circular import at module import time. from contact.ui.contact_ui import request_ui_redraw diff --git a/tests/test_bot_handler.py b/tests/test_bot_handler.py index 67b2e45..2bff76c 100644 --- a/tests/test_bot_handler.py +++ b/tests/test_bot_handler.py @@ -40,18 +40,19 @@ class BotHandlerTests(unittest.TestCase): packet = {"id": 900, "from": 222, "decoded": {}} with mock.patch.object(config, "ping_bot_enabled", "True"): - with mock.patch.object(self.bot_handler.threading, "Thread") as thread: - self.assertTrue(self.bot_handler.bot_respond(packet, "ping", 0)) - send_response = thread.call_args.kwargs["target"] - with mock.patch.object(self.bot_handler.time, "sleep"): - with mock.patch.dict( - sys.modules, - {"contact.ui.contact_ui": types.SimpleNamespace(request_ui_redraw=mock.Mock())}, - ): - send_response() + with mock.patch.object(self.bot_handler, "get_reply_context", return_value=" "): + with mock.patch.object(self.bot_handler.threading, "Thread") as thread: + self.assertTrue(self.bot_handler.bot_respond(packet, "ping", 0)) + send_response = thread.call_args.kwargs["target"] + with mock.patch.object(self.bot_handler.time, "sleep"): + with mock.patch.dict( + sys.modules, + {"contact.ui.contact_ui": types.SimpleNamespace(request_ui_redraw=mock.Mock())}, + ): + send_response() self.bot_handler.send_message.assert_called_once_with( - "Pong!", channel=0, reply_id=900 + "Pong!", channel=0, reply_id=900, reply_context=" " ) def test_bot_response_requires_enabled_app_setting(self) -> None: