You will now make slight modifications to the Node.js code in order to secure the webhook. The one you deployed is not secure and anyone can access it.
- Go to Dialogflow and to the Fulfillment section.
- In the headers, add the key mysecret and the value 12345.
The following screenshot shows the security header added to the webhook:
Securing the webhook
- Edit server.js. Add code that extracts the mysecret key using let secret = req.get("mysecret"). Then, check the value and see if it is equal to 12345. If it is equal, process the request, and if not, return a 403 access denied response return response.status(403).end('Access denied!').
The following code shows the modified code that secures the webhook:
app.post('/fortuneCookie', function (req, res) {
let secret = req.get("mysecret");
if...