Files
passepartout/org/channel-slack.org
Amr Gharbeia da160b71e3
Some checks failed
Deploy (Gitea) / deploy (push) Failing after 2s
passepartout: v0.5.0 File Reorganization
Extract non-core fragments using self-repair criterion:
- core-context -> symbolic-awareness (224 lines, fboundp guards in think())
- heartbeat generation -> symbolic-events (renamed events-start-heartbeat)

Rename 23 files for clarity and new naming scheme:
- 6 core: core-package, core-transport, core-pipeline,
          core-perceive, core-reason, core-act
- 13 system: symbolic-*, neuro-*, embedding-*, channel-shell
- 4 gateway: channel-cli, channel-tui-*, channel-tui-state

Utility relocations:
- markdown-strip -> programming-markdown
- plist-keywords-normalize -> programming-lisp
- cognitive-tool-prompt -> programming-tools
- VAULT-MEMORY -> security-vault
- Merge *backend-registry* into *probabilistic-backends*

Split gateway-messaging into channel-telegram/channel-signal/
channel-discord/channel-slack (4 independent skills)

Delete dead system-model.lisp (16-line wrapper)

Document self-repair criterion in DESIGN_DECISIONS

Version bump: 0.4.3 -> 0.5.0
2026-05-07 18:20:48 -04:00

2.6 KiB

Channel Slack (channel-slack.org)

Channel Slack

Extracted from gateway-messaging in v0.5.0. Isolated platform — Slack-specific poll and send logic.

Implementation

(in-package :passepartout)
(defun slack-get-token ()
  (vault-get-secret :slack))

(defun slack-send (action context)
  "Sends a message via Slack Web API."
  (declare (ignore context))
  (let* ((payload (getf action :payload))
         (meta (getf action :meta))
         (channel (or (getf meta :channel-id) (getf payload :chat-id)))
         (text (or (getf payload :text) (getf action :text)))
         (token (slack-get-token)))
    (when (and token channel text)
      (handler-case
          (dex:post "https://slack.com/api/chat.postMessage"
                    :headers `(("Authorization" . ,(format nil "Bearer ~a" token))
                               ("Content-Type" . "application/json; charset=utf-8"))
                    :content (cl-json:encode-json-to-string
                              `((channel . ,channel) (text . ,text))))
        (error (c) (log-message "SLACK ERROR: ~a" c))))))

(defun slack-poll ()
  "Polls Slack for new messages via conversations.history."
  (let* ((token (slack-get-token)))
    (when token
      (dolist (channel '("general"))  ;; configured channel IDs
        (handler-case
            (let* ((url (format nil "https://slack.com/api/conversations.history?channel=~a&limit=5" channel))
                   (response (dex:get url :headers
                                       `(("Authorization" . ,(format nil "Bearer ~a" token))))))
              (let* ((json (ignore-errors (cl-json:decode-json-from-string response)))
                     (ok (cdr (assoc :ok json)))
                     (messages (cdr (assoc :messages json))))
                (when (and ok messages (listp messages))
                  (dolist (msg messages)
                    (let* ((text (cdr (assoc :text msg)))
                           (user (cdr (assoc :user msg)))
                           (ts (cdr (assoc :ts msg))))
                      (when (and text user (not (string= user "USLACKBOT")))
                        (unless (ignore-errors (hitl-handle-message text :slack))
                          (stimulus-inject
                           (list :type :EVENT
                                 :meta (list :source :slack :chat-id channel)
                                 :payload (list :sensor :user-input :text text))))))))))
          (error (c) (log-message "SLACK POLL ERROR: ~a" c)))))))

#+end_src