Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple fixes #14

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ This bot now supports different kinds of comm-links (communication channels to t
Webhook configuration needs four things defined in `config.edn`:

- `:comm :clj-slackbot.comms.slack-web-hook/start`
- `:post-url` - The post URL to post responses to a channel.
- `:command-token` - The token you get when you create a slash command in slack. Usually something like `/clj`.
- `:port` - The port to run the web-server on.

Expand Down
3 changes: 1 addition & 2 deletions config.example.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
:api-token "XXX"
:prefix ","
:port 3000
:command-token "XXX"
:post-url "XXX"}
:command-token "XXX"}
5 changes: 2 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
:uberjar-name "clj-slackbot.jar"
:main clj-slackbot.core
:profiles
{:dev {:repl-options {:init-ns clj-slackbot.core.handler}
:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}
:uberjar {:aot :all}})
28 changes: 15 additions & 13 deletions src/clj_slackbot/comms/slack_web_hook.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

(defn post-to-slack
([post-url s channel]
(let [p (if channel {:channel channel} {})]
(client/post post-url
{:content-type :json
:form-params (assoc p :text s)
:query-params {"parse" "none"}})))
(let [p (if channel {:channel channel} {})]
jvtrigueros marked this conversation as resolved.
Show resolved Hide resolved
(client/post post-url
{:content-type :json
:form-params (assoc p :text s)
:query-params {"parse" "none"}})))
([post-url s]
(post-to-slack post-url s nil)))
(post-to-slack post-url s nil)))

(defn handle-clj [params command-token cin]
jvtrigueros marked this conversation as resolved.
Show resolved Hide resolved
(if-not (= (:token params) command-token)
jvtrigueros marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,15 +27,17 @@
(str "#" (:channel_name params)))]
;; send the form to our evaluator and get out of here
(>!! cin {:input (:text params)
:meta {:channel channel}})
:meta {:channel channel
:response-url (:response_url params)
:user (:user_name params)}})

{:status 200 :body "..." :headers {"Content-Type" "text/plain"}})))


(defn start [{:keys [port post-url command-token] :as config}]
(defn start [{:keys [port command-token]}]
;; check we have everything
(when (some nil? [port post-url command-token])
(throw (Exception. "Cannot initialize. Missing port, post-url or command-token")))
(when (some nil? [port command-token])
(throw (Exception. "Cannot initialize. Missing port or command-token")))

(println ":: starting http server on port:" port)
(let [cin (async/chan 10)
Expand All @@ -50,11 +52,11 @@
(go-loop [res (<!! cout)]
(if-not res
(println "The form output channel has been closed. Leaving listen loop.")
(let [result (:evaluator/result res)
channel (get-in res [:meta :channel])]
(let [channel (get-in res [:meta :channel])
post-url (get-in res [:meta :response-url])]
jvtrigueros marked this conversation as resolved.
Show resolved Hide resolved
(post-to-slack
post-url
(util/format-result-for-slack result)
(util/format-result-for-slack res)
channel)
(recur (<!! cout)))))

Expand Down