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 committed Jun 28, 2022
1 parent cd5e1e7 commit ca90f59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
41 changes: 17 additions & 24 deletions Dialogflow-CX/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]
2 changes: 1 addition & 1 deletion Dialogflow-CX/webhook_test.py
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 ca90f59

Please sign in to comment.