Issue-2812 - Allow overridden converse methods to accept messages - adding default message=None to MycroftSkill.converse and changing the signature check in the skill manager.

pull/2813/head
neonandrii 2021-01-22 17:16:22 +02:00
parent 3dca3a488a
commit 416eebfee7
2 changed files with 7 additions and 3 deletions

View File

@ -334,7 +334,7 @@ class MycroftSkill:
"""
return None
def converse(self, utterances, lang=None):
def converse(self, utterances, lang=None, message=None):
"""Handle conversation.
This method gets a peek at utterances before the normal intent
@ -350,6 +350,8 @@ class MycroftSkill:
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

View File

@ -447,9 +447,11 @@ class SkillManager(Thread):
utterances = message.data['utterances']
lang = message.data['lang']
# check the signature of a converse method to either pass a message or not
if len(signature(skill_loader.instance.converse).parameters) == 3:
result = skill_loader.instance.converse(utterances, lang, message)
if len(signature(skill_loader.instance.converse).parameters) == 1:
result = skill_loader.instance.converse(message)
else:
utterances = message.data['utterances']
lang = message.data['lang']
result = skill_loader.instance.converse(utterances, lang)
self._emit_converse_response(result, message, skill_loader)
except Exception: