Author picture Rodriq Jaro

How to Receive and Replay External Webhooks in Azure Functions with Hookdeck

Published


Webhooks play a crucial role in modern application development as they enable real-time communication and data transfer between different systems. They are especially important when it comes to Azure Functions, which provides serverless computing on the Microsoft Azure cloud and allows you to run event-driven code without having to manage infrastructure.

Hookdeck is a webhook management platform that helps you securely receive, replay and monitor webhook events from any webhook source to a destination. By integrating Hookdeck with Azure Functions, you can enhance the reliability and management of your webhook events, ensuring seamless integration with external systems.

In this guide, I will show you how to leverage Hookdeck to receive and replay webhooks for Azure Functions.

Create an Azure function

Let’s start by creating a simple Azure function that can handle incoming webhook requests.

  • In the Azure Portal, create a new function app from the list of available resources.
    • Fill in the app name and select Node.js (for this example) as the Runtime stack and Review + create.

Azure Create Function App

  • The function app gets deployed. Click on Create a function to create a new Azure function.

Create Azure function

  • Add a new HTTP-triggered function from the list of function templates and name it WebhookHandler and Create.

Create Azure HTTP trigger function

  • Click on the Code + Test menu from the side panel and replace the code with the example below and Save.

    module.exports = async function (context, req) {
      context.log("Webhook triggered");
    
      if (req.method === "POST") {
        try {
          // Process webhook payload
          const data = req.body;
          console.log(data);
          context.res = {
            status: 200,
            body: {
              message: "Webhook processed successfully",
            },
          };
        } catch (error) {
          context.log.error("Error handling webhook: ", error);
          context.res = {
            status: 500,
            body: {
              error: "An error occurred while processing the webhook",
            },
          };
        }
      } else {
        context.res = {
          status: 405,
          body: "Method Not Allowed",
        };
      }
    };
    
  • On the overview page of the function, click on Get Function Url and copy the HTTP URL provided. It is needed below.

Get Azure function URL

This basic Azure function can receive and process webhooks from external platforms. Learn more here.

Replay webhooks with Hookdeck

Using Hookdeck as a gateway between your source platform webhooks to the Azure function, you can replay any failed event that doesn’t make it to Azure by following the steps below.

Create a Hookdeck connection

  • Go to Hookdeck Dashboard and create a new Connection:
    • Source: The external platform sending webhooks
    • Destination: The HTTP URL of the Azure Function created earlier

Create Azure Hookdeck connection

After creating the connection, you are given a URL to use on the source platform.

The created connection makes it possible for webhooks from the source to be sent to the function via Hookdeck.

Receiving webhook events

You can utilize Hookdeck Console to simulate example webhooks from popular webhook sources.

Say for example your webhook source is GitHub. When an event is triggered, it can be seen on the Hookdeck dashboard and also monitored on Azure Portal logs.

  • On the source platform, configure webhooks using the Hookdeck URL provided.
  • When events occur, switch to the Events tab on your Hookdeck dashboard from the side panel and filter as per the connection created above. This shows the activities of events on that connection.

Hookdeck Azure Events log

  • In the Azure Portal, switch to the Monitor > Logs tab of the function to see it handling events.

Azure Portal Monitor logs

Replaying error or failed events

One of the key features provided by Hookdeck is the ability to replay webhooks. This is useful when you need to replay a failed webhook event in cases where the Azure function doesn’t execute properly.

  • In Hookdeck Events, click the Retry button on the failed event.
  • This replays it to the Azure function, allowing it to process again.

Replay Azure function

Now you know how to receive and replay webhook events in Azure Functions using Hookdeck. By leveraging Hookdeck's powerful features such as security, routing, and analytics, you can effectively manage and troubleshoot webhook events from any third-party platform seamlessly.

Check out the Hookdeck documentation to learn more!