8000 Issue-2812 - Allow overridden converse methods to accept messages by NeonAndrii · Pull Request #2813 · MycroftAI/mycroft-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Sep 8, 2024. It is now read-only.
8000

Issue-2812 - Allow overridden converse methods to accept messages #2813

Merged
merged 7 commits into from
Mar 11, 2021
8000
12 changes: 5 additions & 7 deletions mycroft/skills/mycroft_skill/mycroft_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions mycroft/skills/skill_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
0