In this post, we will go through an example of storing data from Kaizala in Azure Table Storage. If you are not familiar with Kaizala webhooks, please read this post for an introduction.
This post has been classified broadly into these sections:
- Azure Function to handle Kaizala webhook data
- Registering a webhook
- Testing out
Azure Function to handle Kaizala webhook data
In case you are new to Azure Functions, you can follow this article on Microsoft documentation for an introduction. The example in this post will use a http triggered Azure Function written in C#.
There are broadly 2 areas we will need to handle in the Azure Function:
- Handling the validation token
- Handling the webhook callback data
Handling the validation token
Kaizala service validates the endpoint being used to subscribe for webhooks by issuing a GET request to the provided URL with the validation token in the query string parameter. For a successful validation, you will need to return the validation token as plain text in the response body. Below screenshot shows the code for this:
Handling the webhook callback data
Once the webhook has been successfully registered, Kaizala service would give callback through a POST request with data in the request body. In our example, we would store the data in an Azure Cloud Table. Below screenshot has the code where the data is parsed and stored into the Azure table. Post processing the data, you will need to return a 200 OK back to Kaizala service within 60 seconds. If you fail to do this, Kaizala service will mark your webhook callback as a failure and will retry and after a few retries will disable the webhook.
Registering a webhook
Once your Azure Function is ready, you can register a webhook to your Azure Function. Get the URL of your Azure function (if you are unfamiliar of how, you can refer to this article again).
You can use Postman REST client to register the webhook. Below screenshot is an example:
On successful registration, you should get a 200 OK with the webhook id in the response.
Below is a screenshot of the Azure Table Storage with the data from Kaizala.
Hope this was helpful in getting started with Kaizala Webhooks leveraging Azure Functions. If you would like to get updates each time an article is published, you could subscribe to this blog.
The C# file for the code in this example has been shared here. Feel free to share your comments / questions / feedback in the comments section.