paperclip-plugin-telegram 0.2.0 → 0.2.2
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 +68 -4
- package/dist/acp-bridge.d.ts +34 -0
- package/dist/acp-bridge.js +805 -0
- package/dist/acp-bridge.js.map +1 -0
- package/dist/adapter.d.ts +35 -0
- package/dist/adapter.js +75 -0
- package/dist/adapter.js.map +1 -0
- package/dist/command-registry.d.ts +3 -0
- package/dist/command-registry.js +273 -0
- package/dist/command-registry.js.map +1 -0
- package/dist/commands.d.ts +10 -0
- package/dist/commands.js +213 -0
- package/dist/commands.js.map +1 -0
- package/dist/constants.d.ts +44 -0
- package/dist/constants.js +48 -0
- package/dist/constants.js.map +1 -0
- package/dist/escalation.d.ts +41 -0
- package/dist/escalation.js +254 -0
- package/dist/escalation.js.map +1 -0
- package/dist/formatters.d.ts +13 -0
- package/dist/formatters.js +130 -0
- package/dist/formatters.js.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +3 -0
- package/dist/manifest.js +230 -0
- package/dist/manifest.js.map +1 -0
- package/dist/media-pipeline.d.ts +46 -0
- package/dist/media-pipeline.js +161 -0
- package/dist/media-pipeline.js.map +1 -0
- package/dist/telegram-api.d.ts +28 -0
- package/dist/telegram-api.js +147 -0
- package/dist/telegram-api.js.map +1 -0
- package/dist/watch-registry.d.ts +9 -0
- package/dist/watch-registry.js +272 -0
- package/dist/watch-registry.js.map +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +548 -0
- package/dist/worker.js.map +1 -0
- package/package.json +7 -3
- package/src/acp-bridge.ts +0 -1273
- package/src/adapter.ts +0 -129
- package/src/command-registry.ts +0 -482
- package/src/commands.ts +0 -346
- package/src/constants.ts +0 -51
- package/src/escalation.ts +0 -421
- package/src/formatters.ts +0 -148
- package/src/manifest.ts +0 -246
- package/src/media-pipeline.ts +0 -234
- package/src/telegram-api.ts +0 -202
- package/src/watch-registry.ts +0 -369
- package/src/worker.ts +0 -783
- package/tests/acp-bridge.test.ts +0 -314
- package/tests/command-registry.test.ts +0 -283
- package/tests/commands.test.ts +0 -213
- package/tests/escalation.test.ts +0 -550
- package/tests/formatters.test.ts +0 -185
- package/tests/media-pipeline.test.ts +0 -324
- package/tests/telegram-api.test.ts +0 -108
- package/tests/watch-registry.test.ts +0 -404
- package/tsconfig.json +0 -16
- /package/{src/index.ts → dist/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -8,15 +8,69 @@ Built on the Paperclip plugin SDK and the domain event bridge ([PR #909](https:/
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
+
### Core
|
|
12
|
+
|
|
11
13
|
- **Push notifications** on issue created, issue done, approval requested, agent error, run lifecycle
|
|
12
|
-
- **Bot commands**: `/status`, `/issues`, `/agents`, `/approve`, `/help`, `/connect`
|
|
14
|
+
- **Bot commands**: `/status`, `/issues`, `/agents`, `/approve`, `/help`, `/connect`, `/connect-topic`, `/acp`, `/commands`
|
|
13
15
|
- **Inline buttons** for approve/reject on approval notifications
|
|
14
16
|
- **Inbound routing**: reply to a notification in Telegram and it becomes an issue comment in Paperclip
|
|
15
17
|
- **Per-company chat routing** with `/connect` command
|
|
16
18
|
- **Forum topic routing**: map Telegram topics to Paperclip projects
|
|
17
19
|
- **Daily digest**: scheduled summary of agent activity
|
|
18
20
|
- **MarkdownV2 formatting** with automatic plain text fallback
|
|
19
|
-
- **
|
|
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
|
|
20
74
|
|
|
21
75
|
## Setup
|
|
22
76
|
|
|
@@ -68,6 +122,11 @@ In your Paperclip instance settings, configure:
|
|
|
68
122
|
| `escalationTimeoutMs` | No | Timeout before default action fires (default: 900000 / 15 min) |
|
|
69
123
|
| `escalationDefaultAction` | No | Action on timeout: `defer`, `close`, `retry`, `escalate_further` (default: `defer`) |
|
|
70
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) |
|
|
71
130
|
|
|
72
131
|
### 5. Add bot to group (optional)
|
|
73
132
|
|
|
@@ -104,11 +163,16 @@ When a user replies to a bot notification, the plugin looks up which Paperclip e
|
|
|
104
163
|
|---------|---------|-------------|
|
|
105
164
|
| Push notifications | Yes | Yes |
|
|
106
165
|
| Receive messages | No | Yes |
|
|
107
|
-
| Bot commands | No | /status, /issues, /agents, /approve |
|
|
108
|
-
| 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 |
|
|
109
168
|
| Reply routing | No | Replies become issue comments |
|
|
110
169
|
| Topic routing | No | Forum topic = project |
|
|
111
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 |
|
|
112
176
|
| Architecture | Monorepo example | Standalone npm package |
|
|
113
177
|
|
|
114
178
|
## Development
|
|
@@ -0,0 +1,34 @@
|
|
|
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): Promise<void>;
|
|
21
|
+
export declare function routeMessageToAgent(ctx: PluginContext, token: string, chatId: string, threadId: number, text: string, replyToMessageId?: number, companyId?: string): Promise<boolean>;
|
|
22
|
+
export declare function handleAcpOutput(ctx: PluginContext, token: string, event: AcpOutputEvent): Promise<void>;
|
|
23
|
+
export declare function handleHandoffToolCall(ctx: PluginContext, token: string, params: Record<string, unknown>, companyId: string, sourceAgentId: string): Promise<{
|
|
24
|
+
content?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function handleHandoffApproval(ctx: PluginContext, token: string, handoffId: string, actor: string, callbackQueryId: string, chatId: string | null, messageId: number | undefined): Promise<void>;
|
|
28
|
+
export declare function handleHandoffRejection(ctx: PluginContext, token: string, handoffId: string, actor: string, callbackQueryId: string, chatId: string | null, messageId: number | undefined): Promise<void>;
|
|
29
|
+
export declare function handleDiscussToolCall(ctx: PluginContext, token: string, params: Record<string, unknown>, companyId: string, sourceAgentId: string): Promise<{
|
|
30
|
+
content?: string;
|
|
31
|
+
error?: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function getSessions(ctx: PluginContext, chatId: string, threadId: number): Promise<ChatSession[]>;
|
|
34
|
+
export {};
|