Repository: MycroftAI/mycroft-core

Issue:
Allow overridden converse methods to accept emitted messages
**Is your feature request related to a problem? Please describe.**
Passing a message to converse() would make it possible to contribute more complex skills to the project (sometimes, raw utterances are not enough). This changes cannot be simply implementer in an overridden skill converse() since this method is called by the SkillManager.

**Describe the solution you'd like**
In SkillManager.handle_converse_request(), add a function signature check to pass either an overridden converse or the default one.

**Describe alternatives you've considered**
Digging through the message stack directly in skill.converse() but that requires more complex changes.

**Additional context**
This feature is awaiting for a PR review.



Discussion:

Resolving patch:
diff --git a/mycroft/skills/mycroft_skill/mycroft_skill.py b/mycroft/skills/mycroft_skill/mycroft_skill.py
--- a/mycroft/skills/mycroft_skill/mycroft_skill.py
+++ b/mycroft/skills/mycroft_skill/mycroft_skill.py
@@ -334,7 +334,7 @@ def get_intro_message(self):
         """
         return None
 
-    def converse(self, utterances, lang=None):
+    def converse(self, message=None):
         """Handle conversation.
 
         This method gets a peek at utterances before the normal intent
@@ -343,13 +343,11 @@ def converse(self, utterances, lang=None):
         To use, override the converse() method and return True to
         indicate that the utterance has been handled.
 
+        utterances and lang are depreciated
+
         Arguments:
-            utterances (list): The utterances from the user.  If there are
-                               multiple utterances, consider them all to be
-                               transcription possibilities.  Commonly, the
-                               first entry is the user utt and the second
-                               is normalized() version of the first utterance
-            lang:       language the utterance is in, None for default
+            message:    a message object containing a message type with an
+                        optional JSON data packet
 
         Returns:
             bool: True if an utterance was handled, otherwise False
diff --git a/mycroft/skills/skill_manager.py b/mycroft/skills/skill_manager.py
--- a/mycroft/skills/skill_manager.py
+++ b/mycroft/skills/skill_manager.py
@@ -17,6 +17,7 @@
 from glob import glob
 from threading import Thread, Event, Lock
 from time import sleep, time, monotonic
+from inspect import signature
 
 from mycroft.api import is_paired
 from mycroft.enclosure.api import EnclosureAPI
@@ -443,9 +444,17 @@ def handle_converse_request(self, message):
                     self._emit_converse_error(message, skill_id, error_message)
                     break
                 try:
-                    utterances = message.data['utterances']
-                    lang = message.data['lang']
-                    result = skill_loader.instance.converse(utterances, lang)
+                    # check the signature of a converse method
+                    # to either pass a message or not
+                    if len(signature(
+                            skill_loader.instance.converse).parameters) == 1:
+                        result = skill_loader.instance.converse(
+                            message=message)
+                    else:
+                        utterances = message.data['utterances']
+                        lang = message.data['lang']
+                        result = skill_loader.instance.converse(
+                            utterances=utterances, lang=lang)
                     self._emit_converse_response(result, message, skill_loader)
                 except Exception:
                     error_message = 'exception in converse method'


Test patch: