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

docs(samples): add set agent code sample #370

Merged
merged 33 commits into from Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
568f0ba
Added Update Intent Snippet and Test
galz10 Aug 3, 2021
2b278e7
Deleted Setting Env Vars
galz10 Aug 3, 2021
4952c45
Fixed Lint Issues
galz10 Aug 3, 2021
7852110
Fixed Lint and Build Issue
galz10 Aug 3, 2021
8d4999c
Fixed Build Issue
galz10 Aug 3, 2021
1259002
Changed tests to pytests
galz10 Aug 3, 2021
755a7d1
Removed delete and create agent from test
galz10 Aug 4, 2021
b2395e7
Fixed Import Order
galz10 Aug 4, 2021
cb6128e
Deleted unused import
galz10 Aug 4, 2021
af3377e
Removed Language from update_intent Snippet
galz10 Aug 4, 2021
a774718
Added copyright
galz10 Aug 4, 2021
c922a4c
Changed intent name to random name
galz10 Aug 5, 2021
100af60
delete intent after testing
galz10 Aug 5, 2021
7ba7ed4
fix test
galz10 Aug 5, 2021
48c9f13
remove contains
galz10 Aug 5, 2021
7ad7509
Added Create Intent
galz10 Aug 5, 2021
75958c2
fix lint
galz10 Aug 5, 2021
2fad4bf
Merge branch 'master' into master
parthea Aug 12, 2021
a012f58
Merge branch 'master' into master
galz10 Aug 12, 2021
c3eee8b
Merge branch 'master' into master
galz10 Aug 13, 2021
c776f7f
docs(samples): add set agent code sample
galz10 Aug 19, 2021
8d87b9b
lint fix
galz10 Aug 19, 2021
fd6a653
Merge branch 'master' into create-agent
galz10 Aug 19, 2021
0556d84
Resolved comments
galz10 Aug 31, 2021
09f4ebb
Merge branch 'create-agent' of github.com:galz10/python-dialogflow in…
galz10 Aug 31, 2021
5ba68cc
test and lint changes
galz10 Aug 31, 2021
799effe
Merge branch 'main' into create-agent
galz10 Aug 31, 2021
11b4a63
Merge branch 'main' into create-agent
galz10 Sep 1, 2021
d498ee3
Merge branch 'main' into create-agent
galz10 Sep 3, 2021
016f8ad
Merge branch 'main' into create-agent
galz10 Sep 7, 2021
245e62f
Added Comments
galz10 Sep 8, 2021
a98adb3
lint fix
galz10 Sep 8, 2021
c7dfd1c
Merge branch 'main' into create-agent
galz10 Sep 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions samples/snippets/set_agent.py
@@ -0,0 +1,39 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START dialogflow_set_agent_sample]

from google.cloud.dialogflow_v2 import Agent
from google.cloud.dialogflow_v2 import AgentsClient


def set_agent(project_id, display_name):

agents_client = AgentsClient()

parent = agents_client.common_project_path(project_id)

agent = Agent(
parent=parent,
display_name=display_name,
default_language_code="en",
time_zone="America/Los_Angeles",
)

response = agents_client.set_agent(request={"agent": agent})

return response


# [END dialogflow_set_agent_sample]
31 changes: 31 additions & 0 deletions samples/snippets/set_agent_test.py
@@ -0,0 +1,31 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from google.api_core.exceptions import InvalidArgument

import pytest

from set_agent import set_agent

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")


# We cannot test setAgent because Dialogflow ES can only have one agent
# and if we create a agent it will delete the exisitng testing agent and
# would cause all tests to fail
def test_set_agent():
with pytest.raises(InvalidArgument):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The test code might confuse the readers. Maybe you can add a comment justifying the compromising test strategy.

set_agent(PROJECT_ID, "")