add user id for pings
This commit is contained in:
parent
06441874be
commit
34ab774759
18
CLAUDE.md
18
CLAUDE.md
@ -29,10 +29,13 @@ The entire implementation is a single Babashka script (`iamwaiting`) with these
|
|||||||
Configuration is stored in `~/.iamwaiting/config.edn` with the following structure:
|
Configuration is stored in `~/.iamwaiting/config.edn` with the following structure:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
{:webhook-url "https://discord.com/api/webhooks/..."}
|
{:webhook-url "https://discord.com/api/webhooks/..."
|
||||||
|
:user-id "123456789012345678"} ; Optional: Discord user ID for @mentions
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, the webhook URL can be set via the `IAMWAITING_WEBHOOK_URL` environment variable.
|
Alternatively, configuration can be set via environment variables:
|
||||||
|
- `IAMWAITING_WEBHOOK_URL` - Discord webhook URL (required)
|
||||||
|
- `IAMWAITING_USER_ID` - Discord user ID for @mentions (optional)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -114,14 +117,23 @@ Notifications include:
|
|||||||
- ⏳ Waiting indicator
|
- ⏳ Waiting indicator
|
||||||
- 📁 Current working directory / project name
|
- 📁 Current working directory / project name
|
||||||
- 🕐 Timestamp (HH:mm:ss format)
|
- 🕐 Timestamp (HH:mm:ss format)
|
||||||
|
- @mention (if user ID is configured and it's a permission prompt)
|
||||||
|
|
||||||
Example message:
|
Example message (normal prompt):
|
||||||
```
|
```
|
||||||
⏳ **Claude is waiting** in `ajet-industries`
|
⏳ **Claude is waiting** in `ajet-industries`
|
||||||
📁 Path: `/home/user/repos/ajet-industries`
|
📁 Path: `/home/user/repos/ajet-industries`
|
||||||
🕐 Time: 14:23:45
|
🕐 Time: 14:23:45
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example message (permission prompt with user ID configured):
|
||||||
|
```
|
||||||
|
<@123456789012345678> ⏳ **Claude is waiting** in `ajet-industries`
|
||||||
|
📁 Path: `/home/user/repos/ajet-industries`
|
||||||
|
🕐 Time: 14:23:45
|
||||||
|
📢 Type: `permission_prompt`
|
||||||
|
```
|
||||||
|
|
||||||
### Error Handling
|
### Error Handling
|
||||||
|
|
||||||
- Missing configuration prompts user to run `./iamwaiting setup`
|
- Missing configuration prompts user to run `./iamwaiting setup`
|
||||||
|
|||||||
46
iamwaiting
46
iamwaiting
@ -13,8 +13,11 @@
|
|||||||
(let [config (when (fs/exists? config-file)
|
(let [config (when (fs/exists? config-file)
|
||||||
(read-string (slurp config-file)))
|
(read-string (slurp config-file)))
|
||||||
webhook-url (or (:webhook-url config)
|
webhook-url (or (:webhook-url config)
|
||||||
(System/getenv "IAMWAITING_WEBHOOK_URL"))]
|
(System/getenv "IAMWAITING_WEBHOOK_URL"))
|
||||||
{:webhook-url 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]
|
(defn send-discord-webhook [webhook-url message]
|
||||||
"Send a message to Discord via webhook"
|
"Send a message to Discord via webhook"
|
||||||
@ -31,7 +34,7 @@
|
|||||||
(catch Exception e
|
(catch Exception e
|
||||||
{:success false :error (.getMessage 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"
|
"Format a message for Claude waiting event"
|
||||||
(let [cwd (or (:cwd event-data) (System/getProperty "user.dir"))
|
(let [cwd (or (:cwd event-data) (System/getProperty "user.dir"))
|
||||||
project-name (fs/file-name cwd)
|
project-name (fs/file-name cwd)
|
||||||
@ -43,8 +46,15 @@
|
|||||||
permission-mode (:permission_mode event-data)
|
permission-mode (:permission_mode event-data)
|
||||||
hook-message (:message event-data)
|
hook-message (:message event-data)
|
||||||
transcript-path (:transcript_path event-data)
|
transcript-path (:transcript_path event-data)
|
||||||
transcript-file (when transcript-path (fs/file-name transcript-path))]
|
transcript-file (when transcript-path (fs/file-name transcript-path))
|
||||||
(str "⏳ **Claude is waiting** in `" project-name "`\n"
|
;; 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"
|
"📁 Path: `" cwd "`\n"
|
||||||
"🕐 Time: " formatted-time "\n"
|
"🕐 Time: " formatted-time "\n"
|
||||||
(when session-id (str "🔑 Session: `" session-id "`\n"))
|
(when session-id (str "🔑 Session: `" session-id "`\n"))
|
||||||
@ -66,13 +76,25 @@
|
|||||||
(println "Error: webhook URL cannot be empty")
|
(println "Error: webhook URL cannot be empty")
|
||||||
(System/exit 1))
|
(System/exit 1))
|
||||||
|
|
||||||
;; Create config directory
|
(println "\nEnter your Discord user ID (optional, for @mentions on permission prompts):")
|
||||||
(fs/create-dirs (fs/parent config-file))
|
(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
|
;; Create config directory
|
||||||
(spit config-file (pr-str {:webhook-url webhook-url}))
|
(fs/create-dirs (fs/parent config-file))
|
||||||
(println "\n✓ Configuration saved to" config-file)
|
|
||||||
(println "\nTest the webhook with: ./iamwaiting test")))
|
;; 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 []
|
(defn test-webhook []
|
||||||
"Test the webhook configuration"
|
"Test the webhook configuration"
|
||||||
@ -119,7 +141,7 @@
|
|||||||
(json/parse-string (first event-data-args) true)
|
(json/parse-string (first event-data-args) true)
|
||||||
(catch Exception _ {})))
|
(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)]
|
result (send-discord-webhook (:webhook-url config) message)]
|
||||||
(if (:success result)
|
(if (:success result)
|
||||||
(println "✓ Notification sent")
|
(println "✓ Notification sent")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user