Skip to content

Commit ca90f59

Browse files
authored
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
1 parent cd5e1e7 commit ca90f59

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

Dialogflow-CX/webhook.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,29 @@ def handle_webhook(request):
2525
tag = req["fulfillmentInfo"]["tag"]
2626

2727
if tag == "Default Welcome Intent":
28-
# You can also use the google.cloud.dialogflowcx_v3.types.WebhookRequest protos instead of manually writing the json object
29-
# Please see https://googleapis.dev/python/dialogflow/latest/dialogflow_v2/types.html?highlight=webhookresponse#google.cloud.dialogflow_v2.types.WebhookResponse for an overview
30-
res = {
31-
"fulfillment_response": {
32-
"messages": [{"text": {"text": ["Hi from a GCF Webhook"]}}]
33-
}
34-
}
28+
text = "Hello from a GCF Webhook"
3529
elif tag == "get-name":
36-
res = {
37-
"fulfillment_response": {
38-
"messages": [{"text": {"text": ["My name is Phlowhook"]}}]
39-
}
40-
}
30+
text = "My name is Flowhook"
4131
else:
42-
res = {
43-
"fulfillment_response": {
44-
"messages": [
45-
{
46-
"text": {
47-
"text": [
48-
f"There are no fulfillment responses defined for {tag} tag"
49-
]
50-
}
32+
text = f"There are no fulfillment responses defined for {tag} tag"
33+
34+
# You can also use the google.cloud.dialogflowcx_v3.types.WebhookRequest protos instead of manually writing the json object
35+
# Please see https://googleapis.dev/python/dialogflow/latest/dialogflow_v2/types.html?highlight=webhookresponse#google.cloud.dialogflow_v2.types.WebhookResponse for an overview
36+
res = {
37+
"fulfillment_response": {
38+
"messages": [
39+
{
40+
"text": {
41+
"text": [
42+
text
43+
]
5144
}
52-
]
53-
}
45+
}
46+
]
5447
}
48+
}
5549

5650
# Returns json
5751
return res
5852

59-
6053
# [END dialogflow_cx_webhook]

Dialogflow-CX/webhook_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def app():
3131
def test_handle_webhook(app):
3232
with app.test_request_context(json=request):
3333
res = handle_webhook(flask.request)
34-
assert "Hi from a GCF Webhook" in str(res)
34+
assert "Hello from a GCF Webhook" in str(res)

0 commit comments

Comments
 (0)