

Nowadays, webhooks are very important because every application uses live notifications. Webhooks gives relaxation to the server and notifies when some event happens. In conventional ways, a web application keeps fetching data from the database rather than waiting for any event that overwhelms the server by compromising more resources. Sometimes, you only need data when something happens, otherwise, you don't require any data. In a web application, when something happens or an event occurs a message is posted via URL. Webhook is a very friendly and helpful way to get notified when something happens. It is mostly used in making single-page and mobile applications. The SlackResponse is just a helper formatting the response as expected by Slack.React is a JS library that is used to build user interfaces. Further, as the Slack WebHook can return data, we use the Response property on the WebHookHandlerContext to define the data we want to return. Slack sends WebHook data in the form of HTML Form data so we read it as a NameValueCollection. As stated in the blog Introducing Microsoft ASP.NET WebHooks Preview, the preferred way to do this is to set it in the Azure Portal: This is done by setting the MS_WebHookReceiverSecret_Slack app setting for your Web Application to the value of the secret Token obtained from before. The second part is to set the secret token so that it can be verified by the receiver. The first part of the configuration is done in WebApiConfig.cs where you add line 17 like this:ģ: public static void Register(HttpConfiguration config)ġ2: routeTemplate: "api/ġ7: config.InitializeReceiveSlackWebHooks() After having installed the .Slack Nuget package into your ASP.NET application, this happens exactly like show in the blog Introducing Microsoft ASP.NET WebHooks Preview: The last part is to configure the WebHook receiver.

The URI must have the form Configuring Receiver Fill in whatever trigger words and WebHook URI, and copy the Token for use later. Pick the Outgoing WebHooks integration, select Add Outgoing WebHooks Integration and look for the fields Trigger Words, URLs, and Token. Then you configure the WebHook using what they call an Integration as follows: To setup Slack WebHooks you need a Slack account. For example, if you have a trigger word AskMe: then you can get the WebHook to respond like this: In addition, it is possible for the WebHook to send data back to the channel which is very useful. Slack provides an interesting model where you can set up a WebHook to be fired when a certain trigger word is used in one of their messaging channels.

In the blog Introducing Microsoft ASP.NET WebHooks Preview, we gave an overview of how to work with Microsoft ASP.NET WebHooks.
