@rozek/nanoclaw 1.2.17
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/.claude/settings.json +1 -0
- package/.claude/skills/add-compact/SKILL.md +135 -0
- package/.claude/skills/add-discord/SKILL.md +203 -0
- package/.claude/skills/add-gmail/SKILL.md +220 -0
- package/.claude/skills/add-image-vision/SKILL.md +94 -0
- package/.claude/skills/add-ollama-tool/SKILL.md +153 -0
- package/.claude/skills/add-parallel/SKILL.md +290 -0
- package/.claude/skills/add-pdf-reader/SKILL.md +104 -0
- package/.claude/skills/add-reactions/SKILL.md +117 -0
- package/.claude/skills/add-slack/SKILL.md +207 -0
- package/.claude/skills/add-telegram/SKILL.md +222 -0
- package/.claude/skills/add-telegram-swarm/SKILL.md +384 -0
- package/.claude/skills/add-voice-transcription/SKILL.md +148 -0
- package/.claude/skills/add-whatsapp/SKILL.md +372 -0
- package/.claude/skills/convert-to-apple-container/SKILL.md +175 -0
- package/.claude/skills/customize/SKILL.md +110 -0
- package/.claude/skills/debug/SKILL.md +349 -0
- package/.claude/skills/get-qodo-rules/SKILL.md +122 -0
- package/.claude/skills/get-qodo-rules/references/output-format.md +41 -0
- package/.claude/skills/get-qodo-rules/references/pagination.md +33 -0
- package/.claude/skills/get-qodo-rules/references/repository-scope.md +26 -0
- package/.claude/skills/qodo-pr-resolver/SKILL.md +326 -0
- package/.claude/skills/qodo-pr-resolver/resources/providers.md +329 -0
- package/.claude/skills/setup/SKILL.md +218 -0
- package/.claude/skills/update-nanoclaw/SKILL.md +235 -0
- package/.claude/skills/update-skills/SKILL.md +130 -0
- package/.claude/skills/use-local-whisper/SKILL.md +152 -0
- package/.claude/skills/x-integration/SKILL.md +417 -0
- package/.claude/skills/x-integration/agent.ts +243 -0
- package/.claude/skills/x-integration/host.ts +159 -0
- package/.claude/skills/x-integration/lib/browser.ts +148 -0
- package/.claude/skills/x-integration/lib/config.ts +62 -0
- package/.claude/skills/x-integration/scripts/like.ts +56 -0
- package/.claude/skills/x-integration/scripts/post.ts +66 -0
- package/.claude/skills/x-integration/scripts/quote.ts +80 -0
- package/.claude/skills/x-integration/scripts/reply.ts +74 -0
- package/.claude/skills/x-integration/scripts/retweet.ts +62 -0
- package/.claude/skills/x-integration/scripts/setup.ts +87 -0
- package/.env.example +1 -0
- package/.github/CODEOWNERS +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- package/.github/workflows/bump-version.yml +32 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/merge-forward-skills.yml +160 -0
- package/.github/workflows/update-tokens.yml +42 -0
- package/.husky/pre-commit +1 -0
- package/.mcp.json +3 -0
- package/.nvmrc +1 -0
- package/.prettierrc +3 -0
- package/CHANGELOG.md +8 -0
- package/CLAUDE.md +64 -0
- package/CONTRIBUTING.md +23 -0
- package/CONTRIBUTORS.md +15 -0
- package/LICENSE +21 -0
- package/NanoClaw_with_Web-Support.md +290 -0
- package/README.md +261 -0
- package/README_zh.md +200 -0
- package/assets/nanoclaw-favicon.png +0 -0
- package/assets/nanoclaw-icon.png +0 -0
- package/assets/nanoclaw-logo-dark.png +0 -0
- package/assets/nanoclaw-logo.png +0 -0
- package/assets/nanoclaw-profile.jpeg +0 -0
- package/assets/nanoclaw-sales.png +0 -0
- package/assets/social-preview.jpg +0 -0
- package/config-examples/mount-allowlist.json +25 -0
- package/container/Dockerfile +70 -0
- package/container/agent-runner/package-lock.json +1524 -0
- package/container/agent-runner/package.json +21 -0
- package/container/agent-runner/src/index.ts +558 -0
- package/container/agent-runner/src/ipc-mcp-stdio.ts +338 -0
- package/container/agent-runner/tsconfig.json +15 -0
- package/container/build.sh +23 -0
- package/container/skills/agent-browser/SKILL.md +159 -0
- package/container/skills/capabilities/SKILL.md +100 -0
- package/container/skills/status/SKILL.md +104 -0
- package/dist/channels/index.d.ts +2 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +9 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/registry.d.ts +13 -0
- package/dist/channels/registry.d.ts.map +1 -0
- package/dist/channels/registry.js +11 -0
- package/dist/channels/registry.js.map +1 -0
- package/dist/channels/registry.test.d.ts +2 -0
- package/dist/channels/registry.test.d.ts.map +1 -0
- package/dist/channels/registry.test.js +32 -0
- package/dist/channels/registry.test.js.map +1 -0
- package/dist/channels/web.d.ts +2 -0
- package/dist/channels/web.d.ts.map +1 -0
- package/dist/channels/web.js +1738 -0
- package/dist/channels/web.js.map +1 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +182 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +36 -0
- package/dist/config.js.map +1 -0
- package/dist/container-runner.d.ts +44 -0
- package/dist/container-runner.d.ts.map +1 -0
- package/dist/container-runner.js +467 -0
- package/dist/container-runner.js.map +1 -0
- package/dist/container-runner.test.d.ts +2 -0
- package/dist/container-runner.test.d.ts.map +1 -0
- package/dist/container-runner.test.js +150 -0
- package/dist/container-runner.test.js.map +1 -0
- package/dist/container-runtime.d.ts +22 -0
- package/dist/container-runtime.d.ts.map +1 -0
- package/dist/container-runtime.js +96 -0
- package/dist/container-runtime.js.map +1 -0
- package/dist/container-runtime.test.d.ts +2 -0
- package/dist/container-runtime.test.d.ts.map +1 -0
- package/dist/container-runtime.test.js +93 -0
- package/dist/container-runtime.test.js.map +1 -0
- package/dist/credential-proxy.d.ts +21 -0
- package/dist/credential-proxy.d.ts.map +1 -0
- package/dist/credential-proxy.js +95 -0
- package/dist/credential-proxy.js.map +1 -0
- package/dist/credential-proxy.test.d.ts +2 -0
- package/dist/credential-proxy.test.d.ts.map +1 -0
- package/dist/credential-proxy.test.js +134 -0
- package/dist/credential-proxy.test.js.map +1 -0
- package/dist/db.d.ts +115 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +549 -0
- package/dist/db.js.map +1 -0
- package/dist/db.test.d.ts +2 -0
- package/dist/db.test.d.ts.map +1 -0
- package/dist/db.test.js +360 -0
- package/dist/db.test.js.map +1 -0
- package/dist/env.d.ts +8 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +42 -0
- package/dist/env.js.map +1 -0
- package/dist/formatting.test.d.ts +2 -0
- package/dist/formatting.test.d.ts.map +1 -0
- package/dist/formatting.test.js +183 -0
- package/dist/formatting.test.js.map +1 -0
- package/dist/group-folder.d.ts +5 -0
- package/dist/group-folder.d.ts.map +1 -0
- package/dist/group-folder.js +44 -0
- package/dist/group-folder.js.map +1 -0
- package/dist/group-folder.test.d.ts +2 -0
- package/dist/group-folder.test.d.ts.map +1 -0
- package/dist/group-folder.test.js +29 -0
- package/dist/group-folder.test.js.map +1 -0
- package/dist/group-queue.d.ts +34 -0
- package/dist/group-queue.d.ts.map +1 -0
- package/dist/group-queue.js +263 -0
- package/dist/group-queue.js.map +1 -0
- package/dist/group-queue.test.d.ts +2 -0
- package/dist/group-queue.test.d.ts.map +1 -0
- package/dist/group-queue.test.js +341 -0
- package/dist/group-queue.test.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +518 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc-auth.test.d.ts +2 -0
- package/dist/ipc-auth.test.d.ts.map +1 -0
- package/dist/ipc-auth.test.js +434 -0
- package/dist/ipc-auth.test.js.map +1 -0
- package/dist/ipc.d.ts +32 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +311 -0
- package/dist/ipc.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +14 -0
- package/dist/logger.js.map +1 -0
- package/dist/mount-security.d.ts +34 -0
- package/dist/mount-security.d.ts.map +1 -0
- package/dist/mount-security.js +325 -0
- package/dist/mount-security.js.map +1 -0
- package/dist/remote-control.d.ts +32 -0
- package/dist/remote-control.d.ts.map +1 -0
- package/dist/remote-control.js +185 -0
- package/dist/remote-control.js.map +1 -0
- package/dist/remote-control.test.d.ts +2 -0
- package/dist/remote-control.test.d.ts.map +1 -0
- package/dist/remote-control.test.js +321 -0
- package/dist/remote-control.test.js.map +1 -0
- package/dist/router.d.ts +8 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +37 -0
- package/dist/router.js.map +1 -0
- package/dist/routing.test.d.ts +2 -0
- package/dist/routing.test.d.ts.map +1 -0
- package/dist/routing.test.js +81 -0
- package/dist/routing.test.js.map +1 -0
- package/dist/sender-allowlist.d.ts +14 -0
- package/dist/sender-allowlist.d.ts.map +1 -0
- package/dist/sender-allowlist.js +79 -0
- package/dist/sender-allowlist.js.map +1 -0
- package/dist/sender-allowlist.test.d.ts +2 -0
- package/dist/sender-allowlist.test.d.ts.map +1 -0
- package/dist/sender-allowlist.test.js +186 -0
- package/dist/sender-allowlist.test.js.map +1 -0
- package/dist/session-commands.d.ts +47 -0
- package/dist/session-commands.d.ts.map +1 -0
- package/dist/session-commands.js +102 -0
- package/dist/session-commands.js.map +1 -0
- package/dist/session-commands.test.d.ts +2 -0
- package/dist/session-commands.test.d.ts.map +1 -0
- package/dist/session-commands.test.js +190 -0
- package/dist/session-commands.test.js.map +1 -0
- package/dist/task-scheduler.d.ts +22 -0
- package/dist/task-scheduler.d.ts.map +1 -0
- package/dist/task-scheduler.js +210 -0
- package/dist/task-scheduler.js.map +1 -0
- package/dist/task-scheduler.test.d.ts +2 -0
- package/dist/task-scheduler.test.d.ts.map +1 -0
- package/dist/task-scheduler.test.js +107 -0
- package/dist/task-scheduler.test.js.map +1 -0
- package/dist/timezone.d.ts +6 -0
- package/dist/timezone.d.ts.map +1 -0
- package/dist/timezone.js +17 -0
- package/dist/timezone.js.map +1 -0
- package/dist/timezone.test.d.ts +2 -0
- package/dist/timezone.test.d.ts.map +1 -0
- package/dist/timezone.test.js +23 -0
- package/dist/timezone.test.js.map +1 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/APPLE-CONTAINER-NETWORKING.md +90 -0
- package/docs/DEBUG_CHECKLIST.md +143 -0
- package/docs/REQUIREMENTS.md +196 -0
- package/docs/SDK_DEEP_DIVE.md +643 -0
- package/docs/SECURITY.md +122 -0
- package/docs/SPEC.md +785 -0
- package/docs/docker-sandboxes.md +359 -0
- package/docs/nanoclaw-architecture-final.md +1063 -0
- package/docs/nanorepo-architecture.md +168 -0
- package/docs/skills-as-branches.md +662 -0
- package/groups/global/CLAUDE.md +58 -0
- package/groups/main/CLAUDE.md +246 -0
- package/launchd/com.nanoclaw.plist +32 -0
- package/package.json +45 -0
- package/repo-tokens/README.md +113 -0
- package/repo-tokens/action.yml +186 -0
- package/repo-tokens/badge.svg +23 -0
- package/repo-tokens/examples/green.svg +14 -0
- package/repo-tokens/examples/red.svg +14 -0
- package/repo-tokens/examples/yellow-green.svg +14 -0
- package/repo-tokens/examples/yellow.svg +14 -0
- package/scripts/run-migrations.ts +105 -0
- package/setup/container.ts +144 -0
- package/setup/environment.test.ts +121 -0
- package/setup/environment.ts +94 -0
- package/setup/groups.ts +229 -0
- package/setup/index.ts +58 -0
- package/setup/mounts.ts +115 -0
- package/setup/platform.test.ts +120 -0
- package/setup/platform.ts +132 -0
- package/setup/register.test.ts +257 -0
- package/setup/register.ts +177 -0
- package/setup/service.test.ts +187 -0
- package/setup/service.ts +362 -0
- package/setup/status.ts +16 -0
- package/setup/verify.ts +192 -0
- package/setup.sh +161 -0
- package/src/channels/index.ts +12 -0
- package/src/channels/registry.test.ts +42 -0
- package/src/channels/registry.ts +32 -0
- package/src/channels/web.ts +1856 -0
- package/src/cli.ts +209 -0
- package/src/config.ts +73 -0
- package/src/container-runner.test.ts +210 -0
- package/src/container-runner.ts +707 -0
- package/src/container-runtime.test.ts +149 -0
- package/src/container-runtime.ts +127 -0
- package/src/credential-proxy.test.ts +192 -0
- package/src/credential-proxy.ts +125 -0
- package/src/db.test.ts +484 -0
- package/src/db.ts +803 -0
- package/src/env.ts +42 -0
- package/src/formatting.test.ts +256 -0
- package/src/group-folder.test.ts +43 -0
- package/src/group-folder.ts +44 -0
- package/src/group-queue.test.ts +484 -0
- package/src/group-queue.ts +365 -0
- package/src/index.ts +731 -0
- package/src/ipc-auth.test.ts +679 -0
- package/src/ipc.ts +461 -0
- package/src/logger.ts +16 -0
- package/src/mount-security.ts +419 -0
- package/src/remote-control.test.ts +397 -0
- package/src/remote-control.ts +224 -0
- package/src/router.ts +52 -0
- package/src/routing.test.ts +170 -0
- package/src/sender-allowlist.test.ts +216 -0
- package/src/sender-allowlist.ts +128 -0
- package/src/session-commands.test.ts +247 -0
- package/src/session-commands.ts +163 -0
- package/src/task-scheduler.test.ts +129 -0
- package/src/task-scheduler.ts +295 -0
- package/src/timezone.test.ts +29 -0
- package/src/timezone.ts +16 -0
- package/src/types.ts +107 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +7 -0
- package/vitest.skills.config.ts +7 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: add-telegram-swarm
|
|
3
|
+
description: Add Agent Swarm (Teams) support to Telegram. Each subagent gets its own bot identity in the group. Requires Telegram channel to be set up first (use /add-telegram). Triggers on "agent swarm", "agent teams telegram", "telegram swarm", "bot pool".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Add Agent Swarm to Telegram
|
|
7
|
+
|
|
8
|
+
This skill adds Agent Teams (Swarm) support to an existing Telegram channel. Each subagent in a team gets its own bot identity in the Telegram group, so users can visually distinguish which agent is speaking.
|
|
9
|
+
|
|
10
|
+
**Prerequisite**: Telegram must already be set up via the `/add-telegram` skill. If `src/telegram.ts` does not exist or `TELEGRAM_BOT_TOKEN` is not configured, tell the user to run `/add-telegram` first.
|
|
11
|
+
|
|
12
|
+
## How It Works
|
|
13
|
+
|
|
14
|
+
- The **main bot** receives messages and sends lead agent responses (already set up by `/add-telegram`)
|
|
15
|
+
- **Pool bots** are send-only — each gets a Grammy `Api` instance (no polling)
|
|
16
|
+
- When a subagent calls `send_message` with a `sender` parameter, the host assigns a pool bot and renames it to match the sender's role
|
|
17
|
+
- Messages appear in Telegram from different bot identities
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
Subagent calls send_message(text: "Found 3 results", sender: "Researcher")
|
|
21
|
+
→ MCP writes IPC file with sender field
|
|
22
|
+
→ Host IPC watcher picks it up
|
|
23
|
+
→ Assigns pool bot #2 to "Researcher" (round-robin, stable per-group)
|
|
24
|
+
→ Renames pool bot #2 to "Researcher" via setMyName
|
|
25
|
+
→ Sends message via pool bot #2's Api instance
|
|
26
|
+
→ Appears in Telegram from "Researcher" bot
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Prerequisites
|
|
30
|
+
|
|
31
|
+
### 1. Create Pool Bots
|
|
32
|
+
|
|
33
|
+
Tell the user:
|
|
34
|
+
|
|
35
|
+
> I need you to create 3-5 Telegram bots to use as the agent pool. These will be renamed dynamically to match agent roles.
|
|
36
|
+
>
|
|
37
|
+
> 1. Open Telegram and search for `@BotFather`
|
|
38
|
+
> 2. Send `/newbot` for each bot:
|
|
39
|
+
> - Give them any placeholder name (e.g., "Bot 1", "Bot 2")
|
|
40
|
+
> - Usernames like `myproject_swarm_1_bot`, `myproject_swarm_2_bot`, etc.
|
|
41
|
+
> 3. Copy all the tokens
|
|
42
|
+
> 4. Add all bots to your Telegram group(s) where you want agent teams
|
|
43
|
+
|
|
44
|
+
Wait for user to provide the tokens.
|
|
45
|
+
|
|
46
|
+
### 2. Disable Group Privacy for Pool Bots
|
|
47
|
+
|
|
48
|
+
Tell the user:
|
|
49
|
+
|
|
50
|
+
> **Important**: Each pool bot needs Group Privacy disabled so it can send messages in groups.
|
|
51
|
+
>
|
|
52
|
+
> For each pool bot in `@BotFather`:
|
|
53
|
+
> 1. Send `/mybots` and select the bot
|
|
54
|
+
> 2. Go to **Bot Settings** > **Group Privacy** > **Turn off**
|
|
55
|
+
>
|
|
56
|
+
> Then add all pool bots to your Telegram group(s).
|
|
57
|
+
|
|
58
|
+
## Implementation
|
|
59
|
+
|
|
60
|
+
### Step 1: Update Configuration
|
|
61
|
+
|
|
62
|
+
Read `src/config.ts` and add the bot pool config near the other Telegram exports:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
export const TELEGRAM_BOT_POOL = (process.env.TELEGRAM_BOT_POOL || '')
|
|
66
|
+
.split(',')
|
|
67
|
+
.map((t) => t.trim())
|
|
68
|
+
.filter(Boolean);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Step 2: Add Bot Pool to Telegram Module
|
|
72
|
+
|
|
73
|
+
Read `src/telegram.ts` and add the following:
|
|
74
|
+
|
|
75
|
+
1. **Update imports** — add `Api` to the Grammy import:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { Api, Bot } from 'grammy';
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
2. **Add pool state** after the existing `let bot` declaration:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// Bot pool for agent teams: send-only Api instances (no polling)
|
|
85
|
+
const poolApis: Api[] = [];
|
|
86
|
+
// Maps "{groupFolder}:{senderName}" → pool Api index for stable assignment
|
|
87
|
+
const senderBotMap = new Map<string, number>();
|
|
88
|
+
let nextPoolIndex = 0;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
3. **Add pool functions** — place these before the `isTelegramConnected` function:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
/**
|
|
95
|
+
* Initialize send-only Api instances for the bot pool.
|
|
96
|
+
* Each pool bot can send messages but doesn't poll for updates.
|
|
97
|
+
*/
|
|
98
|
+
export async function initBotPool(tokens: string[]): Promise<void> {
|
|
99
|
+
for (const token of tokens) {
|
|
100
|
+
try {
|
|
101
|
+
const api = new Api(token);
|
|
102
|
+
const me = await api.getMe();
|
|
103
|
+
poolApis.push(api);
|
|
104
|
+
logger.info(
|
|
105
|
+
{ username: me.username, id: me.id, poolSize: poolApis.length },
|
|
106
|
+
'Pool bot initialized',
|
|
107
|
+
);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
logger.error({ err }, 'Failed to initialize pool bot');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (poolApis.length > 0) {
|
|
113
|
+
logger.info({ count: poolApis.length }, 'Telegram bot pool ready');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Send a message via a pool bot assigned to the given sender name.
|
|
119
|
+
* Assigns bots round-robin on first use; subsequent messages from the
|
|
120
|
+
* same sender in the same group always use the same bot.
|
|
121
|
+
* On first assignment, renames the bot to match the sender's role.
|
|
122
|
+
*/
|
|
123
|
+
export async function sendPoolMessage(
|
|
124
|
+
chatId: string,
|
|
125
|
+
text: string,
|
|
126
|
+
sender: string,
|
|
127
|
+
groupFolder: string,
|
|
128
|
+
): Promise<void> {
|
|
129
|
+
if (poolApis.length === 0) {
|
|
130
|
+
// No pool bots — fall back to main bot
|
|
131
|
+
await sendTelegramMessage(chatId, text);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const key = `${groupFolder}:${sender}`;
|
|
136
|
+
let idx = senderBotMap.get(key);
|
|
137
|
+
if (idx === undefined) {
|
|
138
|
+
idx = nextPoolIndex % poolApis.length;
|
|
139
|
+
nextPoolIndex++;
|
|
140
|
+
senderBotMap.set(key, idx);
|
|
141
|
+
// Rename the bot to match the sender's role, then wait for Telegram to propagate
|
|
142
|
+
try {
|
|
143
|
+
await poolApis[idx].setMyName(sender);
|
|
144
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
145
|
+
logger.info({ sender, groupFolder, poolIndex: idx }, 'Assigned and renamed pool bot');
|
|
146
|
+
} catch (err) {
|
|
147
|
+
logger.warn({ sender, err }, 'Failed to rename pool bot (sending anyway)');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const api = poolApis[idx];
|
|
152
|
+
try {
|
|
153
|
+
const numericId = chatId.replace(/^tg:/, '');
|
|
154
|
+
const MAX_LENGTH = 4096;
|
|
155
|
+
if (text.length <= MAX_LENGTH) {
|
|
156
|
+
await api.sendMessage(numericId, text);
|
|
157
|
+
} else {
|
|
158
|
+
for (let i = 0; i < text.length; i += MAX_LENGTH) {
|
|
159
|
+
await api.sendMessage(numericId, text.slice(i, i + MAX_LENGTH));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
logger.info({ chatId, sender, poolIndex: idx, length: text.length }, 'Pool message sent');
|
|
163
|
+
} catch (err) {
|
|
164
|
+
logger.error({ chatId, sender, err }, 'Failed to send pool message');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Step 3: Add sender Parameter to MCP Tool
|
|
170
|
+
|
|
171
|
+
Read `container/agent-runner/src/ipc-mcp-stdio.ts` and update the `send_message` tool to accept an optional `sender` parameter:
|
|
172
|
+
|
|
173
|
+
Change the tool's schema from:
|
|
174
|
+
```typescript
|
|
175
|
+
{ text: z.string().describe('The message text to send') },
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
To:
|
|
179
|
+
```typescript
|
|
180
|
+
{
|
|
181
|
+
text: z.string().describe('The message text to send'),
|
|
182
|
+
sender: z.string().optional().describe('Your role/identity name (e.g. "Researcher"). When set, messages appear from a dedicated bot in Telegram.'),
|
|
183
|
+
},
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
And update the handler to include `sender` in the IPC data:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
async (args) => {
|
|
190
|
+
const data: Record<string, string | undefined> = {
|
|
191
|
+
type: 'message',
|
|
192
|
+
chatJid,
|
|
193
|
+
text: args.text,
|
|
194
|
+
sender: args.sender || undefined,
|
|
195
|
+
groupFolder,
|
|
196
|
+
timestamp: new Date().toISOString(),
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
writeIpcFile(MESSAGES_DIR, data);
|
|
200
|
+
|
|
201
|
+
return { content: [{ type: 'text' as const, text: 'Message sent.' }] };
|
|
202
|
+
},
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Step 4: Update Host IPC Routing
|
|
206
|
+
|
|
207
|
+
Read `src/ipc.ts` and make these changes:
|
|
208
|
+
|
|
209
|
+
1. **Add imports** — add `sendPoolMessage` and `initBotPool` from the Telegram swarm module, and `TELEGRAM_BOT_POOL` from config.
|
|
210
|
+
|
|
211
|
+
2. **Update IPC message routing** — in `src/ipc.ts`, find where the `sendMessage` dependency is called to deliver IPC messages (inside `processIpcFiles`). The `sendMessage` is passed in via the `IpcDeps` parameter. Wrap it to route Telegram swarm messages through the bot pool:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
if (data.sender && data.chatJid.startsWith('tg:')) {
|
|
215
|
+
await sendPoolMessage(
|
|
216
|
+
data.chatJid,
|
|
217
|
+
data.text,
|
|
218
|
+
data.sender,
|
|
219
|
+
sourceGroup,
|
|
220
|
+
);
|
|
221
|
+
} else {
|
|
222
|
+
await deps.sendMessage(data.chatJid, data.text);
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Note: The assistant name prefix is handled by `formatOutbound()` in the router — Telegram channels have `prefixAssistantName = false` so no prefix is added for `tg:` JIDs.
|
|
227
|
+
|
|
228
|
+
3. **Initialize pool in `main()` in `src/index.ts`** — after creating the Telegram channel, add:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
if (TELEGRAM_BOT_POOL.length > 0) {
|
|
232
|
+
await initBotPool(TELEGRAM_BOT_POOL);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Step 5: Update CLAUDE.md Files
|
|
237
|
+
|
|
238
|
+
#### 5a. Add global message formatting rules
|
|
239
|
+
|
|
240
|
+
Read `groups/global/CLAUDE.md` and add a Message Formatting section:
|
|
241
|
+
|
|
242
|
+
```markdown
|
|
243
|
+
## Message Formatting
|
|
244
|
+
|
|
245
|
+
NEVER use markdown. Only use WhatsApp/Telegram formatting:
|
|
246
|
+
- *single asterisks* for bold (NEVER **double asterisks**)
|
|
247
|
+
- _underscores_ for italic
|
|
248
|
+
- • bullet points
|
|
249
|
+
- ```triple backticks``` for code
|
|
250
|
+
|
|
251
|
+
No ## headings. No [links](url). No **double stars**.
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### 5b. Update existing group CLAUDE.md headings
|
|
255
|
+
|
|
256
|
+
In any group CLAUDE.md that has a "WhatsApp Formatting" section (e.g. `groups/main/CLAUDE.md`), rename the heading to reflect multi-channel support:
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
## WhatsApp Formatting (and other messaging apps)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### 5c. Add Agent Teams instructions to Telegram groups
|
|
263
|
+
|
|
264
|
+
For each Telegram group that will use agent teams, create or update its `groups/{folder}/CLAUDE.md` with these instructions. Read the existing CLAUDE.md first (or `groups/global/CLAUDE.md` as a base) and add the Agent Teams section:
|
|
265
|
+
|
|
266
|
+
```markdown
|
|
267
|
+
## Agent Teams
|
|
268
|
+
|
|
269
|
+
When creating a team to tackle a complex task, follow these rules:
|
|
270
|
+
|
|
271
|
+
### CRITICAL: Follow the user's prompt exactly
|
|
272
|
+
|
|
273
|
+
Create *exactly* the team the user asked for — same number of agents, same roles, same names. Do NOT add extra agents, rename roles, or use generic names like "Researcher 1". If the user says "a marine biologist, a physicist, and Alexander Hamilton", create exactly those three agents with those exact names.
|
|
274
|
+
|
|
275
|
+
### Team member instructions
|
|
276
|
+
|
|
277
|
+
Each team member MUST be instructed to:
|
|
278
|
+
|
|
279
|
+
1. *Share progress in the group* via `mcp__nanoclaw__send_message` with a `sender` parameter matching their exact role/character name (e.g., `sender: "Marine Biologist"` or `sender: "Alexander Hamilton"`). This makes their messages appear from a dedicated bot in the Telegram group.
|
|
280
|
+
2. *Also communicate with teammates* via `SendMessage` as normal for coordination.
|
|
281
|
+
3. Keep group messages *short* — 2-4 sentences max per message. Break longer content into multiple `send_message` calls. No walls of text.
|
|
282
|
+
4. Use the `sender` parameter consistently — always the same name so the bot identity stays stable.
|
|
283
|
+
5. NEVER use markdown formatting. Use ONLY WhatsApp/Telegram formatting: single *asterisks* for bold (NOT **double**), _underscores_ for italic, • for bullets, ```backticks``` for code. No ## headings, no [links](url), no **double asterisks**.
|
|
284
|
+
|
|
285
|
+
### Example team creation prompt
|
|
286
|
+
|
|
287
|
+
When creating a teammate, include instructions like:
|
|
288
|
+
|
|
289
|
+
\```
|
|
290
|
+
You are the Marine Biologist. When you have findings or updates for the user, send them to the group using mcp__nanoclaw__send_message with sender set to "Marine Biologist". Keep each message short (2-4 sentences max). Use emojis for strong reactions. ONLY use single *asterisks* for bold (never **double**), _underscores_ for italic, • for bullets. No markdown. Also communicate with teammates via SendMessage.
|
|
291
|
+
\```
|
|
292
|
+
|
|
293
|
+
### Lead agent behavior
|
|
294
|
+
|
|
295
|
+
As the lead agent who created the team:
|
|
296
|
+
|
|
297
|
+
- You do NOT need to react to or relay every teammate message. The user sees those directly from the teammate bots.
|
|
298
|
+
- Send your own messages only to comment, share thoughts, synthesize, or direct the team.
|
|
299
|
+
- When processing an internal update from a teammate that doesn't need a user-facing response, wrap your *entire* output in `<internal>` tags.
|
|
300
|
+
- Focus on high-level coordination and the final synthesis.
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Step 6: Update Environment
|
|
304
|
+
|
|
305
|
+
Add pool tokens to `.env`:
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
TELEGRAM_BOT_POOL=TOKEN1,TOKEN2,TOKEN3,...
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**Important**: Sync to all required locations:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
cp .env data/env/env
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Also add `TELEGRAM_BOT_POOL` to the launchd plist (`~/Library/LaunchAgents/com.nanoclaw.plist`) in the `EnvironmentVariables` dict if using launchd.
|
|
318
|
+
|
|
319
|
+
### Step 7: Rebuild and Restart
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
npm run build
|
|
323
|
+
./container/build.sh # Required — MCP tool changed
|
|
324
|
+
# macOS:
|
|
325
|
+
launchctl unload ~/Library/LaunchAgents/com.nanoclaw.plist
|
|
326
|
+
launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist
|
|
327
|
+
# Linux:
|
|
328
|
+
# systemctl --user restart nanoclaw
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Must use `unload/load` (macOS) or `restart` (Linux) because the service env vars changed.
|
|
332
|
+
|
|
333
|
+
### Step 8: Test
|
|
334
|
+
|
|
335
|
+
Tell the user:
|
|
336
|
+
|
|
337
|
+
> Send a message in your Telegram group asking for a multi-agent task, e.g.:
|
|
338
|
+
> "Assemble a team of a researcher and a coder to build me a hello world app"
|
|
339
|
+
>
|
|
340
|
+
> You should see:
|
|
341
|
+
> - The lead agent (main bot) acknowledging and creating the team
|
|
342
|
+
> - Each subagent messaging from a different bot, renamed to their role
|
|
343
|
+
> - Short, scannable messages from each agent
|
|
344
|
+
>
|
|
345
|
+
> Check logs: `tail -f logs/nanoclaw.log | grep -i pool`
|
|
346
|
+
|
|
347
|
+
## Architecture Notes
|
|
348
|
+
|
|
349
|
+
- Pool bots use Grammy's `Api` class — lightweight, no polling, just send
|
|
350
|
+
- Bot names are set via `setMyName` — changes are global to the bot, not per-chat
|
|
351
|
+
- A 2-second delay after `setMyName` allows Telegram to propagate the name change before the first message
|
|
352
|
+
- Sender→bot mapping is stable within a group (keyed as `{groupFolder}:{senderName}`)
|
|
353
|
+
- Mapping resets on service restart — pool bots get reassigned fresh
|
|
354
|
+
- If pool runs out, bots are reused (round-robin wraps)
|
|
355
|
+
|
|
356
|
+
## Troubleshooting
|
|
357
|
+
|
|
358
|
+
### Pool bots not sending messages
|
|
359
|
+
|
|
360
|
+
1. Verify tokens: `curl -s "https://api.telegram.org/botTOKEN/getMe"`
|
|
361
|
+
2. Check pool initialized: `grep "Pool bot" logs/nanoclaw.log`
|
|
362
|
+
3. Ensure all pool bots are members of the Telegram group
|
|
363
|
+
4. Check Group Privacy is disabled for each pool bot
|
|
364
|
+
|
|
365
|
+
### Bot names not updating
|
|
366
|
+
|
|
367
|
+
Telegram caches bot names client-side. The 2-second delay after `setMyName` helps, but users may need to restart their Telegram client to see updated names immediately.
|
|
368
|
+
|
|
369
|
+
### Subagents not using send_message
|
|
370
|
+
|
|
371
|
+
Check the group's `CLAUDE.md` has the Agent Teams instructions. The lead agent reads this when creating teammates and must include the `send_message` + `sender` instructions in each teammate's prompt.
|
|
372
|
+
|
|
373
|
+
## Removal
|
|
374
|
+
|
|
375
|
+
To remove Agent Swarm support while keeping basic Telegram:
|
|
376
|
+
|
|
377
|
+
1. Remove `TELEGRAM_BOT_POOL` from `src/config.ts`
|
|
378
|
+
2. Remove pool code from `src/telegram.ts` (`poolApis`, `senderBotMap`, `initBotPool`, `sendPoolMessage`)
|
|
379
|
+
3. Remove pool routing from IPC handler in `src/index.ts` (revert to plain `sendMessage`)
|
|
380
|
+
4. Remove `initBotPool` call from `main()`
|
|
381
|
+
5. Remove `sender` param from MCP tool in `container/agent-runner/src/ipc-mcp-stdio.ts`
|
|
382
|
+
6. Remove Agent Teams section from group CLAUDE.md files
|
|
383
|
+
7. Remove `TELEGRAM_BOT_POOL` from `.env`, `data/env/env`, and launchd plist/systemd unit
|
|
384
|
+
8. Rebuild: `npm run build && ./container/build.sh && launchctl unload ~/Library/LaunchAgents/com.nanoclaw.plist && launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist` (macOS) or `npm run build && ./container/build.sh && systemctl --user restart nanoclaw` (Linux)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: add-voice-transcription
|
|
3
|
+
description: Add voice message transcription to NanoClaw using OpenAI's Whisper API. Automatically transcribes WhatsApp voice notes so the agent can read and respond to them.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Add Voice Transcription
|
|
7
|
+
|
|
8
|
+
This skill adds automatic voice message transcription to NanoClaw's WhatsApp channel using OpenAI's Whisper API. When a voice note arrives, it is downloaded, transcribed, and delivered to the agent as `[Voice: <transcript>]`.
|
|
9
|
+
|
|
10
|
+
## Phase 1: Pre-flight
|
|
11
|
+
|
|
12
|
+
### Check if already applied
|
|
13
|
+
|
|
14
|
+
Check if `src/transcription.ts` exists. If it does, skip to Phase 3 (Configure). The code changes are already in place.
|
|
15
|
+
|
|
16
|
+
### Ask the user
|
|
17
|
+
|
|
18
|
+
Use `AskUserQuestion` to collect information:
|
|
19
|
+
|
|
20
|
+
AskUserQuestion: Do you have an OpenAI API key for Whisper transcription?
|
|
21
|
+
|
|
22
|
+
If yes, collect it now. If no, direct them to create one at https://platform.openai.com/api-keys.
|
|
23
|
+
|
|
24
|
+
## Phase 2: Apply Code Changes
|
|
25
|
+
|
|
26
|
+
**Prerequisite:** WhatsApp must be installed first (`skill/whatsapp` merged). This skill modifies WhatsApp channel files.
|
|
27
|
+
|
|
28
|
+
### Ensure WhatsApp fork remote
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git remote -v
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If `whatsapp` is missing, add it:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git remote add whatsapp https://github.com/qwibitai/nanoclaw-whatsapp.git
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Merge the skill branch
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git fetch whatsapp skill/voice-transcription
|
|
44
|
+
git merge whatsapp/skill/voice-transcription || {
|
|
45
|
+
git checkout --theirs package-lock.json
|
|
46
|
+
git add package-lock.json
|
|
47
|
+
git merge --continue
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This merges in:
|
|
52
|
+
- `src/transcription.ts` (voice transcription module using OpenAI Whisper)
|
|
53
|
+
- Voice handling in `src/channels/whatsapp.ts` (isVoiceMessage check, transcribeAudioMessage call)
|
|
54
|
+
- Transcription tests in `src/channels/whatsapp.test.ts`
|
|
55
|
+
- `openai` npm dependency in `package.json`
|
|
56
|
+
- `OPENAI_API_KEY` in `.env.example`
|
|
57
|
+
|
|
58
|
+
If the merge reports conflicts, resolve them by reading the conflicted files and understanding the intent of both sides.
|
|
59
|
+
|
|
60
|
+
### Validate code changes
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install --legacy-peer-deps
|
|
64
|
+
npm run build
|
|
65
|
+
npx vitest run src/channels/whatsapp.test.ts
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
All tests must pass and build must be clean before proceeding.
|
|
69
|
+
|
|
70
|
+
## Phase 3: Configure
|
|
71
|
+
|
|
72
|
+
### Get OpenAI API key (if needed)
|
|
73
|
+
|
|
74
|
+
If the user doesn't have an API key:
|
|
75
|
+
|
|
76
|
+
> I need you to create an OpenAI API key:
|
|
77
|
+
>
|
|
78
|
+
> 1. Go to https://platform.openai.com/api-keys
|
|
79
|
+
> 2. Click "Create new secret key"
|
|
80
|
+
> 3. Give it a name (e.g., "NanoClaw Transcription")
|
|
81
|
+
> 4. Copy the key (starts with `sk-`)
|
|
82
|
+
>
|
|
83
|
+
> Cost: ~$0.006 per minute of audio (~$0.003 per typical 30-second voice note)
|
|
84
|
+
|
|
85
|
+
Wait for the user to provide the key.
|
|
86
|
+
|
|
87
|
+
### Add to environment
|
|
88
|
+
|
|
89
|
+
Add to `.env`:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
OPENAI_API_KEY=<their-key>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Sync to container environment:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
mkdir -p data/env && cp .env data/env/env
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The container reads environment from `data/env/env`, not `.env` directly.
|
|
102
|
+
|
|
103
|
+
### Build and restart
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run build
|
|
107
|
+
launchctl kickstart -k gui/$(id -u)/com.nanoclaw # macOS
|
|
108
|
+
# Linux: systemctl --user restart nanoclaw
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Phase 4: Verify
|
|
112
|
+
|
|
113
|
+
### Test with a voice note
|
|
114
|
+
|
|
115
|
+
Tell the user:
|
|
116
|
+
|
|
117
|
+
> Send a voice note in any registered WhatsApp chat. The agent should receive it as `[Voice: <transcript>]` and respond to its content.
|
|
118
|
+
|
|
119
|
+
### Check logs if needed
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
tail -f logs/nanoclaw.log | grep -i voice
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Look for:
|
|
126
|
+
- `Transcribed voice message` — successful transcription with character count
|
|
127
|
+
- `OPENAI_API_KEY not set` — key missing from `.env`
|
|
128
|
+
- `OpenAI transcription failed` — API error (check key validity, billing)
|
|
129
|
+
- `Failed to download audio message` — media download issue
|
|
130
|
+
|
|
131
|
+
## Troubleshooting
|
|
132
|
+
|
|
133
|
+
### Voice notes show "[Voice Message - transcription unavailable]"
|
|
134
|
+
|
|
135
|
+
1. Check `OPENAI_API_KEY` is set in `.env` AND synced to `data/env/env`
|
|
136
|
+
2. Verify key works: `curl -s https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" | head -c 200`
|
|
137
|
+
3. Check OpenAI billing — Whisper requires a funded account
|
|
138
|
+
|
|
139
|
+
### Voice notes show "[Voice Message - transcription failed]"
|
|
140
|
+
|
|
141
|
+
Check logs for the specific error. Common causes:
|
|
142
|
+
- Network timeout — transient, will work on next message
|
|
143
|
+
- Invalid API key — regenerate at https://platform.openai.com/api-keys
|
|
144
|
+
- Rate limiting — wait and retry
|
|
145
|
+
|
|
146
|
+
### Agent doesn't respond to voice notes
|
|
147
|
+
|
|
148
|
+
Verify the chat is registered and the agent is running. Voice transcription only runs for registered groups.
|