{"id":13443093,"url":"https://github.com/BlakeWilliams/Elixir-Slack","last_synced_at":"2025-03-20T16:30:23.961Z","repository":{"id":25129578,"uuid":"28551492","full_name":"BlakeWilliams/Elixir-Slack","owner":"BlakeWilliams","description":"Slack real time messaging and web API client in Elixir","archived":false,"fork":false,"pushed_at":"2024-06-26T22:12:10.000Z","size":835,"stargazers_count":676,"open_issues_count":18,"forks_count":182,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-15T21:07:34.273Z","etag":null,"topics":["bot","elixir","elixir-slack","rtm","slack"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlakeWilliams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-28T02:26:05.000Z","updated_at":"2025-02-16T06:17:01.000Z","dependencies_parsed_at":"2024-11-14T11:10:52.321Z","dependency_job_id":null,"html_url":"https://github.com/BlakeWilliams/Elixir-Slack","commit_stats":{"total_commits":230,"total_committers":76,"mean_commits":3.026315789473684,"dds":0.6869565217391305,"last_synced_commit":"d7292bdf5b93e42631e4a86fe8d2831d4182b09a"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2FElixir-Slack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2FElixir-Slack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2FElixir-Slack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlakeWilliams%2FElixir-Slack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlakeWilliams","download_url":"https://codeload.github.com/BlakeWilliams/Elixir-Slack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244649669,"owners_count":20487467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","elixir","elixir-slack","rtm","slack"],"created_at":"2024-07-31T03:01:55.966Z","updated_at":"2025-03-20T16:30:23.539Z","avatar_url":"https://github.com/BlakeWilliams.png","language":"Elixir","funding_links":[],"categories":["Elixir","Third Party APIs","Frameworks and libraries"],"sub_categories":["Slack"],"readme":"# Elixir-Slack\n\n[![Elixir CI](https://github.com/BlakeWilliams/Elixir-Slack/actions/workflows/elixir.yml/badge.svg)](https://github.com/BlakeWilliams/Elixir-Slack/actions/workflows/elixir.yml)\n[![Module Version](https://img.shields.io/hexpm/v/slack.svg)](https://hex.pm/packages/slack)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/slack/)\n[![Total Download](https://img.shields.io/hexpm/dt/slack.svg)](https://hex.pm/packages/slack)\n[![License](https://img.shields.io/hexpm/l/slack.svg)](https://github.com/BlakeWilliams/Elixir-Slack/blob/master/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/BlakeWilliams/Elixir-Slack.svg)](https://github.com/BlakeWilliams/Elixir-Slack/commits/master)\n\nThis is a Slack [Real Time Messaging API] client for Elixir.  You'll need a\nSlack API token which can be retrieved by following the [Token Generation\nInstructions] or by creating a new [bot integration].\n\n[Real time Messaging API]: https://api.slack.com/rtm\n[Token Generation Instructions]: https://hexdocs.pm/slack/token_generation_instructions.html\n[bot integration]: https://my.slack.com/services/new/bot\n\n## Installing\n\nAdd `:slack` to your `mix.exs` `dependencies` function:\n\n[websocket_client]: https://github.com/jeremyong/websocket_client\n\n```elixir\ndef application do\n  [\n    extra_applications: [:logger]\n  ]\nend\n\ndef deps do\n  [\n    {:slack, \"~\u003e 0.23.6\"}\n  ]\nend\n```\n\n## Upgrading from 0.x to 0.20+\n\nThe newest version of the Slack client introduces breaking changes with regards to starting and connecting to the Real Time Messaging API. `rtm.start` is now [deprecated](https://api.slack.com/methods/rtm.start) and has since been replaced with [`rtm.connect`](https://api.slack.com/methods/rtm.connect). **This has removed the list of  `bots`, `channels`, `groups`, `users`, and `ims` that are normally returned from `rtm.start`**. Additionally, these lists are now rate-limited. In order to achieve relative parity to the old way of doing things, you'll need to make one change in your code:\n\n### Make additional calls to the Slack API to fetch bots, channels, groups, users, and IMs\n\nWherever you grab the passed in `slack` state, add in additional calls to populate these lists:\n\n```elixir\nslack\n|\u003e Map.put(:bots, Slack.Web.Bots.info(%{token: token}) |\u003e Map.get(\"bot\"))\n|\u003e Map.put(:channels, Slack.Web.Channels.list(%{token: token}) |\u003e Map.get(\"channels\"))\n|\u003e Map.put(:groups, Slack.Web.Groups.list(%{token: token}) |\u003e Map.get(\"groups\"))\n|\u003e Map.put(:ims, Slack.Web.Im.list(%{token: token}) |\u003e Map.get(\"ims\"))\n|\u003e Map.put(:users, Slack.Web.Users.list(%{token: token}) |\u003e Map.get(\"members\"))\n```\n\n## Real Time Messaging (RTM) Bot Usage\n\nDefine a module that uses the Slack behaviour and defines the appropriate\ncallback methods.\n\n```elixir\ndefmodule SlackRtm do\n  use Slack\n\n  def handle_connect(slack, state) do\n    IO.puts \"Connected as #{slack.me.name}\"\n    {:ok, state}\n  end\n\n  def handle_event(message = %{type: \"message\"}, slack, state) do\n    send_message(\"I got a message!\", message.channel, slack)\n    {:ok, state}\n  end\n  def handle_event(_, _, state), do: {:ok, state}\n\n  def handle_info({:message, text, channel}, slack, state) do\n    IO.puts \"Sending your message, captain!\"\n\n    send_message(text, channel, slack)\n\n    {:ok, state}\n  end\n  def handle_info(_, _, state), do: {:ok, state}\nend\n```\n\nTo run this example, you'll want to call `Slack.Bot.start_link(SlackRtm, [],\n\"TOKEN_HERE\")` and run the project with `mix run --no-halt`.\n\nYou can send messages to channels using `send_message/3` which takes the message\nas the first argument, channel/user as the second, and the passed in `slack`\nstate as the third.\n\nThe passed in `slack` state holds the current user properties as `me`, team\nproperties as `team`, and the current websocket connection as `socket`.\n\n[rtm.connect]: https://api.slack.com/methods/rtm.connect\n\nIf you want to do things like trigger the sending of messages outside of your\nSlack handlers, you can leverage the `handle_info/3` callback to implement an\nexternal API.\n\nThis allows you to both respond to Slack RTM events and programmatically control\nyour bot from external events.\n\n```elixir\n{:ok, rtm} = Slack.Bot.start_link(SlackRtm, [], \"token\")\nsend rtm, {:message, \"External message\", \"#general\"}\n#=\u003e {:message, \"External message\", \"#general\"}\n#==\u003e Sending your message, captain!\n```\n\nSlack has *a lot* of message types so it's a good idea to define a callback like\nabove where unhandled message types don't crash your application. You can find a\nlist of message types and examples on the [RTM API page].\n\nYou can find more detailed documentation on the [Slack hexdocs\npage][documentation].\n\n[RTM API page]: https://api.slack.com/rtm\n\n## Web API Usage\n\nThe complete Slack Web API is implemented by generating modules/functions from\nthe JSON documentation. You can view this project's [documentation] for more\ndetails.\n\nThere are two ways to authenticate your API calls. You can configure `api_token`\non `slack` that will authenticate all calls to the API automatically.\n\n```elixir\nconfig :slack, api_token: \"VALUE\"\n```\n\nAlternatively you can pass in `%{token: \"VALUE\"}` to any API call in\n`optional_params`. This also allows you to override the configured `api_token`\nvalue if desired.\n\nQuick example, getting the names of everyone on your team:\n\n```elixir\nnames = Slack.Web.Users.list(%{token: \"TOKEN_HERE\"})\n|\u003e Map.get(\"members\")\n|\u003e Enum.map(fn(member) -\u003e\n  member[\"real_name\"]\nend)\n```\n\n### Web Client Configuration\n\nA custom client callback module can be configured for cases in which you need extra control\nover how calls to the web API are performed. This can be used to control timeouts, or to add additional\ncustom error handling as needed.\n\n```elixir\nconfig :slack, :web_http_client, YourApp.CustomClient\n```\n\nAll Web API calls from documentation-generated modules/functions will call `post!/2` with the generated url\nand body passed as arguments.\n\nIn the case where you only need to control the options passed to HTTPoison/hackney, the default client accepts\na keyword list as an additional configuration parameter. Note that this is ignored if configuring a custom client.\n\nSee [HTTPoison docs](https://hexdocs.pm/httpoison/HTTPoison.html#request/5) for a list of available options.\n\n```elixir\nconfig :slack, :web_http_client_opts, [timeout: 10_000, recv_timeout: 10_000]\n```\n\n## Testing\n\nFor integration tests, you can change the default Slack URL to your fake Slack\nserver:\n\n```elixir\nconfig :slack, url: \"http://localhost:8000\"\n```\n\n[documentation]: http://hexdocs.pm/slack/\n\n## Copyright and License\n\nCopyright (c) 2014 Blake Williams\n\nSource code is released under [the MIT license](./LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlakeWilliams%2FElixir-Slack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlakeWilliams%2FElixir-Slack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlakeWilliams%2FElixir-Slack/lists"}