clj-slackbot
clj-slackbot copied to clipboard
Ping/Pong for RTM API
No ping/pong makes WS connection stale.
(defn ping-pong [out-pipe next-id delay]
(go-loop []
(async/<! (async/timeout delay))
(printf "Sending a ping request")
(async/>! out-pipe {:id (next-id) :type :ping})
(recur)))
(defn connect-socket [url next-id]
(let [in (async/chan)
out (async/chan)
socket (ws/connect url
:on-receive
(fn [m]
(async/put! in (parse-string m true)))
:on-error
(fn [_]
(async/close! in)))
heart-beat (ping-pong out next-id 7000)]
(go-loop []
(let [m (async/<! out)
s (generate-string m)]
(ws/send-msg socket s)
(recur)))
[in out]))
I'm trying this. I'm using your skeleton to make a music bot for slack. Its really nice.