Git Product home page Git Product logo

slacker-1's Introduction

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. ๐Ÿš€

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)

slacker-1's People

Contributors

koudelka avatar linell avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.