Skip to content

Commit

Permalink
feat/converse_session
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Sep 20, 2023
1 parent f81d88b commit 9605cb1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ovos_core/intent_services/converse_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import ovos_core.intent_services
from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager
from ovos_bus_client.session import SessionManager, UtteranceState
from ovos_utils import flatten_list
from ovos_utils.log import LOG
from ovos_utils.messagebus import get_message_lang
Expand All @@ -23,6 +23,8 @@ def __init__(self, bus):
self.bus.on('intent.service.skills.activate', self.handle_activate_skill_request)
self.bus.on('active_skill_request', self.handle_activate_skill_request) # TODO backwards compat, deprecate
self.bus.on('intent.service.active_skills.get', self.handle_get_active_skills)
self.bus.on("skill.converse.get_response.enable", self.handle_get_response_enable)
self.bus.on("skill.converse.get_response.disable", self.handle_get_response_disable)

@property
def config(self):
Expand Down Expand Up @@ -256,6 +258,17 @@ def converse(self, utterances, skill_id, lang, message):
"""
session = SessionManager.get(message)
session.lang = lang

state = session.utterance_states.get(skill_id, UtteranceState.INTENT)
if state == UtteranceState.RESPONSE:
session.update_history(message)
converse_msg = message.reply("skill.converse.get_response",
{"skill_id": skill_id,
"utterances": utterances,
"lang": lang})
self.bus.emit(converse_msg)
return True

if self._converse_allowed(skill_id):
session.update_history(message)
converse_msg = message.reply("skill.converse.request",
Expand Down Expand Up @@ -293,6 +306,16 @@ def converse_with_skills(self, utterances, lang, message):
return ovos_core.intent_services.IntentMatch('Converse', None, None, skill_id, utterances[0])
return None

def handle_get_response_enable(self, message):
skill_id = message.data["skill_id"]
session = SessionManager.get(message)
session.enable_response_mode(skill_id)

def handle_get_response_disable(self, message):
skill_id = message.data["skill_id"]
session = SessionManager.get(message)
session.disable_response_mode(skill_id)

def handle_activate_skill_request(self, message):
# TODO imperfect solution - only a skill can activate itself
# someone can forge this message and emit it raw, but in OpenVoiceOS all
Expand Down

0 comments on commit 9605cb1

Please sign in to comment.