- Support for assistant response text as a ResponseEvent

- Don't trigger a ConversationEndEvent if the assistant needs to follow up on the previous interaction
This commit is contained in:
Fabio Manganiello 2018-06-20 19:20:23 +02:00
parent e70eb8bb42
commit f73adc83bc
2 changed files with 10 additions and 2 deletions

View file

@ -12,7 +12,7 @@ from google.assistant.library.file_helpers import existing_file
from platypush.backend import Backend
from platypush.message.event.assistant import \
ConversationStartEvent, ConversationEndEvent, ConversationTimeoutEvent, \
NoResponseEvent, SpeechRecognizedEvent
ResponseEvent, NoResponseEvent, SpeechRecognizedEvent
class AssistantGoogleBackend(Backend):
@ -46,11 +46,14 @@ class AssistantGoogleBackend(Backend):
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
self.bus.post(ConversationStartEvent())
elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED:
self.bus.post(ConversationEndEvent())
if not event.args.get('with_follow_on_turn'):
self.bus.post(ConversationEndEvent())
elif event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT:
self.bus.post(ConversationTimeoutEvent())
elif event.type == EventType.ON_NO_RESPONSE:
self.bus.post(NoResponseEvent())
elif event.type == EventType.ON_RENDER_RESPONSE:
self.bus.post(ResponseEvent(response_text=event.args.get('text')))
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
phrase = event.args['text'].lower().strip()
self.logger.info('Speech recognized: {}'.format(phrase))

View file

@ -37,6 +37,11 @@ class ConversationTimeoutEvent(ConversationEndEvent):
super().__init__(*args, **kwargs)
class ResponseEvent(ConversationEndEvent):
def __init__(self, response_text, *args, **kwargs):
super().__init__(*args, response_text=response_text, **kwargs)
class NoResponseEvent(ConversationEndEvent):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)