Skip to content

undr/slack_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SlackAPI

A Slack RTM and Web APIs client.

Installation

If available in Hex, the package can be installed by adding slack_api to your list of dependencies in mix.exs:

def deps do
  [
    {:slack_api, "~> 0.1.0"}
  ]
end

Real Time Messaging API

defmodule ErrorHandler do
  @behaviour SlackAPI.RTM.ErrorHandler.Behaviour

  def handle(error) do
    # Handle an error
  end

  def handle(exception, strace) do
    # Handle an exception
  end
end
defmodule RTMHandler do
  use SlackAPI.RTM.Handler

  error ErrorHandler

  def init(data, opts) do
    # prepare a state
    {:ok, state}
  end

  def handle_connect(conn, state) do
    # Handle `connect` event.
    {:ok, state}
  end

  def handle_disconnect(conn, state) do
    # Handle `disconnect` event.
    {:ok, state}
  end

  def handle_message(message, state) do
    # Handle `message` event.
    {:ok, state}
  end

  def handle_cast(message, state) do
    # Handle `cast` event.
    # WebSockex.cast(websocket, {:event, "data"})
    {:ok, state}
  end

  def handle_info(message, state) do
    # Handle `info` event.
    # send(websocket, {:event, "data"})
    {:ok, state}
  end
end
{:ok, websocket} = SlackAPI.RTM.start({RTMHandler, [token: "TOKEN", url: "https://slack.com"]})

Web API

client = SlackAPI.Web.new(token: "TOKEN", url: "https://slack.com")
SlackAPI.Web.api().test(client, foo: "bar")
SlackAPI.Web.api().test(client, %{foo: "bar"})

All required params should be explicitly passed into a function as arguments. Order this arguments should be the same as in the list of params in Slack docs.

Optional params should be passed as a map() or Keyword.t(). Excess arguments will be filtered out.

client = SlackAPI.Web.new(token: "TOKEN", url: "https://slack.com")
SlackAPI.Web.channels().test(client, "channel-name", validate: true)
SlackAPI.Web.channels().create(client, "channel-name", %{validate: true})

Supported endpoints:

api

apps

auth

bots

chat

conversations

dialog

dnd

emoji

files

migration

oauth

pins

reactions

reminders

rtm

search

team

usergroups

users

To Do:

admin.apps

admin.conversations

admin.emoji

admin.inviteRequests

admin.teams

admin.users

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/slack_api.

About

An RTM API and Web API clients for Slack.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages