ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - koudelka/slacker: An Elixir Slack bot! (work in progress)
An Elixir Slack bot! (work in progress). Contribute to koudelka/slacker development by creating an account on GitHub.
Visit Site

GitHub - koudelka/slacker: An Elixir Slack bot! (work in progress)

GitHub - koudelka/slacker: An Elixir Slack bot! (work in progress)

Slacker

Slacker's an Elixir bot library for Slack.

It has chat matching functionality built-in, but you can extend it to handle all kinds of events.

Chat

Slacker can match regex or literal strings, then execute a given function (module optional).

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. 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 from Slack and do whatever you like with them.

defmodule CASE do
  use Slacker

  def handle_cast({:handle_incoming, "presence_change", msg}, state) do
    say self, msg["channel"], "You're the man who brought us the probe?"
    {:noreply, state}
  end

end

You can also use Slack's "Web API" 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:

def deps do
  [{:websocket_client, github: "jeremyong/websocket_client"},
  {:slacker,  "~> 0.0.3"}]
end

Create a bot user 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)

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory