Skip to content

MikaAK/slack_hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SlackWebhook

Sends simple messages to Slack channel using webhook API.

Usage

  1. Register new integration here: https://my.slack.com/services/new/incoming-webhook/ You will receive Webhook URL similar to https://hooks.slack.com/services/*/*/*

  2. Add dependency in mix.exs.

{:slack_hook, "~> 0.0.1"}
  1. Add Webhook URL to your application configuration.
config :slack_hook, :url, "https://hooks.slack.com/services/*/*/*"
#or
config :slack_hook,
   default_url: "https://hooks.slack.com/services/*/*/*",
   urls: [my_other_point: "https://hooks.slack.com/services/*/*/*"]
  1. Send synchronous message.
SlackWebhook.send "lorem ipsum"
  1. Send asynchronous message.
SlackWebhook.async_send "lorem ipsum"
  1. Send message to configed url.
SlackWebhook.async_send "lorem ipsum", :my_other_point
  1. Send message to configed url.
SlackWebhook.async_send "lorem ipsum", "https://hooks.slack.com/services/*/*/*"

Sync vs Async

Unless you want to handle exceptions, use async_send. If you compare synchronous:

iex(10)> :timer.tc fn -> SlackWebhook.send "test" end
{239446,

And asynchronous:

iex(10)> :timer.tc fn -> SlackWebhook.async_send "test" end
{604, {:ok, %HTTPoison.AsyncResponse{id: #Reference<0.0.2.666>}}}

You will get:

send (avg)| async_send (avg)
----------|-----------------
239446 us | 685 us

Of course, in asynchronous code we don't wait for reply to handle possible errors and that's where the boost come from. If you use Slack notifications for anything critical, use send. Otherwise, use async_send, enjoy speed and clear process mailbox from time to time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages