pi-telegram-notifier 0.1.4 → 0.1.5
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 +18 -1
- package/extensions/index.ts +27 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,24 @@ export PI_TELEGRAM_BOT_TOKEN='your-bot-token'
|
|
|
12
12
|
pi
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### Update or reload Pi
|
|
16
|
+
|
|
17
|
+
If Pi is already running, run `/reload` after installing the package (restart Pi if you just set the token). To update a published install later, run `pi update npm:pi-telegram-notifier`. If you previously installed a local checkout, run `pi list`, then `pi remove /absolute/path/to/pi-telegram-notifier` to avoid loading both copies.
|
|
18
|
+
|
|
19
|
+
### Pair a private chat
|
|
20
|
+
|
|
21
|
+
1. In Pi, run `/telegram-pair`.
|
|
22
|
+
2. In a private chat, send the bot the displayed **`/start <code>`** within five minutes.
|
|
23
|
+
|
|
24
|
+
During pairing, the bot must receive updates through `getUpdates`; disconnect any webhook or other updates consumer first. If pairing fails, the existing chat remains paired.
|
|
25
|
+
|
|
26
|
+
### Check pairing status
|
|
27
|
+
|
|
28
|
+
In Pi, run `/telegram-status` to see whether the bot token is configured and a private chat is paired. This reports saved local state; it does not check live Telegram connectivity.
|
|
29
|
+
|
|
30
|
+
### Switch chats and pairing storage
|
|
31
|
+
|
|
32
|
+
Run `/telegram-pair` again to switch chats. The extension stores only the numeric chat ID in `~/.pi/agent/pi-telegram-notifier.json` (or `$PI_CODING_AGENT_DIR/pi-telegram-notifier.json`), with mode 0600. Pairing uses `getUpdates` only during setup; there is no always-on polling afterward.
|
|
16
33
|
|
|
17
34
|
**Privacy:** final agent responses and the device hostname are sent to Telegram. Responses can contain sensitive text; only use this package if that is acceptable for your projects and Telegram chat. Bot and provider tokens are not stored in the package or sent as message text. Telegram Bot API uses the bot token in the request URL; do not log outgoing URLs. Keep your shell environment and Pi credentials private. A lost or compromised Telegram bot token must be revoked with BotFather.
|
|
18
35
|
|
package/extensions/index.ts
CHANGED
|
@@ -15,13 +15,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
15
15
|
const tokenConfigured = !!process.env.PI_TELEGRAM_BOT_TOKEN;
|
|
16
16
|
const paired = loadChatId(agentDir()) !== undefined;
|
|
17
17
|
ctx.ui.notify([
|
|
18
|
-
'Telegram
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
'Telegram connection',
|
|
19
|
+
'',
|
|
20
|
+
'Configuration',
|
|
21
|
+
`Bot token: ${tokenConfigured ? 'Configured' : 'Not configured'}`,
|
|
22
|
+
`Private chat: ${paired ? 'Paired' : 'Not paired'}`,
|
|
23
|
+
'',
|
|
24
|
+
'Connectivity',
|
|
25
|
+
'Live check: Not performed',
|
|
26
|
+
...(!tokenConfigured || !paired ? [
|
|
27
|
+
'',
|
|
28
|
+
'Next steps',
|
|
29
|
+
...(!tokenConfigured ? ['Set PI_TELEGRAM_BOT_TOKEN and restart Pi.'] : []),
|
|
30
|
+
...(!paired ? ['Run /telegram-pair to pair a private chat.'] : []),
|
|
31
|
+
] : []),
|
|
32
|
+
].join('\n'), 'info');
|
|
25
33
|
},
|
|
26
34
|
});
|
|
27
35
|
pi.registerCommand('telegram-pair', {
|
|
@@ -29,16 +37,24 @@ export default function (pi: ExtensionAPI) {
|
|
|
29
37
|
handler: async (_args, ctx) => {
|
|
30
38
|
const token = process.env.PI_TELEGRAM_BOT_TOKEN;
|
|
31
39
|
if (!token) {
|
|
32
|
-
ctx.ui.notify('
|
|
40
|
+
ctx.ui.notify('Telegram pairing unavailable\n\nSet PI_TELEGRAM_BOT_TOKEN before starting Pi.', 'error');
|
|
33
41
|
return;
|
|
34
42
|
}
|
|
35
43
|
const code = randomBytes(16).toString('hex');
|
|
36
|
-
ctx.ui.notify(
|
|
44
|
+
ctx.ui.notify([
|
|
45
|
+
'Pair Telegram',
|
|
46
|
+
'',
|
|
47
|
+
'In your private chat with the bot, send:',
|
|
48
|
+
'',
|
|
49
|
+
`/start ${code}`,
|
|
50
|
+
'',
|
|
51
|
+
'Code expires in 5 minutes.',
|
|
52
|
+
].join('\n'), 'info');
|
|
37
53
|
try {
|
|
38
54
|
saveChatId(agentDir(), await pairChat(token, code));
|
|
39
|
-
ctx.ui.notify('
|
|
55
|
+
ctx.ui.notify('Telegram paired\n\nPrivate chat linked successfully.', 'info');
|
|
40
56
|
} catch (error) {
|
|
41
|
-
ctx.ui.notify(error instanceof Error ? error.message : 'Telegram pairing failed'
|
|
57
|
+
ctx.ui.notify(`Telegram pairing failed\n\n${error instanceof Error ? error.message : 'Telegram pairing failed'}`, 'error');
|
|
42
58
|
}
|
|
43
59
|
},
|
|
44
60
|
});
|