Skip to content

Commit

Permalink
chore: Update dialogflow_cx_webhook snippet to match NodeJS (#409)
Browse files Browse the repository at this point in the history
* chore: Update dialogflow_cx_webhook snippet to match NodeJS

* Updates noxfile to skip deps install, if empty; otherwise an exception occurs
  • Loading branch information
nicain authored Jun 28, 2022
1 parent b8bbe05 commit 5a59aa6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/google-cloud-dialogflow-cx/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ def prerelease_deps(session):
deps = [dep for dep in deps if dep not in prerel_deps]
# We use --no-deps to ensure that pre-release versions aren't overwritten
# by the version ranges in setup.py.
session.install(*deps)
if deps:
session.install(*deps)
session.install("--no-deps", "-e", ".[all]")

# Print out prerelease package versions
Expand Down
41 changes: 17 additions & 24 deletions packages/google-cloud-dialogflow-cx/samples/snippets/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,29 @@ def handle_webhook(request):
tag = req["fulfillmentInfo"]["tag"]

if tag == "Default Welcome Intent":
# You can also use the google.cloud.dialogflowcx_v3.types.WebhookRequest protos instead of manually writing the json object
# Please see https://googleapis.dev/python/dialogflow/latest/dialogflow_v2/types.html?highlight=webhookresponse#google.cloud.dialogflow_v2.types.WebhookResponse for an overview
res = {
"fulfillment_response": {
"messages": [{"text": {"text": ["Hi from a GCF Webhook"]}}]
}
}
text = "Hello from a GCF Webhook"
elif tag == "get-name":
res = {
"fulfillment_response": {
"messages": [{"text": {"text": ["My name is Phlowhook"]}}]
}
}
text = "My name is Flowhook"
else:
res = {
"fulfillment_response": {
"messages": [
{
"text": {
"text": [
f"There are no fulfillment responses defined for {tag} tag"
]
}
text = f"There are no fulfillment responses defined for {tag} tag"

# You can also use the google.cloud.dialogflowcx_v3.types.WebhookRequest protos instead of manually writing the json object
# Please see https://googleapis.dev/python/dialogflow/latest/dialogflow_v2/types.html?highlight=webhookresponse#google.cloud.dialogflow_v2.types.WebhookResponse for an overview
res = {
"fulfillment_response": {
"messages": [
{
"text": {
"text": [
text
]
}
]
}
}
]
}
}

# Returns json
return res


# [END dialogflow_cx_webhook]
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def app():
def test_handle_webhook(app):
with app.test_request_context(json=request):
res = handle_webhook(flask.request)
assert "Hi from a GCF Webhook" in str(res)
assert "Hello from a GCF Webhook" in str(res)

0 comments on commit 5a59aa6

Please sign in to comment.