|
| 1 | +# Copyright 2021, Google LLC |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +# See the License for the specific language governing permissions and |
| 12 | +# limitations under the License. |
| 13 | + |
| 14 | +# returns fullfillment response for dialogflow detect_intent call |
| 15 | + |
| 16 | +# [START dialogflow_webhook] |
| 17 | +def handleWebhook(request): |
| 18 | + |
| 19 | + req = request.get_json() |
| 20 | + |
| 21 | + responseText = "" |
| 22 | + intent = req["queryResult"]["intent"]["displayName"] |
| 23 | + |
| 24 | + if intent == "Default Welcome Intent": |
| 25 | + responseText = "Hello from a GCF Webhook" |
| 26 | + elif intent == "get-agent-name": |
| 27 | + responseText = "My name is Flowhook" |
| 28 | + else: |
| 29 | + responseText = f"There are no fulfillment responses defined for Intent {intent}" |
| 30 | + |
| 31 | + # You can also use the google.cloud.dialogflowcx_v3.types.WebhookRequest protos instead of manually writing the json object |
| 32 | + res = {"fulfillmentMessages": [{"text": {"text": [responseText]}}]} |
| 33 | + |
| 34 | + return res |
| 35 | + |
| 36 | + |
| 37 | +# [END dialogflow_webhook] |
0 commit comments