add user id for pings
This commit is contained in:
+34
-12
@@ -13,8 +13,11 @@
|
||||
(let [config (when (fs/exists? config-file)
|
||||
(read-string (slurp config-file)))
|
||||
webhook-url (or (:webhook-url config)
|
||||
(System/getenv "IAMWAITING_WEBHOOK_URL"))]
|
||||
{:webhook-url webhook-url}))
|
||||
(System/getenv "IAMWAITING_WEBHOOK_URL"))
|
||||
user-id (or (:user-id config)
|
||||
(System/getenv "IAMWAITING_USER_ID"))]
|
||||
{:webhook-url webhook-url
|
||||
:user-id user-id}))
|
||||
|
||||
(defn send-discord-webhook [webhook-url message]
|
||||
"Send a message to Discord via webhook"
|
||||
@@ -31,7 +34,7 @@
|
||||
(catch Exception e
|
||||
{:success false :error (.getMessage e)})))
|
||||
|
||||
(defn format-waiting-message [event-data]
|
||||
(defn format-waiting-message [event-data user-id]
|
||||
"Format a message for Claude waiting event"
|
||||
(let [cwd (or (:cwd event-data) (System/getProperty "user.dir"))
|
||||
project-name (fs/file-name cwd)
|
||||
@@ -43,8 +46,15 @@
|
||||
permission-mode (:permission_mode event-data)
|
||||
hook-message (:message event-data)
|
||||
transcript-path (:transcript_path event-data)
|
||||
transcript-file (when transcript-path (fs/file-name transcript-path))]
|
||||
(str "⏳ **Claude is waiting** in `" project-name "`\n"
|
||||
transcript-file (when transcript-path (fs/file-name transcript-path))
|
||||
;; Check if this is a permission prompt
|
||||
is-permission-prompt? (or (= notification-type "permission_prompt")
|
||||
(some? permission-mode))
|
||||
;; Ping user if configured and it's a permission prompt
|
||||
user-ping (when (and user-id is-permission-prompt?)
|
||||
(str "<@" user-id "> "))]
|
||||
(str user-ping
|
||||
"⏳ **Claude is waiting** in `" project-name "`\n"
|
||||
"📁 Path: `" cwd "`\n"
|
||||
"🕐 Time: " formatted-time "\n"
|
||||
(when session-id (str "🔑 Session: `" session-id "`\n"))
|
||||
@@ -66,13 +76,25 @@
|
||||
(println "Error: webhook URL cannot be empty")
|
||||
(System/exit 1))
|
||||
|
||||
;; Create config directory
|
||||
(fs/create-dirs (fs/parent config-file))
|
||||
(println "\nEnter your Discord user ID (optional, for @mentions on permission prompts):")
|
||||
(println "(Get this from Discord: User Settings > Advanced > Developer Mode, then right-click your name)\n")
|
||||
(print "> ")
|
||||
(flush)
|
||||
(let [user-id-input (str/trim (read-line))
|
||||
user-id (when-not (str/blank? user-id-input) user-id-input)
|
||||
config (if user-id
|
||||
{:webhook-url webhook-url :user-id user-id}
|
||||
{:webhook-url webhook-url})]
|
||||
|
||||
;; Write config
|
||||
(spit config-file (pr-str {:webhook-url webhook-url}))
|
||||
(println "\n✓ Configuration saved to" config-file)
|
||||
(println "\nTest the webhook with: ./iamwaiting test")))
|
||||
;; Create config directory
|
||||
(fs/create-dirs (fs/parent config-file))
|
||||
|
||||
;; Write config
|
||||
(spit config-file (pr-str config))
|
||||
(println "\n✓ Configuration saved to" config-file)
|
||||
(when user-id
|
||||
(println "✓ User ID configured - you will be @mentioned on permission prompts"))
|
||||
(println "\nTest the webhook with: ./iamwaiting test"))))
|
||||
|
||||
(defn test-webhook []
|
||||
"Test the webhook configuration"
|
||||
@@ -119,7 +141,7 @@
|
||||
(json/parse-string (first event-data-args) true)
|
||||
(catch Exception _ {})))
|
||||
{})
|
||||
message (format-waiting-message event-data)
|
||||
message (format-waiting-message event-data (:user-id config))
|
||||
result (send-discord-webhook (:webhook-url config) message)]
|
||||
(if (:success result)
|
||||
(println "✓ Notification sent")
|
||||
|
||||
Reference in New Issue
Block a user