Skip to content

Instantly share code, notes, and snippets.

@brianium
Created May 24, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianium/f6e1b47a938d845e659ca02fd77f43ae to your computer and use it in GitHub Desktop.
Save brianium/f6e1b47a938d845e659ca02fd77f43ae to your computer and use it in GitHub Desktop.
;;; 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