Integrate with Slack
This document is obsolete. You should integrate with Slack using our Slack App. In fact, Slack recommend not sharing test tokens outside your company, which is why this guide probably will be deleted in the near future.
Start by copying your Slack-token from the API page. We will need this when setting up the integration.
On elmah.io, go to the Rules tab beneath your log settings. In this example we want a message on Slack every time a new error is logged in our elmah.io log. To do this, name your rule and input a query like illustrated on the following screenshot:
Hit the Then link and select HTTP request. Input the following values (remember to replace YOUR_TOKEN and YOUR_CHANNEL):
The final result should look like this:
Don't worry about the empty Content-Type and Body. Everything needed to post the message to Slack is embedded into the URL. To learn more about the structure of the URL, jump to Breaking it down
Click the OK button and add the new rule by clicking Add. This configuration tells elmah.io, to make a HTTP request against the Slack API, every time a new error is logged. The message at elmah.io is shown as the chat message inside Slack:
Slack doesn't allow more than a single request per second. If you generate more than one message to elmah.io per second, not all of them will show up in Slack because of this.
Breaking it down
You should have received a message on Slack already. To learn more about how to specify and extend the configuration for Slack, this is the section for you. Let's start by inspecting the simplest possible Slack URL:
The initial part (
https://slack.com/api/chat.postMessage) points out the method to invoke on Slack. In this case, we want to post a new message (
token query parameter contains your access token as found on the API page.
channel parameter contains the name or the ID of the channel you want to post the chat message to. In the example above, I specify the #general channel, but it can be any channel on your account. Observe how I've URL encoded the
Next up is the
text parameter which contains the actual message we want to post to #general. By inserting
$message, I tell elmah.io to insert the title or headline of the logged message. In case of an exception, this will be the exception message generated at your website. elmah.io supports a range of variables, available on the Rules tab on the log settings.
To add a sender name other than
Bot, add a
username parameter like this:
If you want a nice profile icon as well, you can append the following parameter:
&icon_url=https://elmah.io/icons/AppIcon50x50.png. This tells Slack to show a nice elmah.io icon next to the chat messages.
This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening and help you fix errors fast.