@odience-network/paperclip-plugin-telegram-enhanced 0.2.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +215 -0
  3. package/dist/acp-bridge.d.ts +35 -0
  4. package/dist/acp-bridge.js +891 -0
  5. package/dist/acp-bridge.js.map +1 -0
  6. package/dist/adapter.d.ts +35 -0
  7. package/dist/adapter.js +75 -0
  8. package/dist/adapter.js.map +1 -0
  9. package/dist/agent-labels.d.ts +12 -0
  10. package/dist/agent-labels.js +96 -0
  11. package/dist/agent-labels.js.map +1 -0
  12. package/dist/allowlist.d.ts +27 -0
  13. package/dist/allowlist.js +34 -0
  14. package/dist/allowlist.js.map +1 -0
  15. package/dist/approval-routing.d.ts +2 -0
  16. package/dist/approval-routing.js +7 -0
  17. package/dist/approval-routing.js.map +1 -0
  18. package/dist/command-registry.d.ts +3 -0
  19. package/dist/command-registry.js +268 -0
  20. package/dist/command-registry.js.map +1 -0
  21. package/dist/commands.d.ts +11 -0
  22. package/dist/commands.js +516 -0
  23. package/dist/commands.js.map +1 -0
  24. package/dist/constants.d.ts +76 -0
  25. package/dist/constants.js +71 -0
  26. package/dist/constants.js.map +1 -0
  27. package/dist/escalation.d.ts +42 -0
  28. package/dist/escalation.js +252 -0
  29. package/dist/escalation.js.map +1 -0
  30. package/dist/file-routing.d.ts +51 -0
  31. package/dist/file-routing.js +212 -0
  32. package/dist/file-routing.js.map +1 -0
  33. package/dist/formatters.d.ts +31 -0
  34. package/dist/formatters.js +336 -0
  35. package/dist/formatters.js.map +1 -0
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.js +4 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/interaction-delivery.d.ts +90 -0
  40. package/dist/interaction-delivery.js +142 -0
  41. package/dist/interaction-delivery.js.map +1 -0
  42. package/dist/manifest.d.ts +3 -0
  43. package/dist/manifest.js +111 -0
  44. package/dist/manifest.js.map +1 -0
  45. package/dist/media-pipeline.d.ts +47 -0
  46. package/dist/media-pipeline.js +162 -0
  47. package/dist/media-pipeline.js.map +1 -0
  48. package/dist/notification-filters.d.ts +23 -0
  49. package/dist/notification-filters.js +93 -0
  50. package/dist/notification-filters.js.map +1 -0
  51. package/dist/paperclip-api.d.ts +25 -0
  52. package/dist/paperclip-api.js +69 -0
  53. package/dist/paperclip-api.js.map +1 -0
  54. package/dist/polling-offset.d.ts +22 -0
  55. package/dist/polling-offset.js +68 -0
  56. package/dist/polling-offset.js.map +1 -0
  57. package/dist/secret-ref-validation.d.ts +7 -0
  58. package/dist/secret-ref-validation.js +49 -0
  59. package/dist/secret-ref-validation.js.map +1 -0
  60. package/dist/telegram-api.d.ts +40 -0
  61. package/dist/telegram-api.js +251 -0
  62. package/dist/telegram-api.js.map +1 -0
  63. package/dist/topic-projects.d.ts +2 -0
  64. package/dist/topic-projects.js +45 -0
  65. package/dist/topic-projects.js.map +1 -0
  66. package/dist/ui/index.d.ts +2 -0
  67. package/dist/ui/index.js +1446 -0
  68. package/dist/ui/index.js.map +1 -0
  69. package/dist/watch-registry.d.ts +9 -0
  70. package/dist/watch-registry.js +272 -0
  71. package/dist/watch-registry.js.map +1 -0
  72. package/dist/worker.d.ts +162 -0
  73. package/dist/worker.js +1520 -0
  74. package/dist/worker.js.map +1 -0
  75. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matt Van Horn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # Telegram Bot for Paperclip — Notifications, Approvals & Multi-Agent Chat Ops
2
+
3
+ [![npm](https://img.shields.io/npm/v/@odience-network/paperclip-plugin-telegram-enhanced)](https://www.npmjs.com/package/@odience-network/paperclip-plugin-telegram-enhanced)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ > Run your [Paperclip](https://github.com/paperclipai/paperclip) AI agents from Telegram. Get instant notifications, approve requests with one tap, chat with multiple agents in a thread, send voice notes that turn into tasks, and build your own slash commands — all without leaving your chat app.
7
+
8
+ > **Enhanced fork** maintained by [Odience Network](https://github.com/odience-network), derived from [mvanhorn/paperclip-plugin-telegram](https://github.com/mvanhorn/paperclip-plugin-telegram) (MIT) and extended with extra features and upstream fork fixes. Published as [`@odience-network/paperclip-plugin-telegram-enhanced`](https://www.npmjs.com/package/@odience-network/paperclip-plugin-telegram-enhanced).
9
+
10
+ **Telegram + Paperclip in one bidirectional bridge.** This plugin turns a Telegram bot into a command center for your AI agents: push notifications flow *out* to your chats, and commands, replies, approvals, and media flow *back in* to Paperclip.
11
+
12
+ ```text
13
+ Paperclip agents ⇄ Telegram bot ⇄ You
14
+ notifications → 📲 chats → tap to approve, reply, chat
15
+ issues & tools ← 💬 commands ← /status, voice notes, @mentions
16
+ ```
17
+
18
+ ---
19
+
20
+ ## Table of contents
21
+
22
+ - [Features](#features)
23
+ - [Quick start](#quick-start-5-minutes)
24
+ - [Documentation](#documentation)
25
+ - [Configuration at a glance](#configuration-at-a-glance)
26
+ - [Agent tools](#agent-tools)
27
+ - [Compatibility note](#compatibility-note-paperclipai-master)
28
+ - [Why this plugin](#why-this-plugin)
29
+ - [Contributing](#contributing)
30
+ - [Credits](#credits)
31
+ - [License](#license)
32
+
33
+ ---
34
+
35
+ ## Features
36
+
37
+ | | Feature | What you get |
38
+ |---|---|---|
39
+ | 🔔 | **Notifications** | Issue created/done/blocked, board `@`-mentions, approvals, agent errors, and run lifecycle — formatted in MarkdownV2 with a plain-text fallback. |
40
+ | ✅ | **One-tap approvals** | Inline **Approve** / **Reject** buttons on every approval. Act without leaving Telegram. |
41
+ | 💬 | **Bot commands** | `/status`, `/issues`, `/agents`, `/approve`, `/connect`, `/topics`, `/acp`, `/commands`, and more. |
42
+ | ↩️ | **Reply routing** | Reply to any notification and it becomes an issue comment or escalation reply. |
43
+ | 🧵 | **Multi-agent threads** | Up to 5 agents per thread with `@mention` routing, handoff, and discuss loops. |
44
+ | 🆘 | **Human-in-the-loop escalation** | Agents escalate when stuck; you get context, a suggested reply, and action buttons. |
45
+ | 🎙️ | **Media-to-task pipeline** | Voice, audio, video, photos, and documents routed to agents — with Whisper transcription. |
46
+ | 🗂️ | **Forum topic routing** | Map Telegram forum topics to Paperclip projects so updates land in the right place. |
47
+ | 📊 | **Daily digest** | Once, twice, or three times a day: completions, active agents, and open work. |
48
+ | ⚙️ | **Custom workflow commands** | Import multi-step workflows as your own `/slash` commands. |
49
+ | 🤖 | **Proactive suggestions** | Agents register watches (e.g. *overdue invoice*) that fire suggestions when conditions hit. |
50
+
51
+ ➡️ **Full feature reference:** see the [documentation](#documentation) below.
52
+
53
+ ---
54
+
55
+ ## Quick start (5 minutes)
56
+
57
+ **1. Create a Telegram bot**
58
+
59
+ Message [@BotFather](https://t.me/BotFather), run `/newbot`, and copy the bot token.
60
+
61
+ **2. Find your chat ID**
62
+
63
+ Send any message to your new bot, then run:
64
+
65
+ ```bash
66
+ curl "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates"
67
+ ```
68
+
69
+ Copy the `chat.id` from the response.
70
+
71
+ **3. Install the plugin**
72
+
73
+ ```bash
74
+ npm install @odience-network/paperclip-plugin-telegram-enhanced
75
+ ```
76
+
77
+ Or register it with a running Paperclip instance:
78
+
79
+ ```bash
80
+ curl -X POST http://127.0.0.1:3100/api/plugins/install \
81
+ -H "Content-Type: application/json" \
82
+ -d '{"packageName":"@odience-network/paperclip-plugin-telegram-enhanced"}'
83
+ ```
84
+
85
+ **4. Store your bot token as a Paperclip secret**
86
+
87
+ Create a company secret for the token and copy its UUID — you'll reference it instead of pasting the raw token.
88
+
89
+ ```bash
90
+ curl -X POST http://127.0.0.1:3100/api/companies/{companyId}/secrets \
91
+ -H "Content-Type: application/json" \
92
+ -d '{"name":"telegram-bot-token","value":"<your-bot-token>","provider":"local_encrypted"}'
93
+ ```
94
+
95
+ **5. Configure the plugin**
96
+
97
+ Set `telegramBotTokenRef` to the secret UUID and `defaultChatId` to your chat ID. Save, and you'll start receiving notifications.
98
+
99
+ 📘 **Need the detailed walkthrough?** Read the [Getting Started guide](docs/getting-started.md) — it covers the settings UI, board access for approvals, and security allowlists.
100
+
101
+ ---
102
+
103
+ ## Documentation
104
+
105
+ | Guide | What's inside |
106
+ |-------|---------------|
107
+ | **[Getting Started](docs/getting-started.md)** | Step-by-step setup, secrets, board access, and security allowlists. |
108
+ | **[Configuration Reference](docs/configuration.md)** | Every config setting, default, and what it does. |
109
+ | **[Notifications & Routing](docs/notifications.md)** | Notification types, per-type chats, forum topics, and digests. |
110
+ | **[Bot Commands](docs/commands.md)** | Full command reference with examples. |
111
+ | **[Agent Tools](docs/agent-tools.md)** | Escalation, multi-agent threads, handoff/discuss, and watches. |
112
+ | **[Workflow Commands](docs/workflow-commands.md)** | Build and run your own multi-step `/slash` commands. |
113
+ | **[Troubleshooting](docs/troubleshooting.md)** | Common issues, compatibility notes, and fixes. |
114
+
115
+ ---
116
+
117
+ ## Configuration at a glance
118
+
119
+ Only one setting is required to get started:
120
+
121
+ | Setting | Required | Description |
122
+ |---------|----------|-------------|
123
+ | `telegramBotTokenRef` | ✅ Yes | Secret UUID for your bot token. |
124
+ | `defaultChatId` | No | Fallback chat for notifications. |
125
+ | `digestMode` | No | `off`, `daily`, `bidaily`, or `tridaily`. |
126
+ | `enableCommands` | No | Enable bot commands (default: `true`). |
127
+ | `enableInbound` | No | Route Telegram replies back to Paperclip (default: `true`). |
128
+
129
+ See the **[full configuration reference](docs/configuration.md)** for all 30+ settings, including per-type chat routing, escalation timeouts, media intake, and proactive-suggestion limits.
130
+
131
+ ---
132
+
133
+ ## Agent tools
134
+
135
+ Your Paperclip agents can call these tools to drive Telegram interactions:
136
+
137
+ | Tool | Description |
138
+ |------|-------------|
139
+ | `escalate_to_human` | Escalate a conversation to a human when confidence is low. |
140
+ | `handoff_to_agent` | Hand off work to another agent in the thread. |
141
+ | `discuss_with_agent` | Start a back-and-forth conversation with another agent. |
142
+ | `register_watch` | Register a proactive watch that monitors entities and sends suggestions. |
143
+ | `send_to_telegram` | Send text or a Markdown document to a chat, with optional project-key file routing. |
144
+
145
+ Details and parameters are in the **[Agent Tools guide](docs/agent-tools.md)**.
146
+
147
+ ---
148
+
149
+ ## Compatibility note (`paperclipai` master)
150
+
151
+ > **Running `paperclipai` master after [#5429](https://github.com/paperclipai/paperclip/pull/5429) (2026-05-09)?**
152
+ > The new Secrets Manager temporarily disables plugin secret-ref UUIDs while a company-scoped `plugin_config` follow-up lands. Activation fails with `Plugin secret references are disabled until company-scoped plugin config lands`, and `POST /api/plugins/:id/config` returns HTTP 422 for configs containing secret-ref UUIDs (e.g. `telegramBotTokenRef`). This is intentional fail-closed mitigation (PAP-2394). Until the follow-up ships, pin to the last `paperclipai` release before #5429.
153
+
154
+ See [Troubleshooting](docs/troubleshooting.md) for the full background and workaround.
155
+
156
+ ---
157
+
158
+ ## Why this plugin
159
+
160
+ Built on the Paperclip plugin SDK and the domain event bridge ([PR #909](https://github.com/paperclipai/paperclip/pull/909)), this plugin goes well beyond push-only notifications:
161
+
162
+ | Capability | Push-only ([PR #407](https://github.com/paperclipai/paperclip/pull/407)) | This plugin |
163
+ |------------|:--:|:--|
164
+ | Push notifications | ✅ | ✅ |
165
+ | Receive messages | ❌ | ✅ |
166
+ | Bot commands | ❌ | `/status`, `/issues`, `/agents`, `/approve`, `/topics`, `/acp`, `/commands` |
167
+ | Inline buttons | ❌ | Approve/reject on approvals, escalations, handoffs |
168
+ | Reply routing | ❌ | Replies become issue comments |
169
+ | Forum topic routing | ❌ | Topic = project |
170
+ | Daily digest | ❌ | ✅ |
171
+ | HITL escalation | ❌ | Dedicated channel with suggested replies + timeout |
172
+ | Multi-agent threads | ❌ | Up to 5 agents, `@mention` routing, handoff, discuss |
173
+ | Media pipeline | ❌ | Voice transcription, Brief Agent intake |
174
+ | Custom commands | ❌ | Importable multi-step workflows |
175
+ | Proactive suggestions | ❌ | Watch conditions with built-in templates |
176
+ | Packaging | Monorepo example | Standalone npm package |
177
+
178
+ It's the plugin Paperclip users asked for the day the plugin system shipped — *"let me know when it's done"* — and a whole lot more.
179
+
180
+ ---
181
+
182
+ ## Contributing
183
+
184
+ Issues and pull requests are welcome at [github.com/odience-network/paperclip-plugin-telegram-enhanced](https://github.com/odience-network/paperclip-plugin-telegram-enhanced). This is an enhanced fork of [mvanhorn/paperclip-plugin-telegram](https://github.com/mvanhorn/paperclip-plugin-telegram); upstream improvements are integrated with attribution.
185
+
186
+ ```bash
187
+ pnpm install # install dependencies
188
+ pnpm typecheck # type-check
189
+ pnpm test # tests across notifications, approvals, escalation, media, and commands
190
+ pnpm build # compile
191
+ ```
192
+
193
+ ### Releases
194
+
195
+ Publishing to npm is **release-gated**, not push-gated. The [`Publish to npm`](.github/workflows/publish.yml) workflow runs only when a GitHub Release is published (or via manual `workflow_dispatch`), and no-ops unless the `NPM_TOKEN` secret is configured. To cut a release:
196
+
197
+ 1. Bump `version` in `package.json` (and `PLUGIN_VERSION` in `src/constants.ts`).
198
+ 2. Merge to `main`.
199
+ 3. Publish a GitHub Release tagged `vX.Y.Z`.
200
+
201
+ The workflow skips automatically if the version is already on npm.
202
+
203
+ ---
204
+
205
+ ## Credits
206
+
207
+ - [@MatB57](https://github.com/MatB57) — escalation channel concept, the "Chat OS" vision for bidirectional agent command centers, and the HITL suggested-reply flow.
208
+ - [@leeknowsai](https://github.com/leeknowsai) — worker bootstrap patterns adapted from the Discord plugin.
209
+ - Inspired by [OpenClaw's Telegram integration](https://github.com/openclaw/openclaw) (grammY, bidirectional messaging, inline buttons), adapted for the Paperclip plugin SDK.
210
+
211
+ ---
212
+
213
+ ## License
214
+
215
+ [MIT](LICENSE)
@@ -0,0 +1,35 @@
1
+ import type { PluginContext } from "@paperclipai/plugin-sdk";
2
+ export type ChatSession = {
3
+ sessionId: string;
4
+ agentId: string;
5
+ agentName: string;
6
+ agentDisplayName: string;
7
+ transport: "native" | "acp";
8
+ spawnedAt: string;
9
+ status: "active" | "closed";
10
+ lastActivityAt: string;
11
+ };
12
+ type AcpOutputEvent = {
13
+ sessionId: string;
14
+ chatId: string;
15
+ threadId: number;
16
+ text: string;
17
+ done?: boolean;
18
+ };
19
+ export declare function setupAcpOutputListener(ctx: PluginContext, token: string): void;
20
+ export declare function handleAcpCommand(ctx: PluginContext, token: string, chatId: string, args: string, messageThreadId?: number, companyId?: string, maxAgentsPerThread?: number): Promise<void>;
21
+ export declare function wakeAgentWithIssue(ctx: PluginContext, agentId: string, companyId: string, promptText: string, reason: string, projectId?: string): Promise<string | null>;
22
+ export declare function routeMessageToAgent(ctx: PluginContext, token: string, chatId: string, threadId: number, text: string, replyToMessageId?: number, companyId?: string): Promise<boolean>;
23
+ export declare function handleAcpOutput(ctx: PluginContext, token: string, event: AcpOutputEvent): Promise<void>;
24
+ export declare function handleHandoffToolCall(ctx: PluginContext, token: string, params: Record<string, unknown>, companyId: string, sourceAgentId: string): Promise<{
25
+ content?: string;
26
+ error?: string;
27
+ }>;
28
+ export declare function handleHandoffApproval(ctx: PluginContext, token: string, handoffId: string, actor: string, callbackQueryId: string, chatId: string | null, messageId: number | undefined): Promise<void>;
29
+ export declare function handleHandoffRejection(ctx: PluginContext, token: string, handoffId: string, actor: string, callbackQueryId: string, chatId: string | null, messageId: number | undefined): Promise<void>;
30
+ export declare function handleDiscussToolCall(ctx: PluginContext, token: string, params: Record<string, unknown>, companyId: string, sourceAgentId: string): Promise<{
31
+ content?: string;
32
+ error?: string;
33
+ }>;
34
+ export declare function getSessions(ctx: PluginContext, chatId: string, threadId: number): Promise<ChatSession[]>;
35
+ export {};