我使用clj-slack start方法获取web-socket url,然后将其传递给gniazdo的connect方法以侦听web-socket。
(require '[clj-slack.rtm :as slack])
(require '[gniazdo.core :as ws])
(def connection {:api-url "https://slack.com/api" :token "your token"})
(defn reset-conn [options]
(def socket
(ws/connect
(:url (slack/start options))
:on-receive #(prn 'received %))))
(reset-conn connection)
此代码工作正常,但它仅提供有关谁是活动的或远离松弛的信息:
received"{\"type\":\"presence_change\",\"presence\":\"active\",\"user\":\"U7BCQHWHY\"}"
但我也想听听这些消息。
虽然在slack-api documentation中声明rtm(real time messaging
)用于消息传递会话,但我不知道为什么不打印消息。