Skip to content

Latest commit

History

26 Commits

Folders and files

NameName
Last commit message
Last commit date

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:

defdepsdo[{:slack_api,"~> 0.1.0"}]end

Real Time Messaging API

defmoduleErrorHandlerdo@behaviourSlackAPI.RTM.ErrorHandler.Behaviourdefhandle(error)do# Handle an errorenddefhandle(exception,strace)do# Handle an exceptionendend
defmoduleRTMHandlerdouseSlackAPI.RTM.HandlererrorErrorHandlerdefinit(data,opts)do# prepare a state{:ok,state}enddefhandle_connect(conn,state)do# Handle `connect` event.{:ok,state}enddefhandle_disconnect(conn,state)do# Handle `disconnect` event.{:ok,state}enddefhandle_message(message,state)do# Handle `message` event.{:ok,state}enddefhandle_cast(message,state)do# Handle `cast` event.# WebSockex.cast(websocket, {:event, "data"}){:ok,state}enddefhandle_info(message,state)do# Handle `info` event.# send(websocket, {:event, "data"}){:ok,state}endend
{: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

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages