Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
fix: added increased timout (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-loved-dreamer committed Sep 27, 2021
1 parent 12b4f60 commit 2126dc9
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions samples/snippets/participant_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from google.cloud import dialogflow_v2beta1 as dialogflow

ROLES = ['HUMAN_AGENT', 'AUTOMATED_AGENT', 'END_USER']
ROLES = ["HUMAN_AGENT", "AUTOMATED_AGENT", "END_USER"]


# [START dialogflow_create_participant]
Expand All @@ -32,13 +32,15 @@ def create_participant(project_id, conversation_id, role):

client = dialogflow.ParticipantsClient()
conversation_path = dialogflow.ConversationsClient.conversation_path(
project_id, conversation_id)
project_id, conversation_id
)
if role in ROLES:
response = client.create_participant(parent=conversation_path,
participant={'role': role})
print('Participant Created.')
print('Role: {}'.format(response.role))
print('Name: {}'.format(response.name))
response = client.create_participant(
parent=conversation_path, participant={"role": role}, timeout=400
)
print("Participant Created.")
print("Role: {}".format(response.role))
print("Name: {}".format(response.name))

return response

Expand All @@ -57,45 +59,51 @@ def analyze_content_text(project_id, conversation_id, participant_id, text):
text: the text message that participant typed."""

client = dialogflow.ParticipantsClient()
participant_path = client.participant_path(project_id, conversation_id,
participant_id)
text_input = {'text': text, 'language_code': 'en-US'}
response = client.analyze_content(participant=participant_path,
text_input=text_input)
print('AnalyzeContent Response:')
print('Reply Text: {}'.format(response.reply_text))
participant_path = client.participant_path(
project_id, conversation_id, participant_id
)
text_input = {"text": text, "language_code": "en-US"}
response = client.analyze_content(
participant=participant_path, text_input=text_input
)
print("AnalyzeContent Response:")
print("Reply Text: {}".format(response.reply_text))

for suggestion_result in response.human_agent_suggestion_results:
if suggestion_result.error is not None:
print('Error: {}'.format(suggestion_result.error.message))
print("Error: {}".format(suggestion_result.error.message))
if suggestion_result.suggest_articles_response:
for answer in suggestion_result.suggest_articles_response.article_answers:
print('Article Suggestion Answer: {}'.format(answer.title))
print('Answer Record: {}'.format(answer.answer_record))
print("Article Suggestion Answer: {}".format(answer.title))
print("Answer Record: {}".format(answer.answer_record))
if suggestion_result.suggest_faq_answers_response:
for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
print('Faq Answer: {}'.format(answer.answer))
print('Answer Record: {}'.format(answer.answer_record))
print("Faq Answer: {}".format(answer.answer))
print("Answer Record: {}".format(answer.answer_record))
if suggestion_result.suggest_smart_replies_response:
for answer in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
print('Smart Reply: {}'.format(answer.reply))
print('Answer Record: {}'.format(answer.answer_record))
for (
answer
) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
print("Smart Reply: {}".format(answer.reply))
print("Answer Record: {}".format(answer.answer_record))

for suggestion_result in response.end_user_suggestion_results:
if suggestion_result.error:
print('Error: {}'.format(suggestion_result.error.message))
print("Error: {}".format(suggestion_result.error.message))
if suggestion_result.suggest_articles_response:
for answer in suggestion_result.suggest_articles_response.article_answers:
print('Article Suggestion Answer: {}'.format(answer.title))
print('Answer Record: {}'.format(answer.answer_record))
print("Article Suggestion Answer: {}".format(answer.title))
print("Answer Record: {}".format(answer.answer_record))
if suggestion_result.suggest_faq_answers_response:
for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
print('Faq Answer: {}'.format(answer.answer))
print('Answer Record: {}'.format(answer.answer_record))
print("Faq Answer: {}".format(answer.answer))
print("Answer Record: {}".format(answer.answer_record))
if suggestion_result.suggest_smart_replies_response:
for answer in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
print('Smart Reply: {}'.format(answer.reply))
print('Answer Record: {}'.format(answer.answer_record))
for (
answer
) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
print("Smart Reply: {}".format(answer.reply))
print("Answer Record: {}".format(answer.answer_record))

return response

Expand Down

0 comments on commit 2126dc9

Please sign in to comment.