{"id":24307905,"url":"https://github.com/expecho/self-hosted-asp.net-webhooks","last_synced_at":"2025-09-26T13:30:46.298Z","repository":{"id":10663234,"uuid":"66544735","full_name":"Expecho/Self-Hosted-Asp.Net-WebHooks","owner":"Expecho","description":"Self hosted custom webhook receiver and sender","archived":false,"fork":false,"pushed_at":"2022-12-08T05:22:57.000Z","size":44,"stargazers_count":52,"open_issues_count":6,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-03T23:56:19.424Z","etag":null,"topics":["asp-net","asp-net-web-api-2","c-sharp","csharp","self-hosted","webhook","webhooks"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Expecho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-25T09:29:04.000Z","updated_at":"2023-08-03T23:56:19.424Z","dependencies_parsed_at":"2023-01-11T17:55:09.871Z","dependency_job_id":null,"html_url":"https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Expecho%2FSelf-Hosted-Asp.Net-WebHooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Expecho%2FSelf-Hosted-Asp.Net-WebHooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Expecho%2FSelf-Hosted-Asp.Net-WebHooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Expecho%2FSelf-Hosted-Asp.Net-WebHooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Expecho","download_url":"https://codeload.github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234310929,"owners_count":18812170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net","asp-net-web-api-2","c-sharp","csharp","self-hosted","webhook","webhooks"],"created_at":"2025-01-17T04:20:40.000Z","updated_at":"2025-09-26T13:30:46.007Z","avatar_url":"https://github.com/Expecho.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Asp.Net WebHooks\nSelf hosted custom webhook receiver and sender.\nMore about webhooks: https://docs.asp.net/projects/webhooks/en/latest/. The product repo can be found [here](https://github.com/aspnet/aspnetwebhooks).\n\nThe solution contains 2 projects:\n\n## Receiver\nThis console application sends a registration for a Webhook and receives message of the Webhook. It also calls the api that triggers the Webhook to send a notification.\n\nThere are two ways to receive custom webhooks. One is using the build in mechanism that works by implementing your own `WebHookHandler`:\n\n```csharp\n    public class CustomWebHookHandler : WebHookHandler\n    {\n        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)\n        {\n            var notifications = context.GetDataOrDefault\u003cCustomNotifications\u003e();\n            \n            Console.WriteLine($\"Received notification with payload:\");\n            foreach (var notification in notifications.Notifications)\n            {\n                Console.WriteLine(string.Join(\", \", notification.Values));\n            }\n\n            return Task.FromResult(true);\n        }\n    }\n```\n\n*([Source](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/CustomWebHookHandler.cs))*\n    \nFor this to work the next line is added to the [web api configuration section](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/Startup.cs#L23)\n\n    config.InitializeReceiveCustomWebHooks();\n    \n\nThe other one is by creating your own web api controller that accepts a POST method like outlined [here](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/WebhookController.cs)\n\nThe registrations of the webhook takes place in [Program.cs](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/Program.cs#L28)\n\n## Web Api Host\nThis console application hosts the Webhook registration endpoints and hosts a web api controller that triggers the Webhook.\n\nMost of the configuration to support custom webhook registrations is done [here](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/WebApi/Startup.cs#L20):\n\n```csharp\n    var config = new HttpConfiguration();\n\n    config.MapHttpAttributeRoutes();\n\n    config.Routes.MapHttpRoute(\n                    \"DefaultApi\",\n                    \"api/{controller}/{id}\",\n                    new { id = RouteParameter.Optional }\n                );\n\n    config.InitializeCustomWebHooks();\n    config.InitializeCustomWebHooksApis(); \n\n    HttpListener listener = (HttpListener)appBuilder.Properties[\"System.Net.HttpListener\"];\n    listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;\n```    \n\n## Usage\nSet the startup projects of the solution to both projects and run the solution. Wait until both projects are fully loaded and then start interacting according to the instructions given.\n\n# Points of interest\nThere are some not so very well documented features you should know of before throwing the towel in the ring.\n\n## Endpoint verification\nIf you create your own controller with a POST method to facilitate incoming webhooks you have to have a GET method also that accepts an Echo parameter and returns the exact content of that parameter in plain text. Failure to do so will result in the following error when you register your webhook:\n\n\u003e WebHook verification failed. Please ensure that the WebHook URI is valid and that the endpoint is accessible.\n\nTo disable this verification you can include the NoEcho parameter upon registration like this:\n\n```csharp\n    // Create a webhook registration to our custom controller\n    var registration = new Registration\n    {\n        WebHookUri = $\"{webhookReceiverBaseAddress}/api/webhook?NoEcho=1\",\n        Description = \"A message is posted.\",\n        Secret = \"12345678901234567890123456789012\",\n\n        // Remove the line below to receive all events, including the MessageRemovedEvent event.\n         Filters = new List\u003cstring\u003e { \"MessagePostedEvent\" } \n     };\n```\n\n*(See [the registration](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/Program.cs#L28) and [the GET method](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/WebhookController.cs#L21))*\n\n## Persisted registrations\n\nThis example, as most examples found regarding this topic, uses an in-memory store to store registrations. To persist registration you can use an [out-of-the box solution](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/master/WebApi/Program.cs#L22) or write your own.\n\n## Secrets\n\nWhen using a [custom webhook handler](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/4ea52401150c47a647d2ffebdc4794573ebfe2a0/Receiver/CustomWebHookHandler.cs) it is important to have matching secrets using the `MS_WebHookReceiverSecret_Custom` application setting.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpecho%2Fself-hosted-asp.net-webhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpecho%2Fself-hosted-asp.net-webhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpecho%2Fself-hosted-asp.net-webhooks/lists"}