Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koudelka/slacker
An Elixir Slack bot! (work in progress)
https://github.com/koudelka/slacker
Last synced: 27 days ago
JSON representation
An Elixir Slack bot! (work in progress)
- Host: GitHub
- URL: https://github.com/koudelka/slacker
- Owner: koudelka
- License: mit
- Created: 2015-05-08T23:49:11.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-27T19:05:58.000Z (over 8 years ago)
- Last Synced: 2024-11-07T18:05:52.740Z (about 1 month ago)
- Language: Elixir
- Size: 16.6 KB
- Stars: 83
- Watchers: 8
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A bot library for the Slack chat service. (Chatting)
- fucking-awesome-elixir - slacker - A bot library for the Slack chat service. (Chatting)
- awesome-elixir - slacker - A bot library for the Slack chat service. (Chatting)
README
Slacker
=======Slacker's an Elixir bot library for [Slack](https://slack.com).
It has chat matching functionality built-in, but you can extend it to handle all kinds of [events](https://api.slack.com/events).
### Chat
Slacker can match regex or literal strings, then execute a given function (module optional).
```elixir
defmodule TARS do
use Slacker
use Slacker.Matcher
match ~r/Sense of humor\. New level setting: ([0-9]+)%/, :set_humor
match "Great idea. A massive, sarcastic robot.", [CueLight, :turn_on]def set_humor(tars, msg, level) do
reply = "Sense of humor set to #{level}"
say tars, msg["channel"], reply
end
end
```Slacker will call your function with the matching [message hash](https://api.slack.com/events/message). You can use `say/3` to respond, be sure to include the channel you want to talk to.
### Extending Slacker
Your robot is really just a `GenServer`, you can catch [RTM events](https://api.slack.com/events) from Slack and do whatever you like with them.```elixir
defmodule CASE do
use Slackerdef handle_cast({:handle_incoming, "presence_change", msg}, state) do
say self, msg["channel"], "You're the man who brought us the probe?"
{:noreply, state}
endend
```You can also use Slack's ["Web API"](https://api.slack.com/methods) via the `Slacker.Web` module. All of the available RPC methods are downcased and underscored.
`users.getPresence` -> `Slacker.Web.users_get_presence("your_api_key", user: "U1234567890")`
### Bootin' it up
Add this to your deps:```elixir
def deps do
[{:websocket_client, github: "jeremyong/websocket_client"},
{:slacker, "~> 0.0.3"}]
end
```Create a [bot user](https://api.slack.com/bot-users) in the Slack GUI, and then pass your api token to your bot's `start_link/1`:
`{:ok, tars} = TARS.start_link("your_api_token")`
It's up to you to supervise your brand new baby bot.
You're going to need to invite your bot to a channel by `@`-mentioning them.
### Contributing
Gimme dem PR's.Some of this stuff is a real pain in the ass to test, just do your best. :rocket:
TODO:
- Keep a map of usernames to ids.
- Keep a map of channel names to ids.
- Private messaging support.
- RTM tests.## License
See the LICENSE file. (MIT)