forked from platypush/platypush
Handling assistant no_response events
This commit is contained in:
parent
4f75b765b1
commit
c1caa182be
2 changed files with 9 additions and 1 deletions
|
@ -12,7 +12,8 @@ from google.assistant.library.file_helpers import existing_file
|
||||||
|
|
||||||
from platypush.backend import Backend
|
from platypush.backend import Backend
|
||||||
from platypush.message.event.assistant import \
|
from platypush.message.event.assistant import \
|
||||||
ConversationStartEvent, ConversationEndEvent, ConversationTimeoutEvent, SpeechRecognizedEvent
|
ConversationStartEvent, ConversationEndEvent, ConversationTimeoutEvent, \
|
||||||
|
NoResponseEvent, SpeechRecognizedEvent
|
||||||
|
|
||||||
class AssistantGoogleBackend(Backend):
|
class AssistantGoogleBackend(Backend):
|
||||||
""" Class for the Google Assistant backend. It creates and event source
|
""" Class for the Google Assistant backend. It creates and event source
|
||||||
|
@ -48,6 +49,8 @@ class AssistantGoogleBackend(Backend):
|
||||||
self.bus.post(ConversationEndEvent())
|
self.bus.post(ConversationEndEvent())
|
||||||
elif event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT:
|
elif event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT:
|
||||||
self.bus.post(ConversationTimeoutEvent())
|
self.bus.post(ConversationTimeoutEvent())
|
||||||
|
elif event.type == EventType.ON_NO_RESPONSE:
|
||||||
|
self.bus.post(NoResponseEvent())
|
||||||
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
|
elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
|
||||||
phrase = event.args['text'].lower().strip()
|
phrase = event.args['text'].lower().strip()
|
||||||
logging.info('Speech recognized: {}'.format(phrase))
|
logging.info('Speech recognized: {}'.format(phrase))
|
||||||
|
|
|
@ -34,6 +34,11 @@ class ConversationTimeoutEvent(ConversationEndEvent):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class NoResponseEvent(ConversationEndEvent):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class SpeechRecognizedEvent(AssistantEvent):
|
class SpeechRecognizedEvent(AssistantEvent):
|
||||||
def __init__(self, phrase, *args, **kwargs):
|
def __init__(self, phrase, *args, **kwargs):
|
||||||
super().__init__(phrase=phrase, *args, **kwargs)
|
super().__init__(phrase=phrase, *args, **kwargs)
|
||||||
|
|
Loading…
Reference in a new issue