Created
May 24, 2019 15:42
-
-
Save brianium/f6e1b47a938d845e659ca02fd77f43ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Multi Method | |
(defmethod slack/slash :info [{:keys [response-type]}] | |
{:response_type response-type | |
:text (str "TeamGantt for Slack v" (version/current))}) | |
(defmethod slack/slash :default [context] | |
(slack/slash (assoc context :command :help))) | |
;;; Syntactic sugar | |
(defmacro defslashcmd | |
"Define a new supported slash command. Supports defining usage inline | |
with the slash command" | |
([name usage bindings & body] | |
(let [id (keyword name) | |
usages (if (vector? usage) (into [id] usage) [id usage])] | |
`(do | |
(apply usage ~usages) | |
(defmethod slash ~id | |
~bindings | |
~@body))))) | |
;;; Usage | |
(defslashcmd today | |
"`/tg today` = See what’s on your plate today and update task progress right from Slack." | |
[{:keys [api user_id response-type]}] | |
(let [{tg :teamgantt} api | |
response (task/get-today tg user_id)] | |
(-> response | |
(today/message) | |
(assoc :response_type response-type)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment