From 5a59aa6ec991837a0c83a934f3c9f90a1bd5db81 Mon Sep 17 00:00:00 2001 From: nicain Date: Tue, 28 Jun 2022 16:10:38 -0700 Subject: [PATCH] chore: Update dialogflow_cx_webhook snippet to match NodeJS (#409) * chore: Update dialogflow_cx_webhook snippet to match NodeJS * Updates noxfile to skip deps install, if empty; otherwise an exception occurs --- .../google-cloud-dialogflow-cx/noxfile.py | 3 +- .../samples/snippets/webhook.py | 41 ++++++++----------- .../samples/snippets/webhook_test.py | 2 +- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/packages/google-cloud-dialogflow-cx/noxfile.py b/packages/google-cloud-dialogflow-cx/noxfile.py index 07b2cc991692..37bbd4b00c6f 100644 --- a/packages/google-cloud-dialogflow-cx/noxfile.py +++ b/packages/google-cloud-dialogflow-cx/noxfile.py @@ -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 diff --git a/packages/google-cloud-dialogflow-cx/samples/snippets/webhook.py b/packages/google-cloud-dialogflow-cx/samples/snippets/webhook.py index 098718470dbe..516000cd45f6 100644 --- a/packages/google-cloud-dialogflow-cx/samples/snippets/webhook.py +++ b/packages/google-cloud-dialogflow-cx/samples/snippets/webhook.py @@ -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] diff --git a/packages/google-cloud-dialogflow-cx/samples/snippets/webhook_test.py b/packages/google-cloud-dialogflow-cx/samples/snippets/webhook_test.py index fd91a17bc59c..1d42ff78cc96 100644 --- a/packages/google-cloud-dialogflow-cx/samples/snippets/webhook_test.py +++ b/packages/google-cloud-dialogflow-cx/samples/snippets/webhook_test.py @@ -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)