2 from google.protobuf
import struct_pb2
3 from dialogflow_v2beta1.types
import Context, EventInput, InputAudioConfig, \
4 OutputAudioConfig, QueryInput, QueryParameters, \
5 SentimentAnalysisRequestConfig, StreamingDetectIntentRequest, TextInput
7 from output
import print_context_parameters
11 """Convert Dialogflow parameter (Google Struct) into ros msg 13 :type parameters: struct_pb2.Struct 14 :return: List of DF Param msgs or empty list 15 :rtype: (list of DialogflowParameter) or None 17 if parameters.items():
19 for name, value
in parameters.items():
20 param = DialogflowParameter(param_name=str(name), value=[str(value)])
21 param_list.append(param)
28 """Create a DF compatible parameter dictionary 29 :param parameters: DialogflowParameter message 30 :type parameters: list(DialogflowParameter) 31 :return: Parameters as a dictionary (Technically) 32 :rtype: struct_pb2.Struct 34 google_struct = struct_pb2.Struct()
35 for param
in parameters:
36 google_struct[param.param_name] = param.value
41 """Convert ROS Event Msg to DF Event 42 :param event: ROS Event Message 43 :type event: DialogflowEvent 44 :param language_code: Language code of event, default 'en-US' 45 :type language_code: str 46 :return: Dialogflow EventInput to send 50 return EventInput(name=event.event_name,
51 parameters=parameters,
52 language_code=language_code)
56 """Utility function that fills the context received from Dialogflow into 58 :param contexts: The output_context received from Dialogflow. 59 :type contexts: Context 60 :return: The ROS DialogflowContext msg. 61 :rtype: DialogflowContext 64 for context
in contexts:
65 df_context_msg = DialogflowContext()
66 df_context_msg.name = str(context.name)
67 df_context_msg.lifespan_count = int(context.lifespan_count)
69 context_list.append(df_context_msg)
74 """Utility function that fills the context received from ROS into 76 :param contexts: The output_context received from ROS. 77 :type contexts: DialogflowContext 78 :return: The Dialogflow Context. 82 for context
in contexts:
84 new_context = Context(name=context.name,
85 lifespan_count=context.lifespan_count,
86 parameters=new_parameters)
87 context_list.append(new_context)
92 """Creates a QueryParameter with contexts. Last contexts used if 93 contexts is empty. No contexts if none found. 94 :param contexts: The ROS DialogflowContext message 95 :type contexts: list(DialogflowContext) 96 :return: A Dialogflow query parameters object. 97 :rtype: QueryParameters 101 rospy.logdebug(
"DF_CLIENT: Using the following contexts:\n{}".format(
104 return QueryParameters(contexts=contexts)
108 """Utility function that fills the result received from Dialogflow into 110 :param query_result: The query_result received from Dialogflow. 111 :type query_result: QueryResult 112 :return: The ROS DialogflowResult msg. 113 :rtype: DialogflowResult 115 df_result_msg = DialogflowResult()
116 df_result_msg.fulfillment_text = str(query_result.fulfillment_text)
117 df_result_msg.query_text = str(query_result.query_text)
118 df_result_msg.action = str(query_result.action)
120 query_result.parameters
123 query_result.output_contexts
125 df_result_msg.intent = str(query_result.intent.display_name)
def parameters_struct_to_msg(parameters)
def params_msg_to_struct(parameters)
def contexts_struct_to_msg(contexts)
def result_struct_to_msg(query_result)
def events_msg_to_struct(event, language_code='en-US')
def contexts_msg_to_struct(contexts)
def create_query_parameters(contexts=None)
def print_context_parameters(contexts)