Deploying Hermes Agent: 9Router + Telegram on One VM


The idea is simple: a Telegram bot as the chat interface, 9Router as a gateway that can swap AI models. Between them sits a small bridge translating Telegram updates into 9Router requests, and back.
The architecture has three layers: Telegram bot (long polling for messages) → bridge (Node.js, mapping chats to requests) → 9Router (forwarding to the chosen AI model). The bridge keeps history per chat ID so conversation context never mixes between users.
// message flow, simplified
telegram.on('message', async (msg) => {
const reply = await nineRouter.chat({
model: currentModel(msg.chat.id),
messages: history(msg.chat.id).concat(msg.text),
});
telegram.sendMessage(msg.chat.id, reply);
});Everything runs as systemd services on one VM: one service for 9Router, one for the bridge, one for the bot. Auto-restart makes sure they all come back after a reboot.
One hard lesson: never run 9Router through its interactive launcher under systemd — without a TTY it exits immediately. Run its server file directly with Node and set the working directory correctly.
