Slug - A Slack bot library inspired by Plug

I’ve been working on a Slack bot framework inspired by Plug.

# lib/bot_family/my_bot.ex
defmodule BotFamily.MyBot do
  use ExBot.Bot

  slug(ExBot.Slug.Common.MessagesOnly)
  slug(ExBot.Slug.Common.CheckMentioned)
  slug(:simple_reply)

  def simple_reply(%ExBot.Event{data: event_data, metadata: %{mentioned: true}} = event) do
    %{user: user_id, channel: channel_id} = event_data
    ExBot.Bot.send_text(__MODULE__, channel_id, "Oh hey, <@#{user_id}>!")
    event
  end

  def simple_reply(event), do: event
end

You can assemble a pipeline of “slugs” that receive Slack events, take actions, and annotate the event as it moves through the pipeline.

It’s nothing fancy yet, but I thought I’d share it all the same :slight_smile:

https://hexdocs.pm/ex_bot/readme.html

6 Likes

Based on the generic name of ExBot, I’m guessing it will be capable of interfacing with other networks as well, such as Discord and IRC in time? :slight_smile:

Now slug :wink: https://github.com/mattbaker/slug

2 Likes