Provides a Slack notifier for the BoomNotifier exception notification package.
You can read the full documentation at https://hexdocs.pm/boom_slack_notifier.
The package can be installed by adding boom_slack_notifier
to your list of dependencies in
mix.exs
:
def deps do
[
{:boom_notifier, "~> 0.8.0"},
{:boom_slack_notifier, "~> 0.1.0"}
]
end
defmodule YourApp.Router do
use Phoenix.Router
use BoomNotifier,
notifier: BoomSlackNotifier.SlackNotifier,
options: [
webhook_url: "<your-slack-generated-url>",
]
# ...
To configure it, you need to set the webhook_url
in the options
keyword list. A POST
request with a json
will be made to that webhook when an error ocurrs with the relevant information.
If you don't already have a webhook setup for Slack, you can follow the steps below:
- Go to Slack API > My Apps
- Create a new application
- Inside your new application go to > Add features and functionality > Incoming Webhooks
- Activate incoming webhooks for your application
- Scroll down to 'Webhook URLs for Your Workspace' and create a new Webhook URL for a given channel.
By default BoomSlackNotifier uses HTTPoison as the http client.
You can setup your favorite client by warpping it with the SlackAdapter
behaviour, for example:
#mojito_http_adapter.ex
@impl BoomSlackNotifier.SlackAdapter
@spec post(any, binary, any) :: {:ok, any} | {:error, any}
def post(body, url, headers) do
{:ok, response} = Mojito.request(body: body, method: :post, url: url, headers: headers)
# ...
end
And then specifying it in your application configuration:
#config.exs
config :boom_slack_notifier, :slack_adapter, MyApp.MojitoHttpAdapter
Default configuration (not required):
config :boom_slack_notifier, :slack_adapter, BoomSlackNotifier.SlackClient.HTTPoisonAdapter
BoomSlackNotifier is released under the terms of the MIT License.