Merge pull request #2476 from forslund/bugfix/message-targeting

Bugfix for padatious and converse responses
pull/2478/head
Åke 2020-02-24 07:32:57 +01:00 committed by GitHub
commit 493d057f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -16,6 +16,7 @@ import json
import re
import inspect
from mycroft.util.parse import normalize
from copy import deepcopy
class Message:
@ -111,10 +112,10 @@ class Message:
Returns:
Message: Message object to be used on the reply to the message
"""
data = data or {}
data = deepcopy(data) or {}
context = context or {}
new_context = self.context
new_context = deepcopy(self.context)
for key in context:
new_context[key] = context[key]
if 'destination' in data:

View File

@ -213,11 +213,11 @@ class IntentService:
for skill in self.active_skills:
self.do_converse(None, skill[0], lang)
def do_converse(self, utterances, skill_id, lang):
def do_converse(self, utterances, skill_id, lang, message):
self.waiting_for_converse = True
self.converse_result = False
self.converse_skill_id = skill_id
self.bus.emit(Message("skill.converse.request", {
self.bus.emit(message.reply("skill.converse.request", {
"skill_id": skill_id, "utterances": utterances, "lang": lang}))
start_time = time.time()
t = 0
@ -333,7 +333,7 @@ class IntentService:
padatious_intent = None
with stopwatch:
# Give active skills an opportunity to handle the utterance
converse = self._converse(combined, lang)
converse = self._converse(combined, lang, message)
if not converse:
# No conversation, use intent system to handle utterance
@ -352,7 +352,9 @@ class IntentService:
if converse:
# Report that converse handled the intent and return
LOG.debug("Handled in converse()")
ident = message.context['ident'] if message.context else None
ident = None
if message.context and 'ident' in message.context:
ident = message.context['ident']
report_timing(ident, 'intent_service', stopwatch,
{'intent_type': 'converse'})
return
@ -385,12 +387,13 @@ class IntentService:
except Exception as e:
LOG.exception(e)
def _converse(self, utterances, lang):
def _converse(self, utterances, lang, message):
""" Give active skills a chance at the utterance
Args:
utterances (list): list of utterances
lang (string): 4 letter ISO language code
message (Message): message to use to generate reply
Returns:
bool: True if converse handled it, False if no skill processes it
@ -403,7 +406,7 @@ class IntentService:
# check if any skill wants to handle utterance
for skill in self.active_skills:
if self.do_converse(utterances, skill[0], lang):
if self.do_converse(utterances, skill[0], lang, message):
# update timestamp, or there will be a timeout where
# intent stops conversing whether its being used or not
self.add_active_skill(skill[0])

View File

@ -169,7 +169,7 @@ class PadatiousService(FallbackSkill):
intent.matches['utterance'] = utt
self.service.add_active_skill(intent.name.split(':')[0])
self.bus.emit(message.reply(intent.name, data=intent.matches))
self.bus.emit(message.forward(intent.name, data=intent.matches))
return True
def handle_fallback_last_chance(self, message):