SlackSandbox.Adapter behaviour (slack_sandbox v0.1.0)

Copy Markdown View Source

Behaviour for the two calls most Slack integrations actually make: posting to a channel and DMing a user.

Implement this in your real Slack client, and swap in SlackSandbox itself (which implements it too) for dev/test:

# config/dev.exs
config :my_app, :slack_adapter, SlackSandbox

# config/prod.exs
config :my_app, :slack_adapter, MyApp.Slack.HttpAdapter

# in your app
adapter = Application.fetch_env!(:my_app, :slack_adapter)
adapter.post_message("Deploy finished", "#ops")

Summary

Callbacks

post_message(text, channel)

@callback post_message(text :: String.t(), channel :: String.t()) ::
  :ok | {:error, term()}

send_dm(slack_id, text)

@callback send_dm(slack_id :: String.t(), text :: String.t()) :: :ok | {:error, term()}