Add register_group IPC command for dynamic group registration

Main agent can now register new groups via MCP tool without restart.
Host updates both in-memory state and JSON file, creates group folders.
Authorization enforced at both agent and host level.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gavriel
2026-02-02 00:08:40 +02:00
parent 05a29d562f
commit 4711ec435a
2 changed files with 75 additions and 0 deletions

View File

@@ -276,6 +276,45 @@ SCHEDULE VALUE FORMAT (all times are LOCAL timezone):
}]
};
}
),
tool(
'register_group',
`Register a new WhatsApp group so the agent can respond to messages there. Main group only.
Use available_groups.json to find the JID for a group. The folder name should be lowercase with hyphens (e.g., "family-chat").`,
{
jid: z.string().describe('The WhatsApp JID (e.g., "120363336345536173@g.us")'),
name: z.string().describe('Display name for the group'),
folder: z.string().describe('Folder name for group files (lowercase, hyphens, e.g., "family-chat")'),
trigger: z.string().describe('Trigger word (e.g., "@Andy")')
},
async (args) => {
if (!isMain) {
return {
content: [{ type: 'text', text: 'Only the main group can register new groups.' }],
isError: true
};
}
const data = {
type: 'register_group',
jid: args.jid,
name: args.name,
folder: args.folder,
trigger: args.trigger,
timestamp: new Date().toISOString()
};
writeIpcFile(TASKS_DIR, data);
return {
content: [{
type: 'text',
text: `Group "${args.name}" registered. It will start receiving messages immediately.`
}]
};
}
)
]
});