diff --git a/platypush/backend/assistant/google/pushtotalk.py b/platypush/backend/assistant/google/pushtotalk.py index d81318bb..c10f0a12 100644 --- a/platypush/backend/assistant/google/pushtotalk.py +++ b/platypush/backend/assistant/google/pushtotalk.py @@ -159,6 +159,7 @@ class AssistantGooglePushtotalkBackend(Backend): logging.info('Assistant conversation triggered') continue_conversation = True + user_request = None while continue_conversation: (user_request, continue_conversation) = self.assistant.assist() @@ -243,6 +244,8 @@ class SampleAssistant(object): yield c self.conversation_stream.start_playback() + user_request = None + # This generator yields AssistResponse proto messages # received from the gRPC Google Assistant API. for resp in self.assistant.Assist(iter_assist_requests(), @@ -285,7 +288,9 @@ class SampleAssistant(object): concurrent.futures.wait(device_actions_futures) logging.info('Finished playing assistant response.') - self.conversation_stream.stop_playback() + + if user_request: + self.conversation_stream.stop_playback() return (user_request, continue_conversation) def gen_assist_requests(self): diff --git a/platypush/message/event/assistant/__init__.py b/platypush/message/event/assistant/__init__.py index 8c09eb3e..483270c7 100644 --- a/platypush/message/event/assistant/__init__.py +++ b/platypush/message/event/assistant/__init__.py @@ -12,8 +12,11 @@ class AssistantEvent(Event): try: self._assistant = get_backend('assistant.google') except KeyError as e: - logging.warning('google.assistant backend not configured/initialized') - self._assistant = None + try: + self._assistant = get_backend('assistant.google.pushtotalk') + except KeyError as e: + logging.warning('google.assistant backend not configured/initialized') + self._assistant = None class ConversationStartEvent(AssistantEvent): diff --git a/platypush/plugins/assistant/google/__init__.py b/platypush/plugins/assistant/google/__init__.py new file mode 100644 index 00000000..a3589284 --- /dev/null +++ b/platypush/plugins/assistant/google/__init__.py @@ -0,0 +1,18 @@ +from platypush.context import get_backend +from platypush.message.response import Response + +from platypush.plugins import Plugin + +class AssistantGooglePlugin(Plugin): + def start_conversation(self): + assistant = get_backend('assistant.google') + assistant.start_conversation() + return Response(output='', errors=[]) + + def stop_conversation(self): + assistant = get_backend('assistant.google') + assistant.stop_conversation() + return Response(output='', errors=[]) + +# vim:sw=4:ts=4:et: + diff --git a/platypush/plugins/assistant/google/pushtotalk.py b/platypush/plugins/assistant/google/pushtotalk.py new file mode 100644 index 00000000..41bedccc --- /dev/null +++ b/platypush/plugins/assistant/google/pushtotalk.py @@ -0,0 +1,18 @@ +from platypush.context import get_backend +from platypush.message.response import Response + +from platypush.plugins import Plugin + +class AssistantGooglePushtotalkPlugin(Plugin): + def start_conversation(self): + assistant = get_backend('assistant.google.pushtotalk') + assistant.start_conversation() + return Response(output='', errors=[]) + + def stop_conversation(self): + assistant = get_backend('assistant.google.pushtotalk') + assistant.stop_conversation() + return Response(output='', errors=[]) + +# vim:sw=4:ts=4:et: +