in genesyscloud/genesyscloud-audiohook/audiohook_blueprint.py [0:0]
def process_ongoing_conversation_messages(
message: json,
dialogflow_api: DialogflowAPI,
audiohook: AudioHook,
agent_stream: Stream,
customer_stream: Stream,
open_conversation_state: OpenConversationState,
ws: Server) -> bool:
"""Process string messages that are not "open" and "ping" from Audiohook client through websocket.
Note:
Audiohook client passes Null UUIDs (00000000-0000-0000-0000-000000000000)
as conversationId and participant.id parameters to identify connection probes.
https://developer.genesys.cloud/devapps/audiohook/protocol-reference#openparameters
Reference: https://developer.genesys.cloud/devapps/audiohook/protocol-reference
Return:
True, if there is a connection close message. So the outer loop for
receiving audio can be completed
False, for other messages to continue process messages from websocket
"""
message_type = message.get("type")
match message_type:
case "resumed":
# The first paused message after open message sets the
# closed to True, now after resume, need to flip the bit
customer_stream.closed = False
agent_stream.closed = False
open_conversation_state.agent_thread.start()
open_conversation_state.user_thread.start()
case "paused":
customer_stream.closed = True
agent_stream.closed = True
logging.debug("Audio stream is paused")
case "close":
# This "close" is for ending a real conversation
agent_stream.closed = True
customer_stream.closed = True
agent_stream.terminate = True
customer_stream.terminate = True
ws.send(json.dumps(audiohook.create_close_message()))
try:
dialogflow_api.complete_conversation(
open_conversation_state.conversation_name)
except Exception as e:
logging.error("Error completing conversation %s", e)
# wait for the two thread to finish then terminate
logging.debug("Stop streaming threads for customers and agents")
return True
case "discarded":
start_time = message.get("START_TIME")
duration = message.get("DURATION")
logging.info(
"Currently the audio stream has been paused from %s for about %s second",
start_time,
duration)
return False