18
18
19
19
from google .cloud import dialogflow_v2beta1 as dialogflow
20
20
21
- ROLES = [' HUMAN_AGENT' , ' AUTOMATED_AGENT' , ' END_USER' ]
21
+ ROLES = [" HUMAN_AGENT" , " AUTOMATED_AGENT" , " END_USER" ]
22
22
23
23
24
24
# [START dialogflow_create_participant]
@@ -32,13 +32,15 @@ def create_participant(project_id, conversation_id, role):
32
32
33
33
client = dialogflow .ParticipantsClient ()
34
34
conversation_path = dialogflow .ConversationsClient .conversation_path (
35
- project_id , conversation_id )
35
+ project_id , conversation_id
36
+ )
36
37
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 ))
42
44
43
45
return response
44
46
@@ -57,45 +59,51 @@ def analyze_content_text(project_id, conversation_id, participant_id, text):
57
59
text: the text message that participant typed."""
58
60
59
61
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 ))
67
71
68
72
for suggestion_result in response .human_agent_suggestion_results :
69
73
if suggestion_result .error is not None :
70
- print (' Error: {}' .format (suggestion_result .error .message ))
74
+ print (" Error: {}" .format (suggestion_result .error .message ))
71
75
if suggestion_result .suggest_articles_response :
72
76
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 ))
75
79
if suggestion_result .suggest_faq_answers_response :
76
80
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 ))
79
83
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 ))
83
89
84
90
for suggestion_result in response .end_user_suggestion_results :
85
91
if suggestion_result .error :
86
- print (' Error: {}' .format (suggestion_result .error .message ))
92
+ print (" Error: {}" .format (suggestion_result .error .message ))
87
93
if suggestion_result .suggest_articles_response :
88
94
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 ))
91
97
if suggestion_result .suggest_faq_answers_response :
92
98
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 ))
95
101
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 ))
99
107
100
108
return response
101
109
0 commit comments