Logging emacs-slack conversations to file

At work, we've been coerced for a few years now to use Slack. At first it wasn't too bad; Slack provided an IRC gateway so irssi remained viable. Then in 2018 they shut down the gateways in the name of "security".

Enter emacs-slack!

As part of my personal initiative to move more of my computing life into Emacs, the IRC gateway closure actually provided me the necessary kick in the pants to move chat from irssi to Emacs.

I'm a simple user and emacs-slack has just worked. I have a few elisp customizations pulled from various sites but for the most part have left emacs-slack to the defaults.

The only thing I missed from irssi was logged chats to my local disk.

Logging chats to disk

My feature was simple - per-team, per-channel, dated files. Basically appending each message received to log/{TEAM}/{CHANNEL}/{YYYY-MM-DD}.log.

I took inspiration from this issue to create a custom message handler (stored in slack-message-custom-notifier) that would log the incoming message to disk:

(setq slack-log-directory (concat (expand-file-name slack-file-dir)))

(defun mc_/handle-message (message room team)
  (let* ((team-name (slack-team-name team))
	 (room-name (slack-room-name room team))
	 (text (slack-message-to-string message team)))
    (mc_/chat-log team-name room-name text)))

(defun mc_/chat-log (team-name room-name text)
  "Write to log/{TEAM}/{ROOM}/{DATE}.log"
  (let* ((dir slack-log-directory)
	 (today (format-time-string "%Y-%m-%d"))
	 (filename (format "%s%s/%s/%s.log" dir team-name room-name today)))
    (when (not (file-exists-p filename))
      (make-directory (file-name-directory filename) t)
      (write-region "" nil filename)
      )
    (write-region (concat (format-time-string "%H:%M:%S") ": " text "\n") nil filename 'append)))

(setq slack-message-custom-notifier #'mc_/handle-message)

I've posted to /r/emacs with the above to solicit feedback. Hopefully this isn't too far off the mark though! Updates if/when the code is revised.