pi-telegram-notifier 0.1.3 → 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 CHANGED
@@ -12,7 +12,24 @@ export PI_TELEGRAM_BOT_TOKEN='your-bot-token'
12
12
  pi
13
13
  ```
14
14
 
15
- If Pi is already running, run `/reload` after installing the package (restart Pi if you just set the token). If you previously installed a local checkout, run `pi list`, then `pi remove /absolute/path/to/pi-telegram-notifier` to avoid loading both copies. To get future releases, run `pi update npm:pi-telegram-notifier`. In Pi run `/telegram-pair`. Within five minutes send **`/start <code>`** to your bot in a private Telegram chat using the displayed one-time code. 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. To switch chats, run `/telegram-pair` again; the existing chat stays paired if pairing fails. The bot needs to receive messages via `getUpdates` during pairing: a webhook or another updates consumer must be disconnected first. There is no always-on polling after pairing.
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
 
@@ -2,28 +2,59 @@ import { randomBytes } from 'node:crypto';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
5
- import { pairChat, saveChatId } from '#src/telegram';
5
+ import { loadChatId, pairChat, saveChatId } from '#src/telegram';
6
6
  import { registerNotifications } from '#src/notification';
7
7
 
8
8
  const agentDir = () => process.env.PI_CODING_AGENT_DIR || join(homedir(), '.pi', 'agent');
9
9
 
10
10
  export default function (pi: ExtensionAPI) {
11
11
  registerNotifications(pi, agentDir(), process.env.PI_TELEGRAM_BOT_TOKEN);
12
+ pi.registerCommand('telegram-status', {
13
+ description: 'Show the Telegram bot configuration and pairing status',
14
+ handler: async (_args, ctx) => {
15
+ const tokenConfigured = !!process.env.PI_TELEGRAM_BOT_TOKEN;
16
+ const paired = loadChatId(agentDir()) !== undefined;
17
+ ctx.ui.notify([
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');
33
+ },
34
+ });
12
35
  pi.registerCommand('telegram-pair', {
13
36
  description: 'Pair a private Telegram chat with this Pi installation',
14
37
  handler: async (_args, ctx) => {
15
38
  const token = process.env.PI_TELEGRAM_BOT_TOKEN;
16
39
  if (!token) {
17
- ctx.ui.notify('Set PI_TELEGRAM_BOT_TOKEN before starting Pi', 'error');
40
+ ctx.ui.notify('Telegram pairing unavailable\n\nSet PI_TELEGRAM_BOT_TOKEN before starting Pi.', 'error');
18
41
  return;
19
42
  }
20
43
  const code = randomBytes(16).toString('hex');
21
- ctx.ui.notify(`Send /start ${code} to your Telegram bot within 5 minutes`, 'info');
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');
22
53
  try {
23
54
  saveChatId(agentDir(), await pairChat(token, code));
24
- ctx.ui.notify('Private Telegram chat paired', 'info');
55
+ ctx.ui.notify('Telegram paired\n\nPrivate chat linked successfully.', 'info');
25
56
  } catch (error) {
26
- ctx.ui.notify(error instanceof Error ? error.message : 'Telegram pairing failed', 'error');
57
+ ctx.ui.notify(`Telegram pairing failed\n\n${error instanceof Error ? error.message : 'Telegram pairing failed'}`, 'error');
27
58
  }
28
59
  },
29
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-telegram-notifier",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Telegram notifications for final Pi agent responses and provider balances",
5
5
  "type": "module",
6
6
  "license": "MIT",