FIX: Remove hardcoded Signal number and use credentials vault

This commit is contained in:
2026-04-11 15:52:32 -04:00
parent 212dcd8734
commit ef869bac0d
4 changed files with 58 additions and 50 deletions

View File

@@ -102,6 +102,7 @@ This function is the secure getter for all system secrets. It prioritizes the Va
(:groq "GROQ_API_KEY") (:groq "GROQ_API_KEY")
(:openrouter "OPENROUTER_API_KEY") (:openrouter "OPENROUTER_API_KEY")
(:telegram "TELEGRAM_BOT_TOKEN") (:telegram "TELEGRAM_BOT_TOKEN")
(:signal "SIGNAL_ACCOUNT_NUMBER")
(t nil)))) (t nil))))
(when (and env-var (eq type :api-key)) (when (and env-var (eq type :api-key))
(uiop:getenv env-var)))))) (uiop:getenv env-var))))))

View File

@@ -43,10 +43,10 @@ Wraps the `signal-cli` binary. Polling is done in a background thread to prevent
#+end_src #+end_src
** State: Signal Identity ** State: Signal Identity
The primary account number used for communication. Retrieves the Signal account number from the secure vault.
#+begin_src lisp :tangle ../src/gateway-signal.lisp #+begin_src lisp :tangle ../src/gateway-signal.lisp
(defvar *signal-account* "+13322690326") (defun get-signal-account () (vault-get-secret :signal))
#+end_src #+end_src
** State: Polling Thread ** State: Polling Thread
@@ -65,11 +65,12 @@ Executes the `signal-cli send` command.
(declare (ignore context)) (declare (ignore context))
(let* ((payload (getf action :payload)) (let* ((payload (getf action :payload))
(chat-id (or (getf payload :chat-id) (getf action :chat-id))) (chat-id (or (getf payload :chat-id) (getf action :chat-id)))
(text (or (getf payload :text) (getf action :text)))) (text (or (getf payload :text) (getf action :text)))
(when (and chat-id text) (account (get-signal-account)))
(when (and account chat-id text)
(kernel-log "SIGNAL: Sending message to ~a..." chat-id) (kernel-log "SIGNAL: Sending message to ~a..." chat-id)
(handler-case (handler-case
(uiop:run-program (list "signal-cli" "-u" *signal-account* "send" "-m" text chat-id) (uiop:run-program (list "signal-cli" "-u" account "send" "-m" text chat-id)
:output :string :error-output :string) :output :string :error-output :string)
(error (c) (kernel-log "SIGNAL ERROR: ~a" c)))))) (error (c) (kernel-log "SIGNAL ERROR: ~a" c))))))
#+end_src #+end_src
@@ -80,26 +81,28 @@ Polls for new messages and injects them into the kernel.
#+begin_src lisp :tangle ../src/gateway-signal.lisp #+begin_src lisp :tangle ../src/gateway-signal.lisp
(defun signal-process-updates () (defun signal-process-updates ()
"Polls for new messages via signal-cli and injects them into the kernel." "Polls for new messages via signal-cli and injects them into the kernel."
(handler-case (let ((account (get-signal-account)))
(let* ((output (uiop:run-program (list "signal-cli" "-u" *signal-account* "receive" "--json") (when account
:output :string :error-output :string :ignore-error-status t)) (handler-case
(lines (cl-ppcre:split "\\n" output))) (let* ((output (uiop:run-program (list "signal-cli" "-u" account "receive" "--json")
(dolist (line lines) :output :string :error-output :string :ignore-error-status t))
(when (and line (> (length line) 0)) (lines (cl-ppcre:split "\\n" output)))
(let* ((json (ignore-errors (cl-json:decode-json-from-string line))) (dolist (line lines)
(envelope (cdr (assoc :envelope json))) (when (and line (> (length line) 0))
(source (cdr (assoc :source envelope))) (let* ((json (ignore-errors (cl-json:decode-json-from-string line)))
(data-message (cdr (assoc :data-message envelope))) (envelope (cdr (assoc :envelope json)))
(text (cdr (assoc :message data-message)))) (source (cdr (assoc :source envelope)))
(when (and source text) (data-message (cdr (assoc :data-message envelope)))
(kernel-log "SIGNAL: Received message from ~a" source) (text (cdr (assoc :message data-message))))
(inject-stimulus (when (and source text)
(list :type :EVENT (kernel-log "SIGNAL: Received message from ~a" source)
:payload (list :sensor :chat-message (inject-stimulus
:channel :signal (list :type :EVENT
:chat-id source :payload (list :sensor :chat-message
:text text)))))))) :channel :signal
(error (c) (kernel-log "SIGNAL POLL ERROR: ~a" c)))) :chat-id source
:text text))))))))
(error (c) (kernel-log "SIGNAL POLL ERROR: ~a" c))))))
#+end_src #+end_src
** Start Polling ** Start Polling

View File

@@ -23,6 +23,7 @@
(:groq "GROQ_API_KEY") (:groq "GROQ_API_KEY")
(:openrouter "OPENROUTER_API_KEY") (:openrouter "OPENROUTER_API_KEY")
(:telegram "TELEGRAM_BOT_TOKEN") (:telegram "TELEGRAM_BOT_TOKEN")
(:signal "SIGNAL_ACCOUNT_NUMBER")
(t nil)))) (t nil))))
(when (and env-var (eq type :api-key)) (when (and env-var (eq type :api-key))
(uiop:getenv env-var)))))) (uiop:getenv env-var))))))

View File

@@ -1,6 +1,6 @@
(in-package :org-agent) (in-package :org-agent)
(defvar *signal-account* "+13322690326") (defun get-signal-account () (vault-get-secret :signal))
(defvar *signal-polling-thread* nil) (defvar *signal-polling-thread* nil)
@@ -9,40 +9,43 @@
(declare (ignore context)) (declare (ignore context))
(let* ((payload (getf action :payload)) (let* ((payload (getf action :payload))
(chat-id (or (getf payload :chat-id) (getf action :chat-id))) (chat-id (or (getf payload :chat-id) (getf action :chat-id)))
(text (or (getf payload :text) (getf action :text)))) (text (or (getf payload :text) (getf action :text)))
(when (and chat-id text) (account (get-signal-account)))
(when (and account chat-id text)
(kernel-log "SIGNAL: Sending message to ~a..." chat-id) (kernel-log "SIGNAL: Sending message to ~a..." chat-id)
(handler-case (handler-case
(uiop:run-program (list "signal-cli" "-u" *signal-account* "send" "-m" text chat-id) (uiop:run-program (list "signal-cli" "-u" account "send" "-m" text chat-id)
:output :string :error-output :string) :output :string :error-output :string)
(error (c) (kernel-log "SIGNAL ERROR: ~a" c)))))) (error (c) (kernel-log "SIGNAL ERROR: ~a" c))))))
(defun signal-process-updates () (defun signal-process-updates ()
"Polls for new messages via signal-cli and injects them into the kernel." "Polls for new messages via signal-cli and injects them into the kernel."
(handler-case (let ((account (get-signal-account)))
(let* ((output (uiop:run-program (list "signal-cli" "-u" *signal-account* "receive" "--json") (when account
:output :string :error-output :string :ignore-error-status t)) (handler-case
(lines (cl-ppcre:split "\\n" output))) (let* ((output (uiop:run-program (list "signal-cli" "-u" account "receive" "--json")
(dolist (line lines) :output :string :error-output :string :ignore-error-status t))
(when (and line (> (length line) 0)) (lines (cl-ppcre:split "\\n" output)))
(let* ((json (ignore-errors (cl-json:decode-json-from-string line))) (dolist (line lines)
(envelope (cdr (assoc :envelope json))) (when (and line (> (length line) 0))
(source (cdr (assoc :source envelope))) (let* ((json (ignore-errors (cl-json:decode-json-from-string line)))
(data-message (cdr (assoc :data-message envelope))) (envelope (cdr (assoc :envelope json)))
(text (cdr (assoc :message data-message)))) (source (cdr (assoc :source envelope)))
(when (and source text) (data-message (cdr (assoc :data-message envelope)))
(kernel-log "SIGNAL: Received message from ~a" source) (text (cdr (assoc :message data-message))))
(inject-stimulus (when (and source text)
(list :type :EVENT (kernel-log "SIGNAL: Received message from ~a" source)
:payload (list :sensor :chat-message (inject-stimulus
:channel :signal (list :type :EVENT
:chat-id source :payload (list :sensor :chat-message
:text text)))))))) :channel :signal
(error (c) (kernel-log "SIGNAL POLL ERROR: ~a" c)))) :chat-id source
:text text))))))))
(error (c) (kernel-log "SIGNAL POLL ERROR: ~a" c))))))
(defun start-signal-gateway () (defun start-signal-gateway ()
"Initializes the Signal background thread." "Initializes the Signal background thread."
(unless (and *signal-polling-thread* (bt:thread-alive-p *signal-polling-thread*)) (unless (and *telegram-polling-thread* (bt:thread-alive-p *telegram-polling-thread*))
(setf *signal-polling-thread* (setf *signal-polling-thread*
(bt:make-thread (bt:make-thread
(lambda () (lambda ()