1818
1919from google .cloud import dialogflow_v2beta1 as dialogflow
2020
21- ROLES = [' HUMAN_AGENT' , ' AUTOMATED_AGENT' , ' END_USER' ]
21+ ROLES = [" HUMAN_AGENT" , " AUTOMATED_AGENT" , " END_USER" ]
2222
2323
2424# [START dialogflow_create_participant]
@@ -32,13 +32,15 @@ def create_participant(project_id, conversation_id, role):
3232
3333 client = dialogflow .ParticipantsClient ()
3434 conversation_path = dialogflow .ConversationsClient .conversation_path (
35- project_id , conversation_id )
35+ project_id , conversation_id
36+ )
3637 if role in ROLES :
37- response = client .create_participant (parent = conversation_path ,
38- participant = {'role' : role })
39- print ('Participant Created.' )
40- print ('Role: {}' .format (response .role ))
41- print ('Name: {}' .format (response .name ))
38+ response = client .create_participant (
39+ parent = conversation_path , participant = {"role" : role }, timeout = 400
40+ )
41+ print ("Participant Created." )
42+ print ("Role: {}" .format (response .role ))
43+ print ("Name: {}" .format (response .name ))
4244
4345 return response
4446
@@ -57,45 +59,51 @@ def analyze_content_text(project_id, conversation_id, participant_id, text):
5759 text: the text message that participant typed."""
5860
5961 client = dialogflow .ParticipantsClient ()
60- participant_path = client .participant_path (project_id , conversation_id ,
61- participant_id )
62- text_input = {'text' : text , 'language_code' : 'en-US' }
63- response = client .analyze_content (participant = participant_path ,
64- text_input = text_input )
65- print ('AnalyzeContent Response:' )
66- print ('Reply Text: {}' .format (response .reply_text ))
62+ participant_path = client .participant_path (
63+ project_id , conversation_id , participant_id
64+ )
65+ text_input = {"text" : text , "language_code" : "en-US" }
66+ response = client .analyze_content (
67+ participant = participant_path , text_input = text_input
68+ )
69+ print ("AnalyzeContent Response:" )
70+ print ("Reply Text: {}" .format (response .reply_text ))
6771
6872 for suggestion_result in response .human_agent_suggestion_results :
6973 if suggestion_result .error is not None :
70- print (' Error: {}' .format (suggestion_result .error .message ))
74+ print (" Error: {}" .format (suggestion_result .error .message ))
7175 if suggestion_result .suggest_articles_response :
7276 for answer in suggestion_result .suggest_articles_response .article_answers :
73- print (' Article Suggestion Answer: {}' .format (answer .title ))
74- print (' Answer Record: {}' .format (answer .answer_record ))
77+ print (" Article Suggestion Answer: {}" .format (answer .title ))
78+ print (" Answer Record: {}" .format (answer .answer_record ))
7579 if suggestion_result .suggest_faq_answers_response :
7680 for answer in suggestion_result .suggest_faq_answers_response .faq_answers :
77- print (' Faq Answer: {}' .format (answer .answer ))
78- print (' Answer Record: {}' .format (answer .answer_record ))
81+ print (" Faq Answer: {}" .format (answer .answer ))
82+ print (" Answer Record: {}" .format (answer .answer_record ))
7983 if suggestion_result .suggest_smart_replies_response :
80- for answer in suggestion_result .suggest_smart_replies_response .smart_reply_answers :
81- print ('Smart Reply: {}' .format (answer .reply ))
82- print ('Answer Record: {}' .format (answer .answer_record ))
84+ for (
85+ answer
86+ ) in suggestion_result .suggest_smart_replies_response .smart_reply_answers :
87+ print ("Smart Reply: {}" .format (answer .reply ))
88+ print ("Answer Record: {}" .format (answer .answer_record ))
8389
8490 for suggestion_result in response .end_user_suggestion_results :
8591 if suggestion_result .error :
86- print (' Error: {}' .format (suggestion_result .error .message ))
92+ print (" Error: {}" .format (suggestion_result .error .message ))
8793 if suggestion_result .suggest_articles_response :
8894 for answer in suggestion_result .suggest_articles_response .article_answers :
89- print (' Article Suggestion Answer: {}' .format (answer .title ))
90- print (' Answer Record: {}' .format (answer .answer_record ))
95+ print (" Article Suggestion Answer: {}" .format (answer .title ))
96+ print (" Answer Record: {}" .format (answer .answer_record ))
9197 if suggestion_result .suggest_faq_answers_response :
9298 for answer in suggestion_result .suggest_faq_answers_response .faq_answers :
93- print (' Faq Answer: {}' .format (answer .answer ))
94- print (' Answer Record: {}' .format (answer .answer_record ))
99+ print (" Faq Answer: {}" .format (answer .answer ))
100+ print (" Answer Record: {}" .format (answer .answer_record ))
95101 if suggestion_result .suggest_smart_replies_response :
96- for answer in suggestion_result .suggest_smart_replies_response .smart_reply_answers :
97- print ('Smart Reply: {}' .format (answer .reply ))
98- print ('Answer Record: {}' .format (answer .answer_record ))
102+ for (
103+ answer
104+ ) in suggestion_result .suggest_smart_replies_response .smart_reply_answers :
105+ print ("Smart Reply: {}" .format (answer .reply ))
106+ print ("Answer Record: {}" .format (answer .answer_record ))
99107
100108 return response
101109
0 commit comments