Webhook Event to Azure analyze


Webhooks when Serverless Development use, part 3 Webhook Event to Azure analyze

In this Tutorial do not expand the section, we use our Azure Function so that it just says, using the http Trigger “Hello”, but concrete information about the Event provides. For this purpose, the Webhook, we have configured in the second part as an example to a GitHub Wiki.

Company to the topic

Our Azure Function parses a Webhook Request and returns a response.Our Azure Function parses a Webhook Request and returns a response.

(Image: Three Of A Kind / Azure)

As a reminder: our Webhook is executed when a specific event occurs, and then sends it using the URL for the Azure function to make a request to this URL. The transported payload is passed to the Azure function.

So far, our Azure Function does nothing, since it only to the Node.js-Sample-Code to Azure Function Apps for http is the Trigger. Now our function is to analyze the requirement of the text to extract the fields from the payload and, if necessary, the desired action. In the following example, we give the determined information only.

The following Code Fragment from the Microsoft documentation is extracted, for example, the name of the GitHub Repositories from the payload. This type of event is in the x-github-event-request header. This data can be used to print the response of the function:

if (req.body.repository.name){
context.res = {
body: "Repository is: " + req.body.repository.name + ", Event Type is: " +
req.headers['x- github-event']

Now we want to adapt our existing Azure Function, we analyze the payload of the Webhooks. To do this, we navigate in the Azure Portal again to our function App, click on “functions” and select the part 1 of the created function. Then we click again on “program and test” and select to update our “index.js” the file with the following Code:

module.exports = async function (context, req) {
context.log('JavaScript http trigger function processed a request.');
if (req.body.pages[0].title){
context.res = {
body: "Page is " + req.body.pages[0].title + ", Action is " +
req.body.pages[0].action + ", Event Type is " + req.headers['x-github-event']
else {
context.res = {
status: 400,
body: ("Invalid payload for Wiki event")

This Code extracts the event type from the request Header, the title and the fields of action from the message text. We can determine whether the page is modified, edited, or re-created. The Code also generates a response, which summarizes the action together.

With the With the “Redeliver” the Webhook again propose a toast.

(Image: Three Of A Kind / Azure)

Then we switch to our GitHub Repo, navigate again to “Settings”, for “Webhooks” and click on “Edit”. To scroll there, we “Recent Deliveries” button below of the Delivery ID right on the three dots and then click the “Redeliver”button.

As a response, you should get something in the following Form:

Page is <Name der Site>, Action is <edited> (oder <created>), Event Type is gollum

Our Azure-Function analysis of the Webhook Request and returns the response.Our Azure-Function analysis of the Webhook Request and returns the response.

(Image: Three Of A Kind / Azure)

You recognize, therefore, that the Webhook has triggered our function. This will then analyze the information (working solutions) and back sent the above answer.

Ready to see us in action:

More To Explore

Enable registration in settings - general
Have any project in mind?

Contact us: