A Slack RTM and Web APIs client.
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
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"]})
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})
api
apps
- apps.uninstall
- apps.permissions.info
- apps.permissions.request
- apps.permissions.resources.list
- apps.permissions.scopes.list
- apps.permissions.users.list
- apps.permissions.users.request
auth
bots
chat
- chat.delete
- chat.deleteScheduledMessage
- chat.getPermalink
- chat.meMessage
- chat.postEphemeral
- chat.postMessage
- chat.scheduleMessage
- chat.unfurl
- chat.update
conversations
- conversations.archive
- conversations.close
- conversations.create
- conversations.history
- conversations.info
- conversations.invite
- conversations.join
- conversations.kick
- conversations.leave
- conversations.list
- conversations.members
- conversations.open
- conversations.rename
- conversations.replies
- conversations.setPurpose
- conversations.setTopic
- conversations.unarchive
dialog
dnd
emoji
files
- files.delete
- files.info
- files.list
- files.revokePublicURL
- files.sharedPublicURL
- files.upload
- files.comments.delete
- files.remote.add
- files.remote.info
- files.remote.list
- files.remote.remove
- files.remote.share
- files.remote.update
migration
oauth
pins
reactions
reminders
rtm
search
team
usergroups
- usergroups.create
- usergroups.disable
- usergroups.enable
- usergroups.list
- usergroups.update
- usergroups.users.list
- usergroups.users.update
users
- users.conversations
- users.deletePhoto
- users.getPresence
- users.identity
- users.info
- users.list
- users.lookupByEmail
- users.setActive
- users.setPhoto
- users.setPresence
- users.profile.get
- users.profile.set
admin.apps
- admin.apps.approve
- admin.apps.restrict
- admin.apps.approved.list
- admin.apps.requests.list
- admin.apps.restricted.list
admin.conversations
admin.emoji
admin.inviteRequests
- admin.inviteRequests.approve
- admin.inviteRequests.deny
- admin.inviteRequests.list
- admin.inviteRequests.approved.list
- admin.inviteRequests.denied.list
admin.teams
- admin.teams.create
- admin.teams.list
- admin.teams.admins.list
- admin.teams.owners.list
- admin.teams.settings.info
- admin.teams.settings.setDefaultChannels
- admin.teams.settings.setDescription
- admin.teams.settings.setDiscoverability
- admin.teams.settings.setIcon
- admin.teams.settings.setName
admin.users
- admin.users.assign
- admin.users.invite
- admin.users.list
- admin.users.remove
- admin.users.setAdmin
- admin.users.setExpiration
- admin.users.setOwner
- admin.users.setRegular
- admin.users.session.reset
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/slack_api.