opencode-discord-notify 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -12
- package/dist/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,18 +60,19 @@ export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
|
|
|
60
60
|
|
|
61
61
|
### Environment Variables
|
|
62
62
|
|
|
63
|
-
| Variable
|
|
64
|
-
|
|
|
65
|
-
| `DISCORD_WEBHOOK_URL`
|
|
66
|
-
| `DISCORD_WEBHOOK_USERNAME`
|
|
67
|
-
| `DISCORD_WEBHOOK_AVATAR_URL`
|
|
68
|
-
| `DISCORD_WEBHOOK_COMPLETE_MENTION`
|
|
69
|
-
| `DISCORD_WEBHOOK_PERMISSION_MENTION`
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
63
|
+
| Variable | Required | Default | Description |
|
|
64
|
+
| ----------------------------------------------- | -------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `DISCORD_WEBHOOK_URL` | ✅ Yes | - | Discord webhook URL. Plugin is disabled if not set. |
|
|
66
|
+
| `DISCORD_WEBHOOK_USERNAME` | ❌ No | - | Custom username for webhook posts |
|
|
67
|
+
| `DISCORD_WEBHOOK_AVATAR_URL` | ❌ No | - | Custom avatar URL for webhook posts |
|
|
68
|
+
| `DISCORD_WEBHOOK_COMPLETE_MENTION` | ❌ No | - | Add `@everyone` or `@here` to session completion/error notifications |
|
|
69
|
+
| `DISCORD_WEBHOOK_PERMISSION_MENTION` | ❌ No | - | Add `@everyone` or `@here` to permission request notifications |
|
|
70
|
+
| `DISCORD_WEBHOOK_COMPLETE_INCLUDE_LAST_MESSAGE` | ❌ No | `1` | Set to `0` to exclude the last assistant message from session completion notifications |
|
|
71
|
+
| `DISCORD_WEBHOOK_EXCLUDE_INPUT_CONTEXT` | ❌ No | `1` | Set to `0` to include file context in notifications |
|
|
72
|
+
| `DISCORD_WEBHOOK_SHOW_ERROR_ALERT` | ❌ No | `1` | Set to `0` to disable error toast notifications |
|
|
73
|
+
| `DISCORD_SEND_PARAMS` | ❌ No | - | Comma-separated embed fields: `sessionID,permissionID,type,pattern,messageID,callID,partID,role,directory,projectID` |
|
|
74
|
+
| `DISCORD_WEBHOOK_FALLBACK_URL` | ❌ No | - | Fallback webhook URL for text channel (sends mentions here too for guaranteed ping) |
|
|
75
|
+
| `DISCORD_NOTIFY_QUEUE_DB_PATH` | ❌ No | `~/.config/opencode/discord-notify-queue.db` | Custom path for the persistent queue database |
|
|
75
76
|
|
|
76
77
|
### Example Configuration
|
|
77
78
|
|
|
@@ -108,6 +109,8 @@ export DISCORD_WEBHOOK_AVATAR_URL="https://example.com/avatar.png"
|
|
|
108
109
|
- **`session.created`**: Queues session start notification (sent when thread info is available)
|
|
109
110
|
- **`permission.updated`**: Posts permission request immediately
|
|
110
111
|
- **`session.idle`**: Posts session completion notification
|
|
112
|
+
- Includes the last assistant message in the embed description by default (customizable via `DISCORD_WEBHOOK_COMPLETE_INCLUDE_LAST_MESSAGE`)
|
|
113
|
+
- Message is truncated to 4096 characters if needed
|
|
111
114
|
- **`session.error`**: Posts error notification (skipped if `sessionID` missing)
|
|
112
115
|
- **`todo.updated`**: Posts checklist with `[▶]` (in progress), `[✓]` (completed); excludes cancelled
|
|
113
116
|
- **`message.updated`**: Tracked internally for role detection (not posted)
|
|
@@ -176,6 +179,7 @@ All notifications are stored in a local SQLite database before sending:
|
|
|
176
179
|
- **Batch size**: Processes 1 message at a time to ensure thread ID consistency
|
|
177
180
|
|
|
178
181
|
**Benefits**:
|
|
182
|
+
|
|
179
183
|
- Messages survive OpenCode restarts
|
|
180
184
|
- Prevents data loss during network issues
|
|
181
185
|
- Ensures correct thread naming with user's first message
|
package/dist/index.js
CHANGED
|
@@ -529,6 +529,8 @@ var plugin = async ({ client }) => {
|
|
|
529
529
|
const excludeInputContext = excludeInputContextRaw !== "0";
|
|
530
530
|
const showErrorAlertRaw = (getEnv("DISCORD_WEBHOOK_SHOW_ERROR_ALERT") ?? "1").trim();
|
|
531
531
|
const showErrorAlert = showErrorAlertRaw !== "0";
|
|
532
|
+
const includeLastMessageInCompleteRaw = (getEnv("DISCORD_WEBHOOK_COMPLETE_INCLUDE_LAST_MESSAGE") ?? "1").trim();
|
|
533
|
+
const includeLastMessageInComplete = includeLastMessageInCompleteRaw !== "0";
|
|
532
534
|
const waitOnRateLimitMs = DEFAULT_RATE_LIMIT_WAIT_MS;
|
|
533
535
|
const sendParams = parseSendParams(getEnv("DISCORD_SEND_PARAMS"));
|
|
534
536
|
const fallbackWebhookUrl = (getEnv("DISCORD_WEBHOOK_FALLBACK_URL") ?? "").trim() || void 0;
|
|
@@ -590,6 +592,7 @@ var plugin = async ({ client }) => {
|
|
|
590
592
|
}
|
|
591
593
|
});
|
|
592
594
|
const firstUserTextBySession = /* @__PURE__ */ new Map();
|
|
595
|
+
const lastAssistantMessageBySession = /* @__PURE__ */ new Map();
|
|
593
596
|
const pendingTextPartsByMessageId = /* @__PURE__ */ new Map();
|
|
594
597
|
const messageRoleById = /* @__PURE__ */ new Map();
|
|
595
598
|
const lastSessionInfo = /* @__PURE__ */ new Map();
|
|
@@ -682,6 +685,9 @@ var plugin = async ({ client }) => {
|
|
|
682
685
|
const normalized = normalizeThreadTitle(text);
|
|
683
686
|
if (normalized) firstUserTextBySession.set(sessionID, normalized);
|
|
684
687
|
}
|
|
688
|
+
if (role === "assistant" && text.trim()) {
|
|
689
|
+
lastAssistantMessageBySession.set(sessionID, text);
|
|
690
|
+
}
|
|
685
691
|
if (role === "user" && !sessionToThread.has(sessionID)) {
|
|
686
692
|
const sessionCreatedBody = buildSessionCreatedEmbed(sessionID);
|
|
687
693
|
if (sessionCreatedBody) {
|
|
@@ -775,9 +781,11 @@ var plugin = async ({ client }) => {
|
|
|
775
781
|
const sessionID = event.properties?.sessionID;
|
|
776
782
|
if (!sessionID) return;
|
|
777
783
|
const mention = buildCompleteMention();
|
|
784
|
+
const lastMessage = includeLastMessageInComplete ? lastAssistantMessageBySession.get(sessionID) : void 0;
|
|
778
785
|
const embed = {
|
|
779
786
|
title: "Session completed",
|
|
780
787
|
color: COLORS.success,
|
|
788
|
+
description: lastMessage ? truncateText(lastMessage, DISCORD_EMBED_DESCRIPTION_MAX_LENGTH) : void 0,
|
|
781
789
|
fields: buildFields(
|
|
782
790
|
filterSendFields(
|
|
783
791
|
[["sessionID", sessionID]],
|