paperclip-plugin-telegram 0.1.0 → 0.2.1

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.
Files changed (48) hide show
  1. package/README.md +86 -6
  2. package/package.json +3 -10
  3. package/src/acp-bridge.ts +1273 -0
  4. package/src/adapter.ts +129 -0
  5. package/src/command-registry.ts +482 -0
  6. package/src/commands.ts +346 -0
  7. package/src/constants.ts +51 -0
  8. package/src/escalation.ts +421 -0
  9. package/src/formatters.ts +148 -0
  10. package/src/index.ts +6 -0
  11. package/src/manifest.ts +246 -0
  12. package/src/media-pipeline.ts +234 -0
  13. package/src/telegram-api.ts +202 -0
  14. package/src/watch-registry.ts +369 -0
  15. package/src/worker.ts +783 -0
  16. package/tests/acp-bridge.test.ts +314 -0
  17. package/tests/command-registry.test.ts +283 -0
  18. package/tests/commands.test.ts +213 -0
  19. package/tests/escalation.test.ts +550 -0
  20. package/tests/formatters.test.ts +185 -0
  21. package/tests/media-pipeline.test.ts +324 -0
  22. package/tests/telegram-api.test.ts +108 -0
  23. package/tests/watch-registry.test.ts +404 -0
  24. package/tsconfig.json +16 -0
  25. package/dist/acp-bridge.d.ts +0 -12
  26. package/dist/acp-bridge.js +0 -166
  27. package/dist/acp-bridge.js.map +0 -1
  28. package/dist/commands.d.ts +0 -10
  29. package/dist/commands.js +0 -212
  30. package/dist/commands.js.map +0 -1
  31. package/dist/constants.d.ts +0 -24
  32. package/dist/constants.js +0 -25
  33. package/dist/constants.js.map +0 -1
  34. package/dist/formatters.d.ts +0 -13
  35. package/dist/formatters.js +0 -130
  36. package/dist/formatters.js.map +0 -1
  37. package/dist/index.d.ts +0 -1
  38. package/dist/index.js +0 -2
  39. package/dist/index.js.map +0 -1
  40. package/dist/manifest.d.ts +0 -3
  41. package/dist/manifest.js +0 -125
  42. package/dist/manifest.js.map +0 -1
  43. package/dist/telegram-api.d.ts +0 -28
  44. package/dist/telegram-api.js +0 -147
  45. package/dist/telegram-api.js.map +0 -1
  46. package/dist/worker.d.ts +0 -1
  47. package/dist/worker.js +0 -300
  48. package/dist/worker.js.map +0 -1
package/README.md CHANGED
@@ -1,19 +1,76 @@
1
1
  # paperclip-plugin-telegram
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/paperclip-plugin-telegram)](https://www.npmjs.com/package/paperclip-plugin-telegram)
4
+
3
5
  Bidirectional Telegram integration for [Paperclip](https://github.com/paperclipai/paperclip). Push agent notifications to Telegram, receive bot commands, approve requests with inline buttons, and route forum topics to projects.
4
6
 
5
7
  Built on the Paperclip plugin SDK and the domain event bridge ([PR #909](https://github.com/paperclipai/paperclip/pull/909)).
6
8
 
7
9
  ## Features
8
10
 
11
+ ### Core
12
+
9
13
  - **Push notifications** on issue created, issue done, approval requested, agent error, run lifecycle
10
- - **Bot commands**: `/status`, `/issues`, `/agents`, `/approve`, `/help`, `/connect`
14
+ - **Bot commands**: `/status`, `/issues`, `/agents`, `/approve`, `/help`, `/connect`, `/connect-topic`, `/acp`, `/commands`
11
15
  - **Inline buttons** for approve/reject on approval notifications
12
16
  - **Inbound routing**: reply to a notification in Telegram and it becomes an issue comment in Paperclip
13
17
  - **Per-company chat routing** with `/connect` command
14
18
  - **Forum topic routing**: map Telegram topics to Paperclip projects
15
19
  - **Daily digest**: scheduled summary of agent activity
16
20
  - **MarkdownV2 formatting** with automatic plain text fallback
21
+ - **ACP bridge**: `/acp spawn`, `/acp status`, `/acp cancel`, `/acp close` for managing agent sessions
22
+
23
+ ### Phase 1: HITL Escalation
24
+
25
+ - Agents call `escalate_to_human` tool when stuck (low confidence, user request, policy violation, unknown intent)
26
+ - Escalation posted to dedicated channel with conversation context, suggested reply, and confidence score
27
+ - Inline buttons: Send Suggested Reply, Reply, Override, Dismiss
28
+ - Configurable timeout with default actions (`defer`, `auto_reply`, `close`)
29
+ - Hold message sent to customer while waiting for human response
30
+ - Reply routing back to originating chat via native or ACP transport
31
+
32
+ ### Phase 2: Multi-Agent Group Threads
33
+
34
+ - Multiple agents per thread (up to 5 configurable via `MAX_AGENTS_PER_THREAD`)
35
+ - `@mention` routing: address a specific agent by name in a multi-agent thread
36
+ - Reply-to routing: reply to an agent's message to route to that agent
37
+ - Fallback routing: most recently active agent receives unaddressed messages
38
+ - **Handoff**: agents call `handoff_to_agent` tool to transfer work, with optional human approval gate
39
+ - **Discuss**: agents call `discuss_with_agent` tool to start back-and-forth conversation loops
40
+ - Conversation loops with configurable max turns and human checkpoint pauses
41
+ - Stale loop detection (auto-pause when output repeats)
42
+ - Output sequencing so multi-agent responses don't interleave
43
+ - Native-first spawning: tries Paperclip agent sessions before falling back to ACP
44
+ - Auto-spawn on handoff/discuss if target agent isn't already in the thread
45
+
46
+ ### Phase 3: Media-to-Task Pipeline
47
+
48
+ - Voice messages, audio, video notes, documents, and photos routed to agents
49
+ - Voice/audio transcription via Whisper API with transcription preview posted back
50
+ - **Brief Agent**: media sent to intake channels is forwarded to a configurable Brief Agent for triage
51
+ - Media in active agent threads is routed to the active session (native or ACP)
52
+
53
+ ### Phase 4: Custom Workflow Commands
54
+
55
+ - `/commands import <json>` - import a multi-step workflow as a custom slash command
56
+ - `/commands list` - show all registered custom commands
57
+ - `/commands run <name> [args]` - execute a workflow
58
+ - `/commands delete <name>` - remove a custom command
59
+ - Custom commands invocable directly as `/<name>` (cannot override built-ins)
60
+ - **Workflow step types**: `fetch_issue`, `invoke_agent`, `http_request`, `send_message`, `create_issue`, `wait_approval`, `set_state`
61
+ - Template interpolation: `{{arg0}}`, `{{args}}`, `{{prev.result}}`, `{{step_id.result}}`
62
+ - Per-company command registry
63
+
64
+ ### Phase 5: Proactive Agent Suggestions
65
+
66
+ - Agents call `register_watch` tool to set up condition-based monitors
67
+ - Watch conditions: `gt`, `lt`, `eq`, `ne`, `contains`, `exists` operators on entity fields
68
+ - Watches evaluate against issues, agents, or custom state-stored data
69
+ - Built-in templates: `invoice-overdue`, `lead-stale`
70
+ - Custom templates with `{{field}}` placeholder interpolation
71
+ - Rate limiting: configurable max suggestions per hour per company
72
+ - Deduplication: same watch+entity won't re-fire within a configurable window (default 24h)
73
+ - Scheduled job checks all watches periodically
17
74
 
18
75
  ## Setup
19
76
 
@@ -36,8 +93,15 @@ Find the `chat.id` field in the response. For groups, the ID is a negative numbe
36
93
  ### 3. Install the plugin
37
94
 
38
95
  ```bash
39
- # From your Paperclip directory
40
- pnpm paperclipai plugin install /path/to/paperclip-plugin-telegram
96
+ npm install paperclip-plugin-telegram
97
+ ```
98
+
99
+ Or register with your Paperclip instance directly:
100
+
101
+ ```bash
102
+ curl -X POST http://127.0.0.1:3100/api/plugins/install \
103
+ -H "Content-Type: application/json" \
104
+ -d '{"packageName":"paperclip-plugin-telegram"}'
41
105
  ```
42
106
 
43
107
  ### 4. Configure
@@ -54,6 +118,15 @@ In your Paperclip instance settings, configure:
54
118
  | `enableInbound` | No | Route Telegram replies to issues (default: true) |
55
119
  | `dailyDigestEnabled` | No | Send daily activity summary |
56
120
  | `topicRouting` | No | Map forum topics to projects |
121
+ | `escalationChatId` | No | Dedicated chat/topic for agent escalations |
122
+ | `escalationTimeoutMs` | No | Timeout before default action fires (default: 900000 / 15 min) |
123
+ | `escalationDefaultAction` | No | Action on timeout: `defer`, `close`, `retry`, `escalate_further` (default: `defer`) |
124
+ | `escalationHoldMessage` | No | Message sent to customer while waiting (default: "Let me check on that - I'll get back to you shortly.") |
125
+ | `briefAgentId` | No | Agent ID for the Brief Agent (Phase 3 media intake) |
126
+ | `briefAgentChatIds` | No | Chat IDs that act as media intake channels for the Brief Agent |
127
+ | `transcriptionApiKeyRef` | No | Secret reference to OpenAI API key for Whisper transcription |
128
+ | `maxSuggestionsPerHourPerCompany` | No | Rate limit for proactive suggestions (default: 10) |
129
+ | `watchDeduplicationWindowMs` | No | Window before same watch+entity can re-fire (default: 86400000 / 24h) |
57
130
 
58
131
  ### 5. Add bot to group (optional)
59
132
 
@@ -90,11 +163,16 @@ When a user replies to a bot notification, the plugin looks up which Paperclip e
90
163
  |---------|---------|-------------|
91
164
  | Push notifications | Yes | Yes |
92
165
  | Receive messages | No | Yes |
93
- | Bot commands | No | /status, /issues, /agents, /approve |
94
- | Inline buttons | No | Approve/reject on approvals |
166
+ | Bot commands | No | /status, /issues, /agents, /approve, /acp, /commands |
167
+ | Inline buttons | No | Approve/reject on approvals + escalations + handoffs |
95
168
  | Reply routing | No | Replies become issue comments |
96
169
  | Topic routing | No | Forum topic = project |
97
170
  | Daily digest | No | Yes |
171
+ | HITL escalation | No | Dedicated channel with suggested replies + timeout |
172
+ | Multi-agent threads | No | Up to 5 agents per thread, @mention routing, handoff, discuss |
173
+ | Media pipeline | No | Voice transcription, Brief Agent intake |
174
+ | Custom commands | No | Importable multi-step workflows |
175
+ | Proactive suggestions | No | Watch conditions with built-in sales templates |
98
176
  | Architecture | Monorepo example | Standalone npm package |
99
177
 
100
178
  ## Development
@@ -111,6 +189,8 @@ MIT
111
189
 
112
190
  ## Credits
113
191
 
114
- This contribution was developed with AI assistance (Claude Code).
192
+ [@MatB57](https://github.com/MatB57) - Escalation channel concept, "Chat OS" vision for turning chat plugins into bidirectional agent command centers, and the HITL suggested-reply flow.
193
+
194
+ [@leeknowsai](https://github.com/leeknowsai) - Worker bootstrap patterns adapted from the Discord plugin.
115
195
 
116
196
  Inspired by [OpenClaw's Telegram integration](https://github.com/openclaw/openclaw) (grammY, bidirectional messaging, inline buttons) and adapted for the Paperclip plugin SDK.
package/package.json CHANGED
@@ -1,15 +1,8 @@
1
1
  {
2
2
  "name": "paperclip-plugin-telegram",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/mvanhorn/paperclip-plugin-telegram.git"
10
- },
11
- "keywords": ["paperclip", "plugin", "telegram", "bot", "notifications", "acp"],
12
- "files": ["dist", "README.md"],
13
6
  "paperclipPlugin": {
14
7
  "manifest": "./dist/manifest.js",
15
8
  "worker": "./dist/worker.js"
@@ -21,8 +14,8 @@
21
14
  "test": "vitest run"
22
15
  },
23
16
  "peerDependencies": {
24
- "@paperclipai/plugin-sdk": "^1.0.0",
25
- "@paperclipai/shared": "^0.3.0"
17
+ "@paperclipai/plugin-sdk": ">=2026.0.0",
18
+ "@paperclipai/shared": ">=2026.0.0"
26
19
  },
27
20
  "devDependencies": {
28
21
  "@paperclipai/plugin-sdk": "^2026.318.0",