From f73adc83bc9eb57b7fe389761378a11b13b98a22 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 20 Jun 2018 19:20:23 +0200 Subject: [PATCH] - Support for assistant response text as a ResponseEvent - Don't trigger a ConversationEndEvent if the assistant needs to follow up on the previous interaction --- platypush/backend/assistant/google/__init__.py | 7 +++++-- platypush/message/event/assistant/__init__.py | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/platypush/backend/assistant/google/__init__.py b/platypush/backend/assistant/google/__init__.py index a2fd69d63..d6c4264ef 100644 --- a/platypush/backend/assistant/google/__init__.py +++ b/platypush/backend/assistant/google/__init__.py @@ -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)) diff --git a/platypush/message/event/assistant/__init__.py b/platypush/message/event/assistant/__init__.py index 849baadfa..149326d7d 100644 --- a/platypush/message/event/assistant/__init__.py +++ b/platypush/message/event/assistant/__init__.py @@ -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)