willrax / marvin

:space_invader: Slack bots using Elixir.

Home Page:http://hexdocs.pm/marvin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Marvin

Slack bots using Elixir.

Installation

If available in Hex, the package can be installed as:

  1. Add Marvin to your list of dependencies in mix.exs:
def deps do
  [
    {:marvin, "~> 0.3.1"},
    {:websocket_client, git: "https://github.com/jeremyong/websocket_client"}
  ]
end

You'll need to add websocket_client manually.

  1. Ensure marvin is started before your application:
def application do
  [applications: [:marvin]]
end

You'll need to set your bots Slack token in your applications config file.

config :marvin, slack_token: "secret"

Creating Bots

Bots are simple to create and can respond to mentions, direct messages and ambient conversation.

defmodule EchoBot do
  use Marvin.Bot

  # Here you can set a specific type of message and a regex pattern to match against
  # Direct includes mentions and direct discussions with the bot. Patterns are case
  # sensitive by default.

  match {:direct, ~r/hello/}

  def handle_message(message, slack) do
    send_message("Hi!", message.channel, slack)
  end
end

Next you'll need to tell Marvin to start your bots by adding them to your config file.

config :marvin, bots: [EchoBot]

You can also capture reactions being applied to a message.

defmodule EchoBot do
  use Marvin.Bot

  match {:reaction, "coin"}

  def handle_message(message, slack) do
    IO.puts "A coin was given"
  end
end

About

:space_invader: Slack bots using Elixir.

http://hexdocs.pm/marvin/


Languages

Language:Elixir 100.0%