Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ne-sachirou/slack.clje
A Slack client for Clojerl.
https://github.com/ne-sachirou/slack.clje
clojerl slack
Last synced: 3 days ago
JSON representation
A Slack client for Clojerl.
- Host: GitHub
- URL: https://github.com/ne-sachirou/slack.clje
- Owner: ne-sachirou
- License: gpl-3.0
- Created: 2020-12-30T12:46:52.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-21T02:14:52.000Z (over 3 years ago)
- Last Synced: 2023-03-22T22:37:10.068Z (over 1 year ago)
- Topics: clojerl, slack
- Language: Erlang
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slack.clje
![Test](https://github.com/ne-sachirou/slack.clje/workflows/Test/badge.svg)
A Slack client for [Clojerl][clojerl].
We are using Slack RTM (Real Time Messageing) API.
## LICENSE
GPL-3.0-or-later
## Installation
`rebar.config`.
```erlang
{deps, […,
{slack, {git, "[email protected]:ne-sachirou/slack.clje.git", {branch, "main"}}}]}
```## Usage
Create `gen_event` modules to handle Slack incoming messages.
```clojure
(ns example-bot.handler1)(erlang.core/behaviours gen_event)
(defn init [{:keys [name arg1] :as args}] #erl[:ok args])
(defn handle_call [_ state] #erl[:ok :ok state])
(def handle_event
(fn* ([#erl[:receive-msg #as(msg #erl{})] #as(state #erl{:name name :arg1 arg1})]
; Handle msg here.
#erl[:ok state])
([_ state]
#erl[:ok state])))
```The `msg` is a decoded JSON received from Slack RTM API.
Then start a `slack.sup` to give `api-token`, `handlers` & unique `name`.
```clojure
(ns example-bot.sup
(:require [slack.sup]))(erlang.core/behaviours supervisor)
(def sup-flags #erl{:strategy :one_for_one
:intensity 1
:period 5})(def child-specs #erl((-> {:api-token "Slack API Token"
:handlers '([:example-bot.handler1 {:arg1 "Some value"}]
[:example-bot.handler2 {}])
:name "example-bot"}
slack.sup/child-spec
clj->erl)))(defn start-link []
(supervisor/start_link #erl[:local :example-bot.sup]
:example-bot.sup
#erl()))(defn init [_]
#erl[:ok #erl[sup-flags child-specs]])
```To send a message to Slack, call `slack/send-msg.2`.
```clojure
(let* [:ok (slack/send-msg name
#erl{:id id
:type "message"
:channel channel
:text text})])
```[clojerl]: https://github.com/clojerl/clojerl