Repository: MycroftAI/mycroft-messagebus-client

Issue:
message.response should use message.reply internally
to account for proper message routing https://github.com/JarbasHiveMind/HiveMind-core/wiki/Mycroft-Messages + https://github.com/MycroftAI/mycroft-core/pull/2461

Discussion:
forslund: Can you bump the version to 0.10.0 as well. It will likely be an issue in the Mycroft-core common play / query skills but I need to verify that.
krisgesling: Hey, on the surface it looks like the behaviour that should be expected. The docstring even says it is a reply.

It would be really useful to have more detailed commit messages and PR descriptions. Even if it's copied verbatim from another source, it means people looking at this PR or the commit history don't need to trawl through other docs to find the relevant pieces and make guesses about why this change is needed.

I'm also wondering if we can add in some more tests here. There seems to be a minimal test for response and nothing for reply, and this potentially breaking change didn't register as an issue on the existing test.
JarbasAl: related change https://github.com/OpenVoiceOS/skill-ovos-common-query/commit/2189e60b204b9f8b96d7a64429627736b714f399
NeonDaniel: Anything holding up this PR? Appears related to a routing question I had
krisgesling: Hey, thanks for adding those unit tests.

I've updated the title and description a little - can you just confirm this is accurate and then we can merge it in.

Patch:
diff --git a/mycroft_bus_client/message.py b/mycroft_bus_client/message.py
index 48351ca..037e3e3 100644
--- a/mycroft_bus_client/message.py
+++ b/mycroft_bus_client/message.py
@@ -146,9 +146,7 @@ class Message:
         Returns
             (Message) message with the type modified to match default response
         """
-        response_message = Message(self.msg_type + '.response', data or {},
-                                   context or self.context)
-        return response_message
+        return self.reply(self.msg_type + '.response', data, context)
 
     def publish(self, msg_type, data, context=None):
         """


Test patch:
diff --git a/test/test_message.py b/test/test_message.py
index b1f2077..67d2939 100644
--- a/test/test_message.py
+++ b/test/test_message.py
@@ -40,6 +40,23 @@ class TestMessage(TestCase):
         self.assertEqual(response_msg.data, {})
         self.assertEqual(response_msg.context, source.context)
 
+    def test_reply(self):
+        """Assert that the source and destination are swapped"""
+        source = Message('test_type',
+                         data={'robot': 'marvin', 'android': 'data'},
+                         context={'source': 'earth',
+                                  'destination': 'alpha centauri'})
+
+        reply_msg = source.reply('reply_type')
+        self.assertEqual(reply_msg.context["source"],
+                         source.context["destination"])
+        self.assertEqual(reply_msg.context["destination"],
+                         source.context["source"])
+
+        # assert that .response calls .reply internally as stated in docstrings
+        response_msg = source.response()
+        self.assertEqual(response_msg.context, reply_msg.context)
+
     def test_dig_for_message_simple(self):
         test_msg = Message("test message", {"test": "data"}, {"time": time()})
         self.assertEqual(test_msg, get_message_standard(test_msg))