Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcorrado/slackbot-router
A Clojure Slack bot request routing framework
https://github.com/jcorrado/slackbot-router
clojure library slack
Last synced: 26 days ago
JSON representation
A Clojure Slack bot request routing framework
- Host: GitHub
- URL: https://github.com/jcorrado/slackbot-router
- Owner: jcorrado
- License: epl-1.0
- Created: 2018-01-14T03:25:18.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-25T20:00:56.000Z (almost 7 years ago)
- Last Synced: 2024-07-12T02:28:19.264Z (4 months ago)
- Topics: clojure, library, slack
- Language: Clojure
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# slackbot-router
[![Clojars Project](https://img.shields.io/clojars/v/jcorrado/slackbot-router.svg)](https://clojars.org/jcorrado/slackbot-router)slackbot-router is a small routing library for Slack bots, organizing incoming message tests and reply-generators into tables. Incoming messages are handled asynchronously.
## Installation
Add the following dependency to your `project.clj` file:[jcorrado/slackbot-router "0.1.1"]
## Usage
### Bot Setup
A Slack bot is a web application designed to handle events surfaced by a configured Slack workspace. Slack offers two patterns: the [Real Time Messaging API](https://api.slack.com/rtm) and the simpler [Events API](https://api.slack.com/events-api); I have only used the latter.Here is a fragment of a Compojure app that shows the basic idea. Our message routing rules are in `message-table`, detailed below.
You will need to configure Ring, via `project.clj` to use your `init` and `handler` fns.
```clojure
(defproject mybot "0.1.0"
:dependencies [[org.clojure/clojure "1.9.0"]
[jcorrado/slackbot-router "0.1.1"]
;; ...]
:ring {:init mybot.handler/init
:handler mybot.handler/app})
```A simple `mybot.handler` fragment with the basic idea.
```clojure
(def events-c (chan 100))(defn slack-event-handler
[req]
(let [event (:body req)]
(try
(response (slackbot-router.core/route-event event events-c))
(catch java.lang.Exception e
(println "Unknown Slack message type:" (.getMessage e))
;; We always reply 200 to incoming Slack events
(response "OK")))))(defroutes app
(POST "/slack-event" [body] slack-event-handler))(defn init
[]
(go-loop []
(let [msg (