def sample_streaming_analyze_content(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.StreamingAnalyzeContentRequest( input_audio=b'input_audio_blob', participant="participant_value", ) # This method expects an iterator which contains # 'dialogflow_v2beta1.StreamingAnalyzeContentRequest' objects # Here we create a generator that yields a single `request` for # demonstrative purposes. requests = [request] def request_generator(): for request in requests: yield request # Make the request stream = client.streaming_analyze_content(requests=request_generator()) # Handle the response for response in stream: print(response)
def analyze_content_text(project_id, conversation_id, participant_id, text): """Analyze text message content from a participant. Args: project_id: The GCP project linked with the conversation profile. conversation_id: Id of the conversation. participant_id: Id of the participant. 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)) for suggestion_result in response.human_agent_suggestion_results: if suggestion_result.error is not None: 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)) 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)) 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 suggestion_result in response.end_user_suggestion_results: if suggestion_result.error: 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)) 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)) 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)) return response
def sample_update_participant(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.UpdateParticipantRequest() # Make the request response = client.update_participant(request=request) # Handle the response print(response)
def sample_get_participant(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.GetParticipantRequest(name="name_value", ) # Make the request response = client.get_participant(request=request) # Handle the response print(response)
def sample_compile_suggestion(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.CompileSuggestionRequest() # Make the request response = client.compile_suggestion(request=request) # Handle the response print(response)
def sample_suggest_faq_answers(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.SuggestFaqAnswersRequest( parent="parent_value", ) # Make the request response = client.suggest_faq_answers(request=request) # Handle the response print(response)
def sample_list_suggestions(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.ListSuggestionsRequest() # Make the request page_result = client.list_suggestions(request=request) # Handle the response for response in page_result: print(response)
def sample_analyze_content(): # Create a client client = dialogflow_v2beta1.ParticipantsClient() # Initialize request argument(s) request = dialogflow_v2beta1.AnalyzeContentRequest( participant="participant_value", ) # Make the request response = client.analyze_content(request=request) # Handle the response print(response)
def create_participant(project_id, conversation_id, role): """Creates a participant in a given conversation. Args: project_id: The GCP project linked with the conversation profile. conversation_id: Id of the conversation. participant: participant to be created.""" client = dialogflow.ParticipantsClient() conversation_path = dialogflow.ConversationsClient.conversation_path( 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)) return response