├── test ├── test_helper.exs └── slack_test.exs ├── lib ├── slack │ ├── client.ex │ ├── rtm.ex │ ├── api.ex │ ├── bot.ex │ ├── team │ │ └── profile.ex │ ├── emoji.ex │ ├── oauth.ex │ ├── user │ │ └── profile.ex │ ├── user_group │ │ └── user.ex │ ├── search.ex │ ├── auth.ex │ ├── star.ex │ ├── pin.ex │ ├── file │ │ └── comment.ex │ ├── team.ex │ ├── chat.ex │ ├── reminder.ex │ ├── user_group.ex │ ├── im.ex │ ├── reaction.ex │ ├── mpim.ex │ ├── dnd.ex │ ├── user.ex │ ├── request.ex │ ├── file.ex │ ├── channel.ex │ └── group.ex └── slack.ex ├── .gitignore ├── README.md ├── LICENSE.md ├── config └── config.exs ├── mix.exs ├── CONTRIBUTING.md └── mix.lock /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /test/slack_test.exs: -------------------------------------------------------------------------------- 1 | defmodule SlackTest do 2 | use ExUnit.Case 3 | doctest Slack 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/slack/client.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Client do 2 | @moduledoc """ 3 | A struct containing an authorization token 4 | """ 5 | 6 | @enforce_keys [:token] 7 | 8 | defstruct token: "" 9 | 10 | @type t :: %__MODULE__{token: String.t} 11 | end 12 | -------------------------------------------------------------------------------- /lib/slack/rtm.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.RTM do 2 | @moduledoc """ 3 | Functions for creating Real Time Messaging API sessions 4 | """ 5 | 6 | @base "rtm" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Start an RTM API session. 12 | 13 | https://api.slack.com/methods/rtm.start 14 | 15 | ## Examples 16 | 17 | Slack.RTM.start(client) 18 | """ 19 | @spec start(Slack.Client.t, Keyword.t) :: Slack.response 20 | defpost :start 21 | end 22 | -------------------------------------------------------------------------------- /lib/slack/api.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.API do 2 | @moduledoc """ 3 | Functions for checking calling code 4 | """ 5 | 6 | @base "api" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Test calling code. 12 | 13 | https://api.slack.com/methods/api.test 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.API.test(foo: "bar") 19 | """ 20 | @spec test(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :test 22 | end 23 | -------------------------------------------------------------------------------- /lib/slack/bot.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Bot do 2 | @moduledoc """ 3 | Functions for getting information about bots 4 | """ 5 | 6 | @base "bots" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Get info for a bot. 12 | 13 | https://api.slack.com/methods/bots.info 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.Bot.info(bot: "B12345678") 19 | """ 20 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defget :info 22 | end 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /lib/slack/team/profile.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Team.Profile do 2 | @moduledoc """ 3 | Functions for team profiles 4 | """ 5 | 6 | @base "team.profile" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Get the profile field definitions for the team. 12 | 13 | https://api.slack.com/methods/team.profile.get 14 | 15 | ## Examples 16 | 17 | Slack.Team.Profile.get(client) 18 | """ 19 | @spec get(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defget :get 21 | end 22 | -------------------------------------------------------------------------------- /lib/slack/emoji.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Emoji do 2 | @moduledoc """ 3 | Functions for working with a team's custom emoji 4 | """ 5 | 6 | @base "emoji" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | List the custom emoji for a team. 12 | 13 | https://api.slack.com/methods/emoji.list 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.Emoji.list 19 | """ 20 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defget :list 22 | end 23 | -------------------------------------------------------------------------------- /lib/slack/oauth.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.OAuth do 2 | @moduledoc """ 3 | Functions for handling OAuth code/token exchange 4 | """ 5 | 6 | @base "oauth" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Exchange an OAuth code for a Slack API access token. 12 | 13 | https://api.slack.com/methods/oauth.access 14 | 15 | ## Examples 16 | 17 | Slack.OAuth.access( 18 | client_id: "client_id", client_secret: "client_secret", code: "code") 19 | """ 20 | @spec access(Keyword.t) :: Slack.slack_response 21 | defrequest access(params \\ []) do 22 | Slack.get "#{@base}.access", [], params: params 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SlackEx 2 | 3 | A client for the Slack API. 4 | 5 | ## Usage 6 | 7 | Most of the API methods work by first creating a Slack client 8 | (`Slack.client(token)`) and then passing it in to an API call. Note that a 9 | `Slack.Client` is only a convenience wrapper for a map with a `:token` key. 10 | 11 | ```elixir 12 | {:ok, %{"channel" => channel}} = 13 | token 14 | |> Slack.client 15 | |> Slack.Channel.create(name: "mynewchannel") 16 | ``` 17 | 18 | ## Installation 19 | 20 | 1. Add `slack` to your list of dependencies in `mix.exs`: 21 | 22 | ```elixir 23 | def deps do 24 | [{:slack_ex, "~> 0.0.14"}] 25 | end 26 | ``` 27 | -------------------------------------------------------------------------------- /lib/slack/user/profile.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.User.Profile do 2 | @moduledoc """ 3 | Functions for working with user profiles 4 | """ 5 | 6 | @base "users.profile" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Get the profile information of a user. 12 | 13 | https://api.slack.com/methods/users.profile.get 14 | 15 | ## Examples 16 | 17 | Slack.User.Profile.get(client, user: "U1234567890") 18 | """ 19 | @spec get(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defget :get 21 | 22 | @doc """ 23 | Set the profile information of a user. 24 | 25 | https://api.slack.com/methods/users.profile.set 26 | 27 | ## Examples 28 | 29 | Slack.User.Profile.set(client, user: "U1234567890", name: "Name") 30 | """ 31 | @spec set(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defpost :set 33 | end 34 | -------------------------------------------------------------------------------- /lib/slack/user_group/user.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.UserGroup.User do 2 | @moduledoc """ 3 | Functions for working with users in user groups 4 | """ 5 | 6 | @base "usergroups.users" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | List users in a usergroup. 12 | 13 | https://api.slack.com/methods/usergroups.users.list 14 | 15 | ## Examples 16 | 17 | Slack.UserGroup.list(client, usergroup: "S0604QSJC") 18 | """ 19 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defget :list 21 | 22 | @doc """ 23 | Update the list of users in a user group. 24 | 25 | https://api.slack.com/methods/usergroups.users.update 26 | 27 | ## Examples 28 | 29 | Slack.UserGroup.update( 30 | client, usergroup: "S0604QSJC", user: "U060R4BJ4,U060RNRCZ") 31 | """ 32 | @spec update(Slack.Client.t, Keyword.t) :: Slack.slack_response 33 | defpost :update 34 | end 35 | -------------------------------------------------------------------------------- /lib/slack/search.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Search do 2 | @moduledoc """ 3 | Functions for searching 4 | """ 5 | 6 | @base "search" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Search messages and files. 12 | 13 | https://api.slack.com/methods/search.all 14 | 15 | ## Examples 16 | 17 | Slack.Search.all(client, query: "My query") 18 | """ 19 | @spec all(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defpost :all 21 | 22 | @doc """ 23 | Search files. 24 | 25 | https://api.slack.com/methods/search.files 26 | 27 | ## Examples 28 | 29 | Slack.Search.files(client, query: "My query") 30 | """ 31 | @spec files(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defpost :files 33 | 34 | @doc """ 35 | Search messages. 36 | 37 | https://api.slack.com/methods/search.messages 38 | 39 | ## Examples 40 | 41 | Slack.Search.messages(client, query: "My query") 42 | """ 43 | @spec messages(Slack.Client.t, Keyword.t) :: Slack.slack_response 44 | defpost :messages 45 | end 46 | -------------------------------------------------------------------------------- /lib/slack/auth.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Auth do 2 | @moduledoc """ 3 | Functions for dealing with access tokens 4 | """ 5 | 6 | @base "auth" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Revoke an access token. 12 | 13 | https://api.slack.com/methods/auth.revoke 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.Auth.revoke 19 | """ 20 | @spec revoke(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defrequest revoke(client, body \\ []) do 22 | body = body |> Keyword.put(:token, client.token) 23 | Slack.post "#{@base}.revoke", {:form, body} 24 | end 25 | 26 | @doc """ 27 | Check and identity an access token. 28 | 29 | https://api.slack.com/methods/auth.test 30 | 31 | ## Examples 32 | 33 | Slack.client(token) 34 | |> Slack.Auth.test 35 | """ 36 | @spec test(Slack.Client.t, Keyword.t) :: Slack.slack_response 37 | defrequest test(client, body \\ []) do 38 | body = body |> Keyword.put(:token, client.token) 39 | Slack.get "#{@base}.test", {:form, body} 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/slack/star.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Star do 2 | @moduledoc """ 3 | Functions for working with starred items 4 | """ 5 | 6 | @base "stars" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Add a star to an item. 12 | 13 | https://api.slack.com/methods/stars.add 14 | 15 | ## Examples 16 | 17 | Slack.Star.add(client, channel: "C1234567890") 18 | """ 19 | @spec add(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defpost :add 21 | 22 | @doc """ 23 | Lists items starred by the user. 24 | 25 | https://api.slack.com/methods/stars.list 26 | 27 | ## Examples 28 | 29 | Slack.Star.list(client) 30 | """ 31 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defget :list 33 | 34 | @doc """ 35 | Remove a star from an item. 36 | Star messages and files. 37 | 38 | https://api.slack.com/methods/stars.remove 39 | 40 | ## Examples 41 | 42 | Slack.Star.remove(client, channel: "C1234567890") 43 | """ 44 | @spec remove(Slack.Client.t, Keyword.t) :: Slack.slack_response 45 | defpost :remove 46 | end 47 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Jonathan Clem 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /lib/slack/pin.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Pin do 2 | @moduledoc """ 3 | Functions for working with pinned items 4 | """ 5 | 6 | @base "pins" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Pin an item to a channel. 12 | 13 | https://api.slack.com/methods/pins.add 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.Pin.add(channel: "C1234567890", file: "F1234567890") 19 | """ 20 | @spec add(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :add 22 | 23 | @doc """ 24 | List pins in a channel. 25 | 26 | https://api.slack.com/methods/pins.list 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.Pin.list(channel: "C1234567890") 32 | """ 33 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defget :list 35 | 36 | @doc """ 37 | Un-pin an item from a channel. 38 | 39 | https://api.slack.com/methods/pins.remove 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.Pin.remove(channel: "C1234567890", file: "F1234567890") 45 | """ 46 | @spec remove(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defpost :remove 48 | end 49 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for 9 | # 3rd-party users, it should be done in your "mix.exs" file. 10 | 11 | # You can configure for your application as: 12 | # 13 | # config :slack, key: :value 14 | # 15 | # And access this configuration in your application as: 16 | # 17 | # Application.get_env(:slack, :key) 18 | # 19 | # Or configure a 3rd-party app: 20 | # 21 | # config :logger, level: :info 22 | # 23 | 24 | # It is also possible to import configuration files, relative to this 25 | # directory. For example, you can emulate configuration per environment 26 | # by uncommenting the line below and defining dev.exs, test.exs and such. 27 | # Configuration from the imported file will override the ones defined 28 | # here (which is why it is important to import them last). 29 | # 30 | # import_config "#{Mix.env}.exs" 31 | -------------------------------------------------------------------------------- /lib/slack/file/comment.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.File.Comment do 2 | @moduledoc """ 3 | Functions for working with comments on files 4 | """ 5 | 6 | @base "files.comments" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Add a comment to an existing file. 12 | 13 | https://api.slack.com/methods/files.comments.add 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.File.Comment.add(file: "F1234467890", comment: "Foo") 19 | """ 20 | @spec add(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :add 22 | 23 | @doc """ 24 | Delete a comment on a file. 25 | 26 | https://api.slack.com/methods/files.comments.delete 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.File.Comment.delete(file: "F1234467890", id: "Fc1234567890") 32 | """ 33 | @spec delete(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defpost :delete 35 | 36 | @doc """ 37 | Edit a comment on a file. 38 | 39 | https://api.slack.com/methods/files.comments.edit 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.File.Comment.edit( 45 | file: "F1234467890", id: "Fc1234567890", comment: "Hello") 46 | """ 47 | @spec edit(Slack.Client.t, Keyword.t) :: Slack.slack_response 48 | defpost :edit 49 | end 50 | -------------------------------------------------------------------------------- /lib/slack/team.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Team do 2 | @moduledoc """ 3 | Functions for working with a Slack team 4 | """ 5 | 6 | @base "team" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Get access logs for a team. 12 | 13 | https://api.slack.com/methods/team.accessLogs 14 | 15 | ## Examples 16 | 17 | Slack.Team.accessLogs(client) 18 | """ 19 | @spec accessLogs(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defget :accessLogs 21 | 22 | @doc """ 23 | Get billabale information for user or users on a team. 24 | 25 | https://api.slack.com/methods/team.billableInfo 26 | 27 | ## Examples 28 | 29 | Slack.Team.billableInfo(client, user: "U1234567890") 30 | """ 31 | @spec billableInfo(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defget :billableInfo 33 | 34 | @doc """ 35 | Get basic team info. 36 | 37 | https://api.slack.com/methods/team.info 38 | 39 | ## Examples 40 | 41 | Slack.Team.info(client) 42 | """ 43 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 44 | defget :info 45 | 46 | @doc """ 47 | Get integration activity logs for the team. 48 | 49 | https://api.slack.com/methods/team.integrationLogs 50 | 51 | ## Examples 52 | 53 | Slack.Team.integrationLogs(client) 54 | """ 55 | @spec integrationLogs(Slack.Client.t, Keyword.t) :: Slack.slack_response 56 | defget :integrationLogs 57 | end 58 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Slack.Mixfile do 2 | use Mix.Project 3 | 4 | @github_url "https://github.com/jclem/slack_ex" 5 | @version "0.2.1" 6 | 7 | def project do 8 | [app: :slack_ex, 9 | description: "A client for the Slack API", 10 | version: @version, 11 | package: package(), 12 | name: "Slack", 13 | homepage_url: @github_url, 14 | source_url: @github_url, 15 | docs: docs(), 16 | elixir: "~> 1.4", 17 | build_embedded: Mix.env == :prod, 18 | start_permanent: Mix.env == :prod, 19 | dialyzer: [plt_add_deps: true], 20 | deps: deps()] 21 | end 22 | 23 | # Configuration for the OTP application 24 | # 25 | # Type "mix help compile.app" for more information 26 | def application do 27 | [extra_applications: []] 28 | end 29 | 30 | defp docs do 31 | [extras: ~w(CONTRIBUTING.md LICENSE.md), 32 | main: "Slack", 33 | source_ref: "v#{@version}"] 34 | end 35 | 36 | # Dependencies can be Hex packages: 37 | # 38 | # {:mydep, "~> 0.3.0"} 39 | # 40 | # Or git/path repositories: 41 | # 42 | # {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"} 43 | # 44 | # Type "mix help deps" for more examples and options 45 | defp deps do 46 | [{:httpoison, "~> 1.4"}, 47 | {:poison, "~> 3.1 or ~> 4.0"}, 48 | {:ex_doc, ">= 0.0.0", only: :dev}] 49 | end 50 | 51 | defp package do 52 | [name: :slack_ex, 53 | licenses: ["MIT"], 54 | maintainers: ["Jonathan Clem "], 55 | links: %{"GitHub" => @github_url}] 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/slack/chat.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Chat do 2 | @moduledoc """ 3 | Functions for handling channel messages 4 | """ 5 | 6 | @base "chat" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Delete a chat message. 12 | 13 | https://api.slack.com/methods/chat.delete 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.Chat.delete(channel: "C1234567890", ts: "1405894322.002768") 19 | """ 20 | @spec delete(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :delete 22 | 23 | @doc """ 24 | Send a "me message" to a channel. 25 | 26 | https://api.slack.com/methods/chat.meMessage 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.Chat.meMessage(channel: "C1234567890", text: "Hello") 32 | """ 33 | @spec meMessage(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defpost :meMessage 35 | 36 | @doc """ 37 | Post a message to a channel. 38 | 39 | https://api.slack.com/methods/chat.postMessage 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.Chat.postMessage(channel: "C1234567890", text: "Hello") 45 | """ 46 | @spec postMessage(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defpost :postMessage 48 | 49 | @doc """ 50 | Update a message in a channel. 51 | 52 | https://api.slack.com/methods/chat.update 53 | 54 | ## Examples 55 | 56 | Slack.client(token) 57 | |> Slack.Chat.postMessage( 58 | channel: "C1234567890", text: "Hello", ts: "1405894322.002768") 59 | """ 60 | @spec update(Slack.Client.t, Keyword.t) :: Slack.slack_response 61 | defpost :update 62 | end 63 | -------------------------------------------------------------------------------- /lib/slack/reminder.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Reminder do 2 | @moduledoc """ 3 | Functions for Reminders 4 | """ 5 | 6 | @base "reminders" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Create a reminder. 12 | 13 | https://api.slack.com/methods/reminders.add 14 | 15 | ## Examples 16 | 17 | Slack.Reminder.add(client, text: "Walk the dog") 18 | """ 19 | @spec add(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defpost :add 21 | 22 | @doc """ 23 | Mark a reminder as completed. 24 | 25 | https://api.slack.com/methods/reminders.complete 26 | 27 | ## Examples 28 | 29 | Slack.Reminder.complete(client, reminder: "Rm12345678") 30 | """ 31 | @spec complete(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defpost :complete 33 | 34 | @doc """ 35 | Delete a reminder. 36 | 37 | https://api.slack.com/methods/reminders.delete 38 | 39 | ## Examples 40 | 41 | Slack.Reminder.delete(client, reminder: "Rm12345678") 42 | """ 43 | @spec delete(Slack.Client.t, Keyword.t) :: Slack.slack_response 44 | defpost :delete 45 | 46 | @doc """ 47 | Get info on a reminder. 48 | 49 | https://api.slack.com/methods/reminders.info 50 | 51 | ## Examples 52 | 53 | Slack.Reminder.info(client, reminder: "Rm12345678") 54 | """ 55 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 56 | defget :info 57 | 58 | @doc """ 59 | List the user's reminders. 60 | 61 | https://api.slack.com/methods/reminders.list 62 | 63 | ## Examples 64 | 65 | Slack.Reminder.list(client) 66 | """ 67 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 68 | defget :list 69 | end 70 | -------------------------------------------------------------------------------- /lib/slack/user_group.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.UserGroup do 2 | @moduledoc """ 3 | Functions for a team's User Groups 4 | """ 5 | 6 | @base "usergroups" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Create a new user group. 12 | 13 | https://api.slack.com/methods/usergroups.create 14 | 15 | ## Examples 16 | 17 | Slack.UserGroup.create(client, name: "usergroup") 18 | """ 19 | @spec create(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defpost :create 21 | 22 | @doc """ 23 | Disable a user group. 24 | 25 | https://api.slack.com/methods/usergroups.disable 26 | 27 | ## Examples 28 | 29 | Slack.UserGroup.disable(client, usergroup: "S0604QSJC") 30 | """ 31 | @spec disable(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defpost :disable 33 | 34 | @doc """ 35 | Enable a user group. 36 | 37 | https://api.slack.com/methods/usergroups.enable 38 | 39 | ## Examples 40 | 41 | Slack.UserGroup.enable(client, usergroup: "S0604QSJC") 42 | """ 43 | @spec enable(Slack.Client.t, Keyword.t) :: Slack.slack_response 44 | defpost :enable 45 | 46 | @doc """ 47 | List user groups for the team. 48 | 49 | https://api.slack.com/methods/usergroups.list 50 | 51 | ## Examples 52 | 53 | Slack.UserGroup.list(client) 54 | """ 55 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 56 | defget :list 57 | 58 | @doc """ 59 | Update a user group. 60 | 61 | https://api.slack.com/methods/usergroups.update 62 | 63 | ## Examples 64 | 65 | Slack.UserGroup.update(client, usergroup: "S0604QSJC", name: "newname") 66 | """ 67 | @spec update(Slack.Client.t, Keyword.t) :: Slack.slack_response 68 | defpost :update 69 | end 70 | -------------------------------------------------------------------------------- /lib/slack/im.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.IM do 2 | @moduledoc """ 3 | Functions for direct messages 4 | """ 5 | 6 | @base "im" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Close an IM channel 12 | 13 | https://api.slack.com/methods/im.close 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.IM.close(channel: "D1234567890") 19 | """ 20 | @spec close(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :close 22 | 23 | @doc """ 24 | Get the history of an IM channel. 25 | 26 | https://api.slack.com/methods/im.history 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.IM.history(channel: "D1234567890") 32 | """ 33 | @spec history(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defget :history 35 | 36 | @doc """ 37 | List IM channels for the user. 38 | 39 | https://api.slack.com/methods/im.list 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.IM.list 45 | """ 46 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defget :list 48 | 49 | @doc """ 50 | Move the read cursor in an IM channel. 51 | 52 | https://api.slack.com/methods/im.mark 53 | 54 | ## Examples 55 | 56 | Slack.client(token) 57 | |> Slack.IM.mark(channel: "D1234567890", ts: 1234567890.123456) 58 | """ 59 | @spec mark(Slack.Client.t, Keyword.t) :: Slack.slack_response 60 | defpost :mark 61 | 62 | @doc """ 63 | Open an IM channel with a user. 64 | 65 | https://api.slack.com/methods/im.open 66 | 67 | ## Examples 68 | 69 | Slack.client(token) 70 | |> Slack.IM.open(user: "U1234567890") 71 | """ 72 | @spec open(Slack.Client.t, Keyword.t) :: Slack.slack_response 73 | defpost :open 74 | end 75 | -------------------------------------------------------------------------------- /lib/slack/reaction.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Reaction do 2 | @moduledoc """ 3 | Functions for working with reactions to messages 👍 4 | """ 5 | 6 | @base "reactions" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Add a reaction to an item. 12 | 13 | https://api.slack.com/methods/reactions.add 14 | 15 | ## Examples 16 | 17 | Slack.Reaction.add(client, 18 | name: "thumbsup", 19 | timestamp: 1234567890.123456, 20 | channel: "C1234567890") 21 | """ 22 | @spec add(Slack.Client.t, Keyword.t) :: Slack.slack_response 23 | defpost :add 24 | 25 | @doc """ 26 | Get reactions for an iteam. 27 | 28 | https://api.slack.com/methods/reactions.get 29 | 30 | ## Examples 31 | 32 | Slack.Reaction.get(client, 33 | name: "thumbsup", 34 | timestamp: 1234567890.123456, 35 | channel: "C1234567890") 36 | """ 37 | @spec get(Slack.Client.t, Keyword.t) :: Slack.slack_response 38 | defget :get 39 | 40 | @doc """ 41 | List items reacted to by the user. 42 | 43 | https://api.slack.com/methods/reactions.list 44 | 45 | ## Examples 46 | 47 | Slack.Reaction.list(client) 48 | """ 49 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 50 | defget :list 51 | 52 | @doc """ 53 | Remove a reaction from an item. 54 | 55 | https://api.slack.com/methods/reactions.remove 56 | 57 | ## Examples 58 | 59 | Slack.Reaction.remove(client, 60 | name: "thumbsup", 61 | timestamp: 1234567890.123456, 62 | channel: "C1234567890") 63 | """ 64 | @spec remove(Slack.Client.t, Keyword.t) :: Slack.slack_response 65 | defpost :remove 66 | end 67 | -------------------------------------------------------------------------------- /lib/slack/mpim.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.MPIM do 2 | @moduledoc """ 3 | Functions for multiparty IMs 4 | """ 5 | 6 | @base "mpim" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Close a multiparty IM channel 12 | 13 | https://api.slack.com/methods/im.close 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.IM.close(channel: "G1234567890") 19 | """ 20 | @spec close(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :close 22 | 23 | @doc """ 24 | Get the history of a multiparty IM channel. 25 | 26 | https://api.slack.com/methods/im.history 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.IM.history(channel: "G1234567890") 32 | """ 33 | @spec history(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defget :history 35 | 36 | @doc """ 37 | List multiparty IM channels for the user. 38 | 39 | https://api.slack.com/methods/im.list 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.IM.list 45 | """ 46 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defget :list 48 | 49 | @doc """ 50 | Move the read cursor in a multiparty IM channel. 51 | 52 | https://api.slack.com/methods/im.mark 53 | 54 | ## Examples 55 | 56 | Slack.client(token) 57 | |> Slack.IM.mark(channel: "G1234567890", ts: 1234567890.123456) 58 | """ 59 | @spec mark(Slack.Client.t, Keyword.t) :: Slack.slack_response 60 | defpost :mark 61 | 62 | @doc """ 63 | Open a multiparty IM channel with a user. 64 | 65 | https://api.slack.com/methods/im.open 66 | 67 | ## Examples 68 | 69 | Slack.client(token) 70 | |> Slack.IM.open(user: "U1234567890,U2345678901") 71 | """ 72 | @spec open(Slack.Client.t, Keyword.t) :: Slack.slack_response 73 | defpost :open 74 | end 75 | -------------------------------------------------------------------------------- /lib/slack/dnd.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.DND do 2 | @moduledoc """ 3 | Functions for working with the user's Do Not Disturb session 4 | """ 5 | 6 | @base "dnd" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | End the user's Do Not Disturb session. 12 | 13 | https://api.slack.com/methods/dnd.endDnd 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.DND.endDnd 19 | """ 20 | @spec endDnd(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :endDnd 22 | 23 | @doc """ 24 | End the user's snooze mode. 25 | 26 | https://api.slack.com/methods/dnd.endSnooze 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.DND.endSnooze 32 | """ 33 | @spec endSnooze(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defpost :endSnooze 35 | 36 | @doc """ 37 | Get information on the user's Do Not Disturb settings. 38 | 39 | https://api.slack.com/methods/dnd.info 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.DND.info(user: "U1234") 45 | """ 46 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defget :info 48 | 49 | @doc """ 50 | Adjust the snooze duration for the user's Do Not Disturb settings. 51 | 52 | https://api.slack.com/methods/dnd.setSnooze 53 | 54 | ## Examples 55 | 56 | Slack.client(token) 57 | |> Slack.DND.setSnooze(num_minutes: 30) 58 | """ 59 | @spec setSnooze(Slack.Client.t, Keyword.t) :: Slack.slack_response 60 | defpost :setSnooze 61 | 62 | @doc """ 63 | Get information about Do Not Disturb settings for a team. 64 | 65 | https://api.slack.com/methods/dnd.teamInfo 66 | 67 | ## Examples 68 | 69 | Slack.client(token) 70 | |> Slack.DND.teamInfo 71 | """ 72 | @spec teamInfo(Slack.Client.t, Keyword.t) :: Slack.slack_response 73 | defget :teamInfo 74 | end 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This document outlines the basic guidelines for contributing to `slack_ex`, and 4 | also serves as a reminder for its main contributor, should they forget what to 5 | do when they need to add new API methods 😰 6 | 7 | ## New API Methods 8 | 9 | Let's say that Slack decides to add new functionality where users can (legally) 10 | add music tracks that play on a loop while users are in a Slack channel. They 11 | forget to add methods for disabling these tracks, so the only methods provided 12 | are `tracks.addToChannel` and `tracks.upload`. 13 | 14 | In order to support these methods, we'll create a `Slack.Track` module that 15 | exposes `addToChannel` and `upload` functions: 16 | 17 | ```elixir 18 | defmodule Slack.Track do 19 | @moduledoc """ 20 | Functions for adding and uploading music tracks 21 | """ 22 | 23 | @base "tracks" 24 | 25 | use Slack.Request 26 | 27 | @doc """ 28 | Add an existing track to a channel. 29 | 30 | https://api.slack.com/methods/tracks.addToChannel 31 | 32 | ## Examples 33 | 34 | Slack.client(token) 35 | |> Slack.Track.addToChannel(channel: "C1234567890", track: "T1234567890") 36 | """ 37 | @spec addToChannel(Slack.Client.t, Keyword.t) :: Slack.response 38 | defpost :addToChannel 39 | 40 | @doc """ 41 | Upload a new track. 42 | 43 | https://api.slack.com/methods/tracks.upload 44 | 45 | ## Examples 46 | 47 | Slack.client(token) 48 | |> Slack.Track.upload(notes: "BAG,BAG,GGGGAAAA,BAG") # "Hot Cross Buns" 49 | """ 50 | @spec upload(Slack.Client.t, Keyword.t) :: Slack.response 51 | defpost :upload 52 | end 53 | ``` 54 | 55 | And that's it! The macro `defpost` (you can use `defget` when you're not 56 | changing anything) does all the work for us, creating a function with the given 57 | name that does all of the fancy pattern matching we need in order to determine 58 | a successful API method call. 59 | -------------------------------------------------------------------------------- /lib/slack/user.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.User do 2 | @moduledoc """ 3 | Functions for working with Slack users 4 | """ 5 | 6 | @base "users" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Get information about a user's presence. 12 | 13 | https://api.slack.com/methods/users.getPresence 14 | 15 | ## Examples 16 | 17 | Slack.User.getPresence(client, user: "U1234567890") 18 | """ 19 | @spec getPresence(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defget :getPresence 21 | 22 | @doc """ 23 | Get the token holder's identity. 24 | 25 | https://api.slack.com/methods/users.identity 26 | 27 | ## Examples 28 | 29 | Slack.User.identity(client) 30 | """ 31 | @spec identity(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defget :identity 33 | 34 | @doc """ 35 | Get information about a user. 36 | 37 | https://api.slack.com/methods/users.info 38 | 39 | ## Examples 40 | 41 | Slack.User.info(client, user: "U1234567890") 42 | """ 43 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 44 | defget :info 45 | 46 | @doc """ 47 | List users on a team. 48 | 49 | https://api.slack.com/methods/users.list 50 | 51 | ## Examples 52 | 53 | Slack.User.list(client) 54 | """ 55 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 56 | defget :list 57 | 58 | @doc """ 59 | Let the messaging server know the user is active. 60 | 61 | https://api.slack.com/methods/users.setActive 62 | 63 | ## Examples 64 | 65 | Slack.User.setActive(client) 66 | """ 67 | @spec setActive(Slack.Client.t, Keyword.t) :: Slack.slack_response 68 | defpost :setActive 69 | 70 | @doc """ 71 | Set the calling user's presence. 72 | 73 | https://api.slack.com/methods/users.setPresence 74 | 75 | ## Examples 76 | 77 | Slack.User.setPresence(client, presence: "away") 78 | """ 79 | @spec setPresence(Slack.Client.t, Keyword.t) :: Slack.slack_response 80 | defpost :setPresence 81 | end 82 | -------------------------------------------------------------------------------- /lib/slack/request.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Request do 2 | defmacro __using__(_opts) do 3 | quote do 4 | import Slack.Request 5 | end 6 | end 7 | 8 | @doc """ 9 | Define a method `method` that makes a GET request to the module's base 10 | endpoint plus the method name: e.g. `baseEndpoint.methodName`. 11 | """ 12 | defmacro defget(method) do 13 | quote do 14 | defrequest unquote(method)(client, query \\ []) do 15 | params = query |> Keyword.put(:token, client.token) 16 | Slack.get "#{@base}.#{unquote(method)}", [], params: params 17 | end 18 | end 19 | end 20 | 21 | @doc """ 22 | Define a method `method` that makes a POST request to the module's base 23 | endpoint plus the method name: e.g. `baseEndpoint.methodName`. 24 | """ 25 | defmacro defpost(method) do 26 | quote do 27 | defrequest unquote(method)(client, body \\ []) do 28 | Slack.post "#{@base}.#{unquote(method)}", 29 | {:form, body}, 30 | [], 31 | params: [token: client.token] 32 | end 33 | end 34 | end 35 | 36 | @doc """ 37 | Define a method `method` that makes a request (the block must return a call 38 | to an HTTPoison request method). 39 | 40 | The body of a successful response will be pattern matched against Slack's 41 | standard `%{"ok" => true}` message format, and will return `{:ok, body}` when 42 | the body matches `%{"ok" => true}`, or `{:error, response}` otherwise. 43 | 44 | In the case of an actual failed request, `{:error, HTTPoison.Error.t}` will be 45 | returned. 46 | """ 47 | defmacro defrequest(signature, do: body) do 48 | quote do 49 | def unquote(signature) do 50 | case unquote(body) do 51 | {:ok, response = %HTTPoison.Response{body: %{"ok" => true}}} -> 52 | {:ok, response.body} 53 | {:ok, response} -> 54 | {:error, response} 55 | {:error, error} -> 56 | {:error, error} 57 | end 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/slack/file.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.File do 2 | @moduledoc """ 3 | Functions for working with files in Slack 4 | """ 5 | 6 | @base "files" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Delete a file from the team. 12 | 13 | https://api.slack.com/methods/files.delete 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.File.delete(file: "F1234467890") 19 | """ 20 | @spec delete(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :delete 22 | 23 | @doc """ 24 | Get information about a file. 25 | 26 | https://api.slack.com/methods/files.info 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.File.info(file: "F1234467890") 32 | """ 33 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defget :info 35 | 36 | @doc """ 37 | List files within the team. 38 | 39 | https://api.slack.com/methods/files.list 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.File.list 45 | """ 46 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defget :list 48 | 49 | @doc """ 50 | Disable public sharing for a file. 51 | 52 | https://api.slack.com/methods/files.revokePublicURL 53 | 54 | ## Examples 55 | 56 | Slack.client(token) 57 | |> Slack.File.revokePublicURL(file: "F1234467890") 58 | """ 59 | @spec revokePublicURL(Slack.Client.t, Keyword.t) :: Slack.slack_response 60 | defpost :revokePublicURL 61 | 62 | @doc """ 63 | Enable public sharing for a file. 64 | 65 | https://api.slack.com/methods/files.sharedPublicURL 66 | 67 | ## Examples 68 | 69 | Slack.client(token) 70 | |> Slack.File.sharedPublicURL(file: "F1234467890") 71 | """ 72 | @spec sharedPublicURL(Slack.Client.t, Keyword.t) :: Slack.slack_response 73 | defpost :sharedPublicURL 74 | 75 | @doc """ 76 | Upload a file. 77 | 78 | https://api.slack.com/methods/files.upload 79 | 80 | ## Examples 81 | 82 | Slack.client(token) 83 | |> Slack.File.upload(content: "File contents") 84 | """ 85 | @spec upload(Slack.Client.t, Keyword.t) :: Slack.slack_response 86 | defpost :upload 87 | end 88 | -------------------------------------------------------------------------------- /lib/slack.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack do 2 | @moduledoc """ 3 | A client for the Slack API. 4 | 5 | This library exports a module for each namespace on the Slack API. For each 6 | method in that namespace, a function is exported from its parent module. 7 | Nested namespaces are in nested modules. 8 | 9 | When looking at the Slack API documentation, if you see a method called 10 | `usergroups.users.list`, you know that you can call this API method with the 11 | function call `Slack.UserGroup.User.list`. Note that all module names are 12 | singular, regardless of whether they are singular or plural in the Slack API. 13 | 14 | ## Authentication 15 | 16 | For Slack API endpoints that require an authentication token (which is all of 17 | them save some special OAuth endpoints), a `Slack.Client.t` must be passed 18 | in as the first argument to a function call: 19 | 20 | access_token 21 | |> Slack.client # Creates a new `Slack.Client.t` 22 | |> Slack.Channel.list 23 | 24 | While the typespec currently expects a `Slack.Client.t`, anything can 25 | technically passed in on which the function can call `client.token`. 26 | 27 | ## Request Methods 28 | 29 | The Slack API allows clients to either issue `GET` or `POST` requests for any 30 | API method. In this client, `POST` is used whenever the request can 31 | potentially create or change data. Otherwise, a `GET` is used. 32 | 33 | ## Return Values 34 | 35 | For any successful method, the Slack API returns a key `"okay"` in the 36 | response body with `true` as the value. When handling a response, this library 37 | checks for this value and if it is present, returns `{:ok, response_body}`. 38 | 39 | An `HTTPoison.Response.t` is only returned when a method call fails, in a 40 | tuple: `{:error, response}`. 41 | 42 | ## Arbitrary Request 43 | 44 | To make some arbitrary request that is not in this library, you can use 45 | special HTTP methods on the `Slack` module: 46 | 47 | {:ok, response} = 48 | Slack.get "namespace.method", [], params: [token: access_token] 49 | """ 50 | use HTTPoison.Base 51 | 52 | @type slack_response :: 53 | {:ok, map} | 54 | {:error, HTTPoison.Response.t} | 55 | {:error, HTTPoison.Error.t} 56 | 57 | @endpoint "https://slack.com/api" 58 | 59 | def client(token), do: %Slack.Client{token: token} 60 | 61 | def process_url("/" <> url), do: process_url(url) 62 | def process_url(url), do: "#{@endpoint}/#{url}" 63 | def process_response_body(body), do: Poison.decode!(body) 64 | end 65 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, 3 | "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm"}, 4 | "ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, 5 | "hackney": {:hex, :hackney, "1.14.3", "b5f6f5dcc4f1fba340762738759209e21914516df6be440d85772542d4a5e412", [:rebar3], [{:certifi, "2.4.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, 6 | "httpoison": {:hex, :httpoison, "1.4.0", "e0b3c2ad6fa573134e42194d13e925acfa8f89d138bc621ffb7b1989e6d22e73", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, 7 | "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, 8 | "makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, 9 | "makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, 10 | "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, 11 | "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, 12 | "nimble_parsec": {:hex, :nimble_parsec, "0.5.2", "1d71150d5293d703a9c38d4329da57d3935faed2031d64bc19e77b654ef2d177", [:mix], [], "hexpm"}, 13 | "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, 14 | "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}, 15 | "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, 16 | "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, 17 | } 18 | -------------------------------------------------------------------------------- /lib/slack/channel.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Channel do 2 | @moduledoc """ 3 | A publicly listed communication channel in a team 4 | """ 5 | 6 | @base "channels" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Archive a channel. 12 | 13 | https://api.slack.com/methods/channels.archive 14 | 15 | ## Examples 16 | 17 | Slack.client(token) 18 | |> Slack.Channel.archive(channel: "C1234567890") 19 | """ 20 | @spec archive(Slack.Client.t, Keyword.t) :: Slack.slack_response 21 | defpost :archive 22 | 23 | @doc """ 24 | Create a channel. 25 | 26 | https://api.slack.com/methods/channels.create 27 | 28 | ## Examples 29 | 30 | Slack.client(token) 31 | |> Slack.Channel.create(name: "mychannel") 32 | """ 33 | @spec create(Slack.Client.t, Keyword.t) :: Slack.slack_response 34 | defpost :create 35 | 36 | @doc """ 37 | Retrieve channel history. 38 | 39 | https://api.slack.com/methods/channels.history 40 | 41 | ## Examples 42 | 43 | Slack.client(token) 44 | |> Slack.Channel.history(channel: "C1234567890") 45 | """ 46 | @spec history(Slack.Client.t, Keyword.t) :: Slack.slack_response 47 | defget :history 48 | 49 | @doc """ 50 | Get channel info. 51 | 52 | https://api.slack.com/methods/channels.info 53 | 54 | ## Examples 55 | 56 | Slack.client(token) 57 | |> Slack.Channel.info(channel: "C1234567890") 58 | """ 59 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 60 | defget :info 61 | 62 | @doc """ 63 | Invite a user to a channel. 64 | 65 | https://api.slack.com/methods/channels.invite 66 | 67 | ## Examples 68 | 69 | Slack.client(token) 70 | |> Slack.Channel.invite(channel: "C1234567890", user: "U1234567890") 71 | """ 72 | @spec invite(Slack.Client.t, Keyword.t) :: Slack.slack_response 73 | defpost :invite 74 | 75 | @doc """ 76 | Join a channel. 77 | 78 | https://api.slack.com/methods/channels.join 79 | 80 | ## Examples 81 | 82 | Slack.client(token) 83 | |> Slack.Channel.join(channel: "C1234567890") 84 | """ 85 | @spec join(Slack.Client.t, Keyword.t) :: Slack.slack_response 86 | defpost :join 87 | 88 | @doc """ 89 | Kick a user from a channel. 90 | 91 | https://api.slack.com/methods/channels.kick 92 | 93 | ## Examples 94 | 95 | Slack.client(token) 96 | |> Slack.Channel.kick(channel: "C1234567890", user: "U1234567890") 97 | """ 98 | @spec kick(Slack.Client.t, Keyword.t) :: Slack.slack_response 99 | defpost :kick 100 | 101 | @doc """ 102 | Leave a channel. 103 | 104 | https://api.slack.com/methods/channels.leave 105 | 106 | ## Examples 107 | 108 | Slack.client(token) 109 | |> Slack.Channel.leave(channel: "C1234567890") 110 | """ 111 | @spec leave(Slack.Client.t, Keyword.t) :: Slack.slack_response 112 | defpost :leave 113 | 114 | @doc """ 115 | List all of the channels in a team. 116 | 117 | https://api.slack.com/methods/channels.list 118 | 119 | ## Examples 120 | 121 | Slack.client(token) 122 | |> Slack.Channel.list 123 | """ 124 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 125 | defget :list 126 | 127 | @doc """ 128 | Move the read cursor in a channel. 129 | 130 | https://api.slack.com/methods/channels.mark 131 | 132 | ## Examples 133 | 134 | Slack.client(token) 135 | |> Slack.Channel.mark(channel: "C1234567890", ts: "1234567890.123456") 136 | """ 137 | @spec mark(Slack.Client.t, Keyword.t) :: Slack.slack_response 138 | defpost :mark 139 | 140 | @doc """ 141 | Rename a channel. 142 | 143 | https://api.slack.com/methods/channels.rename 144 | 145 | ## Examples 146 | 147 | Slack.client(token) 148 | |> Slack.Channel.rename(channel: "C1234567890", name: "newname") 149 | """ 150 | @spec rename(Slack.Client.t, Keyword.t) :: Slack.slack_response 151 | defpost :rename 152 | 153 | @doc """ 154 | Set the purpose of a channel. 155 | 156 | https://api.slack.com/methods/channels.setPurpose 157 | 158 | ## Examples 159 | 160 | Slack.client(token) 161 | |> Slack.Channel.setPurpose(channel: "C1234567890", purpose: "Purpose") 162 | """ 163 | @spec setPurpose(Slack.Client.t, Keyword.t) :: Slack.slack_response 164 | defpost :setPurpose 165 | 166 | @doc """ 167 | Set the topic of a channel. 168 | 169 | https://api.slack.com/methods/channels.setTopic 170 | 171 | ## Examples 172 | 173 | Slack.client(token) 174 | |> Slack.Channel.setTopic(channel: "C1234567890", topic: "Topic") 175 | """ 176 | @spec setTopic(Slack.Client.t, Keyword.t) :: Slack.slack_response 177 | defpost :setTopic 178 | 179 | @doc """ 180 | Unarchive a channel. 181 | 182 | https://api.slack.com/methods/channels.unarchive 183 | 184 | ## Examples 185 | 186 | Slack.client(token) 187 | |> Slack.Channel.unarchive(channel: "C1234567890") 188 | """ 189 | @spec unarchive(Slack.Client.t, Keyword.t) :: Slack.slack_response 190 | defpost :unarchive 191 | end 192 | -------------------------------------------------------------------------------- /lib/slack/group.ex: -------------------------------------------------------------------------------- 1 | defmodule Slack.Group do 2 | @moduledoc """ 3 | Functions for working with private channels (groups) 4 | """ 5 | 6 | @base "groups" 7 | 8 | use Slack.Request 9 | 10 | @doc """ 11 | Archive a private channel. 12 | 13 | https://api.slack.com/methods/groups.archive 14 | 15 | ## Examples 16 | 17 | Slack.Group.archive(client, channel: "G1234567890") 18 | """ 19 | @spec archive(Slack.Client.t, Keyword.t) :: Slack.slack_response 20 | defpost :archive 21 | 22 | @doc """ 23 | Close a private channel. 24 | 25 | https://api.slack.com/methods/groups.close 26 | 27 | ## Examples 28 | 29 | Slack.Group.close(client, channel: "G1234567890") 30 | """ 31 | @spec close(Slack.Client.t, Keyword.t) :: Slack.slack_response 32 | defpost :close 33 | 34 | @doc """ 35 | Create a private channel. 36 | 37 | https://api.slack.com/methods/groups.create 38 | 39 | ## Examples 40 | 41 | Slack.Group.create(client, name: "newchannel") 42 | """ 43 | @spec create(Slack.Client.t, Keyword.t) :: Slack.slack_response 44 | defpost :create 45 | 46 | @doc """ 47 | Replace a private channel. 48 | 49 | https://api.slack.com/methods/groups.createChild 50 | 51 | ## Examples 52 | 53 | Slack.Group.createChild(client, channel: "G1234567890") 54 | """ 55 | @spec createChild(Slack.Client.t, Keyword.t) :: Slack.slack_response 56 | defpost :createChild 57 | 58 | @doc """ 59 | Get the history of a private channel. 60 | 61 | https://api.slack.com/methods/groups.history 62 | 63 | ## Examples 64 | 65 | Slack.Group.history(client, channel: "G1234567890") 66 | """ 67 | @spec history(Slack.Client.t, Keyword.t) :: Slack.slack_response 68 | defget :history 69 | 70 | @doc """ 71 | Get the info of a private channel. 72 | 73 | https://api.slack.com/methods/groups.info 74 | 75 | ## Examples 76 | 77 | Slack.Group.info(client, channel: "G1234567890") 78 | """ 79 | @spec info(Slack.Client.t, Keyword.t) :: Slack.slack_response 80 | defget :info 81 | 82 | @doc """ 83 | Invite a user to a private channel. 84 | 85 | https://api.slack.com/methods/groups.invite 86 | 87 | ## Examples 88 | 89 | Slack.Group.invite(client, channel: "G1234567890", user: "U1234567890") 90 | """ 91 | @spec invite(Slack.Client.t, Keyword.t) :: Slack.slack_response 92 | defpost :invite 93 | 94 | @doc """ 95 | Kick a user from a private channel. 96 | 97 | https://api.slack.com/methods/groups.kick 98 | 99 | ## Examples 100 | 101 | Slack.Group.kick(client, channel: "G1234567890", user: "U1234567890") 102 | """ 103 | @spec kick(Slack.Client.t, Keyword.t) :: Slack.slack_response 104 | defpost :kick 105 | 106 | @doc """ 107 | Leave a private channel. 108 | 109 | https://api.slack.com/methods/groups.leave 110 | 111 | ## Examples 112 | 113 | Slack.Group.leave(client, channel: "G1234567890") 114 | """ 115 | @spec leave(Slack.Client.t, Keyword.t) :: Slack.slack_response 116 | defpost :leave 117 | 118 | @doc """ 119 | List private channels. 120 | 121 | https://api.slack.com/methods/groups.list 122 | 123 | ## Examples 124 | 125 | Slack.Group.list(client) 126 | """ 127 | @spec list(Slack.Client.t, Keyword.t) :: Slack.slack_response 128 | defget :list 129 | 130 | @doc """ 131 | Move the read cursor in a private channel. 132 | 133 | https://api.slack.com/methods/groups.mark 134 | 135 | ## Examples 136 | 137 | Slack.Group.mark(client, channel: "G1234567890", ts: 1234567890.123456) 138 | """ 139 | @spec mark(Slack.Client.t, Keyword.t) :: Slack.slack_response 140 | defpost :mark 141 | 142 | @doc """ 143 | Open a private channel. 144 | 145 | https://api.slack.com/methods/groups.open 146 | 147 | ## Examples 148 | 149 | Slack.Group.open(client, channel: "G1234567890") 150 | """ 151 | @spec open(Slack.Client.t, Keyword.t) :: Slack.slack_response 152 | defpost :open 153 | 154 | @doc """ 155 | Rename a private channel. 156 | 157 | https://api.slack.com/methods/groups.rename 158 | 159 | ## Examples 160 | 161 | Slack.Group.rename(client, channel: "G1234567890", name: "newname") 162 | """ 163 | @spec rename(Slack.Client.t, Keyword.t) :: Slack.slack_response 164 | defpost :rename 165 | 166 | @doc """ 167 | Set the purpose of a private channel. 168 | 169 | https://api.slack.com/methods/groups.setPurpose 170 | 171 | ## Examples 172 | 173 | Slack.Group.setPurpose(client, channel: "G1234567890", purpose: "purpose") 174 | """ 175 | @spec setPurpose(Slack.Client.t, Keyword.t) :: Slack.slack_response 176 | defpost :setPurpose 177 | 178 | @doc """ 179 | Set the topic of a private channel. 180 | 181 | https://api.slack.com/methods/groups.setTopic 182 | 183 | ## Examples 184 | 185 | Slack.Group.setTopic(client, channel: "G1234567890", topic: "topic") 186 | """ 187 | @spec setTopic(Slack.Client.t, Keyword.t) :: Slack.slack_response 188 | defpost :setTopic 189 | 190 | @doc """ 191 | Unarchive a private channel. 192 | 193 | https://api.slack.com/methods/groups.unarchive 194 | 195 | ## Examples 196 | 197 | Slack.Group.unarchive(client, channel: "G1234567890") 198 | """ 199 | @spec unarchive(Slack.Client.t, Keyword.t) :: Slack.slack_response 200 | defpost :unarchive 201 | end 202 | --------------------------------------------------------------------------------