@bazilio-san/codex-notify 1.0.6 → 1.0.9
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 +48 -36
- package/bin/cli.js +7 -7
- package/package.json +2 -2
- package/src/channels.js +15 -0
- package/src/config.js +6 -1
- package/src/install.js +32 -11
- package/src/notifier.js +16 -12
- package/src/prompt.js +3 -3
- package/src/send-sample.js +10 -6
- package/src/show-toast.ps1 +11 -0
- package/src/telegram.js +3 -3
- package/src/uninstall.js +3 -3
- package/src/windows.js +20 -0
package/README.md
CHANGED
|
@@ -1,41 +1,54 @@
|
|
|
1
1
|
# codex-notify
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Get a notification when Codex finishes a turn. Choose Telegram, Windows desktop notifications, or both. Codex launches
|
|
4
|
+
the notifier using the `notify` setting in its configuration file.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Windows notifications show the project name. Telegram messages also include your prompt and the final Codex response.
|
|
7
|
+
By default, the bot deletes its messages older than 24 hours the next time it sends a notification.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Requirements
|
|
10
10
|
|
|
11
|
-
- Node.js 18
|
|
12
|
-
-
|
|
13
|
-
- Telegram
|
|
11
|
+
- Node.js 18 or later and the Codex command-line interface (CLI).
|
|
12
|
+
- For desktop notifications, run Codex on Windows with Windows PowerShell available.
|
|
13
|
+
- For Telegram, create a bot with [@BotFather](https://t.me/BotFather) and send your bot a message before setup.
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Installation
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
Install the package and start the setup wizard.
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
npm install -g @bazilio-san/codex-notify
|
|
21
21
|
codex-notify install
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
`~/.codex/config.toml
|
|
24
|
+
The wizard saves your preferences to `~/.codex/codex-notify.config.json`, registers the notification command in
|
|
25
|
+
`~/.codex/config.toml`, and sends a test notification. Restart Codex if it was already running during setup.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
## Enable Windows notifications
|
|
28
|
+
|
|
29
|
+
Run `codex-notify install` to choose your channels, even if you have already set up Telegram. From a local checkout,
|
|
30
|
+
run `node .\bin\cli.js install` in PowerShell from the project root.
|
|
31
|
+
|
|
32
|
+
- Select **1** for Telegram only.
|
|
33
|
+
- Select **2** for Windows desktop notifications only. The built-in Windows PowerShell is sufficient.
|
|
34
|
+
- Select **3** for both channels. Press Enter at the Telegram bot token prompt to keep your saved token.
|
|
35
|
+
|
|
36
|
+
To send another test notification to your selected channels, run the command below. From a local checkout, use
|
|
37
|
+
`node .\bin\cli.js test`.
|
|
28
38
|
|
|
29
39
|
```bash
|
|
30
40
|
codex-notify test
|
|
31
41
|
```
|
|
32
42
|
|
|
33
|
-
##
|
|
43
|
+
## Configuration
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
The following example shows a Telegram configuration in `~/.codex/codex-notify.config.json`.
|
|
36
46
|
|
|
37
47
|
```json
|
|
38
48
|
{
|
|
49
|
+
"windows": {
|
|
50
|
+
"enabled": false
|
|
51
|
+
},
|
|
39
52
|
"telegram": {
|
|
40
53
|
"enabled": true,
|
|
41
54
|
"token": "123456789:ABC...",
|
|
@@ -47,44 +60,43 @@ codex-notify test
|
|
|
47
60
|
}
|
|
48
61
|
```
|
|
49
62
|
|
|
50
|
-
|
|
63
|
+
Environment variables override the corresponding settings in the configuration file.
|
|
51
64
|
|
|
52
|
-
- `CODEX_NOTIFY_TELEGRAM_TOKEN`
|
|
53
|
-
- `CODEX_NOTIFY_TELEGRAM_CHAT_ID`
|
|
54
|
-
- `CODEX_NOTIFY_TELEGRAM=0`
|
|
55
|
-
- `
|
|
56
|
-
- `
|
|
65
|
+
- `CODEX_NOTIFY_TELEGRAM_TOKEN` sets the bot token.
|
|
66
|
+
- `CODEX_NOTIFY_TELEGRAM_CHAT_ID` sets the ID of the private chat or group.
|
|
67
|
+
- `CODEX_NOTIFY_TELEGRAM=0` disables Telegram messages.
|
|
68
|
+
- `CODEX_NOTIFY_WINDOWS=1` enables Windows desktop notifications. Set it to `0` to disable them.
|
|
69
|
+
- `CODEX_NOTIFY_INCLUDE_LAST_MESSAGE=0` omits the final Codex response from Telegram messages.
|
|
70
|
+
- `CODEX_NOTIFY_DEBUG=1` includes the thread ID in Telegram messages and enables diagnostic output.
|
|
57
71
|
|
|
58
|
-
|
|
72
|
+
Set `deleteAfterHours` to `0` to turn off automatic deletion of older Telegram messages.
|
|
59
73
|
|
|
60
|
-
##
|
|
74
|
+
## Uninstall
|
|
61
75
|
|
|
62
76
|
```bash
|
|
63
77
|
codex-notify uninstall
|
|
64
|
-
npm uninstall -g codex-notify
|
|
78
|
+
npm uninstall -g @bazilio-san/codex-notify
|
|
65
79
|
```
|
|
66
80
|
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
The first command removes the package's `notify` entry from the Codex configuration and keeps your channel settings
|
|
82
|
+
for future installations.
|
|
69
83
|
|
|
70
|
-
##
|
|
84
|
+
## Supported Codex events
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
передаются этому уведомителю.
|
|
86
|
+
The notifier handles `agent-turn-complete`, which Codex emits at the end of a turn. The Codex interface handles
|
|
87
|
+
approval requests and prompts for additional input through its own notifications.
|
|
75
88
|
|
|
76
|
-
##
|
|
89
|
+
## License
|
|
77
90
|
|
|
78
91
|
MIT
|
|
79
92
|
|
|
80
|
-
##
|
|
93
|
+
## Publishing
|
|
81
94
|
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
Run the release script from a clean `master` branch. It increments the patch version, runs the checks, creates a
|
|
96
|
+
commit and tag, pushes them to GitHub, and publishes the package to npm with public access.
|
|
84
97
|
|
|
85
98
|
```bash
|
|
86
99
|
npm run release
|
|
87
100
|
```
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
`npm run release:current`.
|
|
102
|
+
To publish the version already specified in `package.json`, run `npm run release:current`.
|
package/bin/cli.js
CHANGED
|
@@ -31,7 +31,7 @@ async function main() {
|
|
|
31
31
|
await notify(command);
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
|
-
console.error(
|
|
34
|
+
console.error(`Unknown command: ${command}`);
|
|
35
35
|
printHelp();
|
|
36
36
|
process.exitCode = 1;
|
|
37
37
|
}
|
|
@@ -42,13 +42,13 @@ function looksLikeCodexEvent(value) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function printHelp() {
|
|
45
|
-
console.log(
|
|
45
|
+
console.log(`Usage: codex-notify <command>
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
install
|
|
49
|
-
test
|
|
50
|
-
uninstall
|
|
51
|
-
--help
|
|
47
|
+
Commands:
|
|
48
|
+
install Choose notification channels and connect them to Codex
|
|
49
|
+
test Send a test notification
|
|
50
|
+
uninstall Disconnect from Codex and keep your notification settings
|
|
51
|
+
--help Show this help message`);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
main().catch((error) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bazilio-san/codex-notify",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Telegram notifications when a Codex turn completes",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Windows and Telegram notifications when a Codex turn completes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/notifier.js",
|
|
7
7
|
"bin": {
|
package/src/channels.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export async function deliver(config, telegram, windows) {
|
|
2
|
+
const deliveries = [];
|
|
3
|
+
if (config.telegram.enabled && config.telegram.token && config.telegram.chatId) {
|
|
4
|
+
deliveries.push(telegram());
|
|
5
|
+
}
|
|
6
|
+
if (config.windows.enabled) {
|
|
7
|
+
deliveries.push(windows());
|
|
8
|
+
}
|
|
9
|
+
const results = await Promise.allSettled(deliveries);
|
|
10
|
+
const failures = results.filter((result) => result.status === 'rejected');
|
|
11
|
+
if (failures.length) {
|
|
12
|
+
throw new Error(failures.map((result) => result.reason.message).join('\n'));
|
|
13
|
+
}
|
|
14
|
+
return results.length;
|
|
15
|
+
}
|
package/src/config.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { getConfigPath } from './paths.js';
|
|
5
5
|
|
|
6
6
|
export const DEFAULT_CONFIG = Object.freeze({
|
|
7
|
+
windows: { enabled: false },
|
|
7
8
|
telegram: {
|
|
8
9
|
enabled: true,
|
|
9
10
|
token: '',
|
|
@@ -20,13 +21,14 @@ export function loadConfig(configPath = getConfigPath()) {
|
|
|
20
21
|
stored = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
21
22
|
} catch (error) {
|
|
22
23
|
if (error.code !== 'ENOENT') {
|
|
23
|
-
throw new Error(
|
|
24
|
+
throw new Error(`Could not read settings from ${configPath}: ${error.message}`);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
const config = {
|
|
28
29
|
...DEFAULT_CONFIG,
|
|
29
30
|
...stored,
|
|
31
|
+
windows: { ...DEFAULT_CONFIG.windows, ...stored.windows },
|
|
30
32
|
telegram: {
|
|
31
33
|
...DEFAULT_CONFIG.telegram,
|
|
32
34
|
...stored.telegram,
|
|
@@ -44,6 +46,9 @@ export function saveConfig(config, configPath = getConfigPath()) {
|
|
|
44
46
|
|
|
45
47
|
function applyEnvironment(config) {
|
|
46
48
|
const env = process.env;
|
|
49
|
+
if (env.CODEX_NOTIFY_WINDOWS !== undefined) {
|
|
50
|
+
config.windows.enabled = parseBoolean(env.CODEX_NOTIFY_WINDOWS);
|
|
51
|
+
}
|
|
47
52
|
if (env.CODEX_NOTIFY_TELEGRAM_TOKEN !== undefined) {
|
|
48
53
|
config.telegram.token = env.CODEX_NOTIFY_TELEGRAM_TOKEN;
|
|
49
54
|
}
|
package/src/install.js
CHANGED
|
@@ -4,22 +4,29 @@ import { createNotifyCommand, registerNotify } from './codex-config.js';
|
|
|
4
4
|
import { loadConfig, saveConfig } from './config.js';
|
|
5
5
|
import { getCodexConfigPath, getConfigPath } from './paths.js';
|
|
6
6
|
import { askRequired, withPrompts } from './prompt.js';
|
|
7
|
-
import {
|
|
7
|
+
import { testNotification } from './send-sample.js';
|
|
8
|
+
import { findChatId } from './telegram.js';
|
|
8
9
|
|
|
9
10
|
export async function install() {
|
|
10
11
|
const config = loadConfig();
|
|
11
12
|
await withPrompts(async (prompt) => {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
if (process.platform === 'win32') {
|
|
14
|
+
await chooseChannels(prompt, config);
|
|
15
|
+
} else {
|
|
16
|
+
config.windows.enabled = false;
|
|
17
|
+
config.telegram.enabled = true;
|
|
18
|
+
}
|
|
19
|
+
if (!config.telegram.enabled) return;
|
|
20
|
+
console.log('Create a bot with @BotFather and send it a message before continuing.\n');
|
|
14
21
|
|
|
15
|
-
config.telegram.token = await askRequired(prompt, '
|
|
22
|
+
config.telegram.token = await askRequired(prompt, 'Enter your Telegram bot token', config.telegram.token);
|
|
16
23
|
const detectedChatId = await tryFindChatId(config.telegram.token);
|
|
17
24
|
if (detectedChatId) {
|
|
18
|
-
console.log(`Telegram
|
|
25
|
+
console.log(`Found Telegram chat: ${detectedChatId}`);
|
|
19
26
|
}
|
|
20
27
|
config.telegram.chatId = detectedChatId || (await askRequired(
|
|
21
28
|
prompt,
|
|
22
|
-
'
|
|
29
|
+
'Enter your Telegram chat ID',
|
|
23
30
|
config.telegram.chatId,
|
|
24
31
|
));
|
|
25
32
|
});
|
|
@@ -27,18 +34,32 @@ export async function install() {
|
|
|
27
34
|
saveConfig(config);
|
|
28
35
|
const cliPath = fileURLToPath(new URL('../bin/cli.js', import.meta.url));
|
|
29
36
|
registerNotify(createNotifyCommand(cliPath));
|
|
30
|
-
|
|
37
|
+
console.log(`\nSaved notification settings to ${getConfigPath()}.`);
|
|
38
|
+
console.log(`Registered the notification command in ${getCodexConfigPath()}.`);
|
|
39
|
+
await testNotification(config);
|
|
40
|
+
console.log('Restart Codex if it is already running.');
|
|
41
|
+
}
|
|
31
42
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
console.log('
|
|
43
|
+
async function chooseChannels(prompt, config) {
|
|
44
|
+
const current = config.windows.enabled ? (config.telegram.enabled ? '3' : '2') : '1';
|
|
45
|
+
console.log('Where should Codex send notifications?');
|
|
46
|
+
console.log('1. Telegram\n2. Windows Notification Center\n3. Telegram and Windows');
|
|
47
|
+
while (true) {
|
|
48
|
+
const choice = (await prompt.question(`Enter a number or press Enter to select ${current}: `)).trim() || current;
|
|
49
|
+
if (['1', '2', '3'].includes(choice)) {
|
|
50
|
+
config.telegram.enabled = choice !== '2';
|
|
51
|
+
config.windows.enabled = choice !== '1';
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
console.log('Enter a number from 1 to 3.');
|
|
55
|
+
}
|
|
35
56
|
}
|
|
36
57
|
|
|
37
58
|
async function tryFindChatId(token) {
|
|
38
59
|
try {
|
|
39
60
|
return await findChatId(token);
|
|
40
61
|
} catch (error) {
|
|
41
|
-
console.warn(
|
|
62
|
+
console.warn(`Could not detect the Telegram chat: ${error.message}`);
|
|
42
63
|
return '';
|
|
43
64
|
}
|
|
44
65
|
}
|
package/src/notifier.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
|
+
import { deliver } from './channels.js';
|
|
3
4
|
import { loadConfig } from './config.js';
|
|
4
5
|
import { loadState, saveState } from './state.js';
|
|
5
6
|
import { deleteTelegramMessage, escapeHtml, sendTelegramMessage, truncateText } from './telegram.js';
|
|
7
|
+
import { showWindowsNotification } from './windows.js';
|
|
6
8
|
|
|
7
9
|
export async function notify(rawEvent) {
|
|
8
10
|
const config = loadConfig();
|
|
9
|
-
if (!config.telegram.enabled || !config.telegram.token || !config.telegram.chatId) {
|
|
10
|
-
debug(config, 'Уведомление пропущено, потому что Telegram не настроен или отключён.');
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
11
|
const event = parseEvent(rawEvent);
|
|
15
12
|
if (event.type !== 'agent-turn-complete') {
|
|
16
|
-
debug(config,
|
|
13
|
+
debug(config, `Skipping event with type ${event.type || '(unspecified)'}.`);
|
|
17
14
|
return;
|
|
18
15
|
}
|
|
19
16
|
|
|
17
|
+
await deliver(config, () => notifyTelegram(config, event), () => {
|
|
18
|
+
const cwd = event.cwd || process.cwd();
|
|
19
|
+
return showWindowsNotification('Codex finished its turn', `Project: ${path.basename(cwd) || cwd}`);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function notifyTelegram(config, event) {
|
|
20
24
|
const state = loadState();
|
|
21
25
|
await deleteExpiredMessages(config, state);
|
|
22
26
|
const sent = await sendTelegramMessage(config, formatNotification(event, config));
|
|
@@ -26,12 +30,12 @@ export async function notify(rawEvent) {
|
|
|
26
30
|
|
|
27
31
|
export function parseEvent(rawEvent) {
|
|
28
32
|
if (!rawEvent) {
|
|
29
|
-
throw new Error('Codex
|
|
33
|
+
throw new Error('Codex did not provide event data.');
|
|
30
34
|
}
|
|
31
35
|
try {
|
|
32
36
|
return JSON.parse(rawEvent);
|
|
33
37
|
} catch (error) {
|
|
34
|
-
throw new Error(`Codex
|
|
38
|
+
throw new Error(`Codex provided invalid JSON for the event: ${error.message}`);
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -40,16 +44,16 @@ export function formatNotification(event, config) {
|
|
|
40
44
|
const project = path.basename(cwd) || cwd;
|
|
41
45
|
const input = Array.isArray(event['input-messages']) ? event['input-messages'].join('\n') : '';
|
|
42
46
|
const response = config.telegram.includeLastMessage ? event['last-assistant-message'] || '' : '';
|
|
43
|
-
const lines = [`✅ <b>Codex
|
|
47
|
+
const lines = [`✅ <b>Codex finished its turn</b>`, `<b>Project:</b> <code>${escapeHtml(project)}</code>`];
|
|
44
48
|
|
|
45
49
|
if (input) {
|
|
46
|
-
lines.push('', '<b
|
|
50
|
+
lines.push('', '<b>Task:</b>', escapeHtml(truncateText(input, 900)));
|
|
47
51
|
}
|
|
48
52
|
if (response) {
|
|
49
|
-
lines.push('', '<b
|
|
53
|
+
lines.push('', '<b>Response:</b>', escapeHtml(truncateText(response, 2800)));
|
|
50
54
|
}
|
|
51
55
|
if (config.debug) {
|
|
52
|
-
lines.push('', `<b
|
|
56
|
+
lines.push('', `<b>Thread:</b> <code>${escapeHtml(event['thread-id'] || 'unknown')}</code>`);
|
|
53
57
|
}
|
|
54
58
|
return lines.join('\n');
|
|
55
59
|
}
|
package/src/prompt.js
CHANGED
|
@@ -2,7 +2,7 @@ import readline from 'node:readline/promises';
|
|
|
2
2
|
|
|
3
3
|
export async function withPrompts(callback) {
|
|
4
4
|
if (!process.stdin.isTTY) {
|
|
5
|
-
throw new Error('
|
|
5
|
+
throw new Error('Run codex-notify install in an interactive terminal to set up notifications.');
|
|
6
6
|
}
|
|
7
7
|
const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
8
8
|
try {
|
|
@@ -14,7 +14,7 @@ export async function withPrompts(callback) {
|
|
|
14
14
|
|
|
15
15
|
export async function askRequired(prompt, question, currentValue = '') {
|
|
16
16
|
while (true) {
|
|
17
|
-
const suffix = currentValue ? ' (
|
|
17
|
+
const suffix = currentValue ? ' (press Enter to keep the current value)' : '';
|
|
18
18
|
const answer = (await prompt.question(`${question}${suffix}: `)).trim();
|
|
19
19
|
if (answer) {
|
|
20
20
|
return answer;
|
|
@@ -22,6 +22,6 @@ export async function askRequired(prompt, question, currentValue = '') {
|
|
|
22
22
|
if (currentValue) {
|
|
23
23
|
return currentValue;
|
|
24
24
|
}
|
|
25
|
-
console.log('
|
|
25
|
+
console.log('Enter a value to continue.');
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/send-sample.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { deliver } from './channels.js';
|
|
1
2
|
import { loadConfig } from './config.js';
|
|
2
3
|
import { sendTelegramMessage } from './telegram.js';
|
|
4
|
+
import { showWindowsNotification } from './windows.js';
|
|
3
5
|
|
|
4
|
-
export async function testNotification() {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export async function testNotification(config = loadConfig()) {
|
|
7
|
+
const sent = await deliver(config,
|
|
8
|
+
() => sendTelegramMessage(config, '✅ <b>codex-notify test</b>\nThis is a test notification.'),
|
|
9
|
+
() => showWindowsNotification('codex-notify test', 'Codex will notify you when it finishes a turn.'),
|
|
10
|
+
);
|
|
11
|
+
if (!sent) {
|
|
12
|
+
throw new Error('Run codex-notify install to enable notifications first.');
|
|
8
13
|
}
|
|
9
|
-
|
|
10
|
-
console.log('Пробное уведомление успешно отправлено в Telegram.');
|
|
14
|
+
console.log('Sent a test notification to the selected channels.');
|
|
11
15
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
|
|
3
|
+
$null = [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime]
|
|
4
|
+
$template = [Windows.UI.Notifications.ToastTemplateType]::ToastText02
|
|
5
|
+
$document = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($template)
|
|
6
|
+
$fields = $document.GetElementsByTagName('text')
|
|
7
|
+
$null = $fields.Item(0).AppendChild($document.CreateTextNode($env:CODEX_TOAST_TITLE))
|
|
8
|
+
$null = $fields.Item(1).AppendChild($document.CreateTextNode($env:CODEX_TOAST_MESSAGE))
|
|
9
|
+
$appId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
|
|
10
|
+
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($appId)
|
|
11
|
+
$notifier.Show([Windows.UI.Notifications.ToastNotification]::new($document))
|
package/src/telegram.js
CHANGED
|
@@ -57,11 +57,11 @@ async function readTelegramResponse(response) {
|
|
|
57
57
|
try {
|
|
58
58
|
return await response.json();
|
|
59
59
|
} catch {
|
|
60
|
-
return { ok: false, description: 'Telegram
|
|
60
|
+
return { ok: false, description: 'Telegram returned a response that could not be parsed as JSON.' };
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function formatTelegramError(status, result) {
|
|
65
|
-
const description = result.description || 'Telegram
|
|
66
|
-
return `Telegram API
|
|
65
|
+
const description = result.description || 'Telegram did not provide error details.';
|
|
66
|
+
return `The Telegram API returned HTTP ${status}: ${description}`;
|
|
67
67
|
}
|
package/src/uninstall.js
CHANGED
|
@@ -7,9 +7,9 @@ export async function uninstall() {
|
|
|
7
7
|
const cliPath = fileURLToPath(new URL('../bin/cli.js', import.meta.url));
|
|
8
8
|
const removed = unregisterNotify(createNotifyCommand(cliPath));
|
|
9
9
|
if (removed) {
|
|
10
|
-
console.log(
|
|
10
|
+
console.log(`Removed the notification command from ${getCodexConfigPath()}.`);
|
|
11
11
|
} else {
|
|
12
|
-
console.log('
|
|
12
|
+
console.log('Codex has no registered codex-notify command.');
|
|
13
13
|
}
|
|
14
|
-
console.log(
|
|
14
|
+
console.log(`Your notification settings are available in ${getConfigPath()} for future use.`);
|
|
15
15
|
}
|
package/src/windows.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
|
|
5
|
+
const execute = promisify(execFile);
|
|
6
|
+
const script = fileURLToPath(new URL('./show-toast.ps1', import.meta.url));
|
|
7
|
+
|
|
8
|
+
export async function showWindowsNotification(title, message) {
|
|
9
|
+
if (process.platform !== 'win32') {
|
|
10
|
+
throw new Error('Run codex-notify on Windows to receive desktop notifications.');
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
await execute('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-File', script], {
|
|
14
|
+
windowsHide: true,
|
|
15
|
+
env: { ...process.env, CODEX_TOAST_TITLE: title, CODEX_TOAST_MESSAGE: message },
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(`Could not send the Windows notification. ${error.stderr?.trim() || error.message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|