MANUAL
Telegram Bot
Introduction
What is the Telegram Channel?
The Telegram channel connects a Telegram bot with Fararoni, allowing users to interact with your AI assistant through the Telegram application.
Architecture
+----------------+ +-----------------+ +----------------+ +----------------+
| User | --> | Telegram API | --> | Sidecar TG | --> | Fararoni |
| Telegram | | (Bot Father) | | (:3001) | | Gateway |
+----------------+ +-----------------+ +----------------+ | (:7071) |
+----------------+
|
v
+----------------+
| LLM Agents |
+----------------+Telegram Advantages
| Feature | Value |
|---|---|
| Cost | FREE (no limits) |
| API | Official and stable |
| Ban risk | None |
| Encryption | End-to-end |
| Speed | Very fast |
| Setup | 5 minutes |
WhatsApp Comparison
| Aspect | Telegram | WhatsApp Baileys | WhatsApp Enterprise |
|---|---|---|---|
| Cost | Free | Free | Pay per message |
| Ban risk | No | Yes | No |
| API | Official | Unofficial | Official |
| Setup | 5 min | 15 min | 2-5 days |
| Users | 900M+ | 2B+ | 2B+ |
Prerequisites
Required Software
- Node.js 18 or higher
- npm (comes with Node.js)
- Fararoni Core installed
- Java 25+ with --enable-preview
Accounts
- Telegram account (on your phone or desktop)
Ports
| Port | Service | Required State |
|---|---|---|
| 7071 | Gateway REST | Open (local) |
| 3001 | Sidecar Telegram | Open (local) |
# Verify Node.js (must be 18+)
node --version
# Verify npm
npm --version
# Verify Java
java --versionChannel Encryption (Encryption Key)
Bot tokens are stored encrypted in the local database.
| Scenario | Key env var | DEV_MODE | Result |
|---|---|---|---|
| Production with key | "abc123..." | false | Uses env key |
| Production without key | (empty) | false | LOG.severe warns, no encryption |
| Development without key | (empty) | true | Auto-generates persistent AES-256 key |
# Production
export FARARONI_CHANNELS_ENCRYPTION_KEY="$(openssl rand -base64 32)"
# Local development (no extra config needed)
export FARARONI_DEV_MODE=trueCreate Bot on Telegram
Step 3.1: Open BotFather
- Open Telegram on your phone or desktop
- Search for @BotFather
- Select the user with the blue verification badge
- Start a conversation (click "Start")
Step 3.2: Create New Bot
Send the command: /newbot
BotFather will ask for the display name (e.g.: Fararoni Assistant) and then the username (e.g.: my_assistant_bot).
IMPORTANT: The username MUST end in bot and must be unique across Telegram.Step 3.3: Get the Token
BotFather will give you a message with your token:
Use this token to access the HTTP API:
1234567890:ABCdefGHIjklMNOpqrSTUvwxYZCOPY AND SAVE THIS TOKEN — You'll need it to start the Sidecar.
IMPORTANT: The token is secret. NEVER share it publicly or push it to git.
Recover Existing Token
Send /mybots to @BotFather, select your bot and click API Token.
Regenerate Compromised Token
Send /revoke to @BotFather, select your bot. The previous one will stop working immediately.
Install the Sidecar
cd /path/to/fararoni/fararoni-sidecar-tg
npm installThis will install: telegraf, express, axios, dotenv
Configure Fararoni
Verify modules.yml
Location: ~/.fararoni/config/modules.yml
channels:
telegram:
enabled: true
trust_level: SECURE_ENCRYPTED
egress_url: "http://localhost:3001/send"
capabilities:
- text
timeout_ms: 5000
retry_count: 3Verify REST Gateway
gateway:
rest:
enabled: true
port: 7071Getting Started
Quick Summary
Terminal 1: java --enable-preview -jar fararoni-core-1.0.0.jar --server
Terminal 2: export TELEGRAM_TOKEN="your_token" && npm start
Telegram: Search your bot and send a messageStart Order (IMPORTANT)
1. Fararoni Core (Gateway) <-- FIRST (port 7071)
2. Sidecar Telegram <-- SECOND (port 3001)Terminal 1: Start Fararoni Core
cd fararoni-core/target
java --enable-preview -jar fararoni-core-1.0.0.jar --serverWait until you see:
[MODULE-REGISTRY] Loaded module: OmniChannelGatewayModule
[INGRESS] RestIngressServer listening on port 7071
[READY] Fararoni Core readyTerminal 2: Start Telegram Sidecar
cd fararoni-sidecar-tg
export TELEGRAM_TOKEN="1234567890:ABCdefGHIjklMNOpqrSTUvwxYZ"
npm startWait until you see:
[INFO] [HTTP] Egress Server on port 3001
[INFO] [TELEGRAM] Bot connected: @your_bot_username
[INFO] [READY] Sidecar ready to receive messagesAlternative: Use .env File
cd fararoni-sidecar-tg
cp .env.example .env
nano .envTELEGRAM_TOKEN=1234567890:ABCdefGHIjklMNOpqrSTUvwxYZ
SIDECAR_PORT=3001
GATEWAY_URL=http://localhost:7071/gateway/v1/inbound
DEBUG=falseVerify Operation
Gateway Health Check
curl http://localhost:7071/gateway/v1/health
# {"status": "healthy", "module": "gateway-rest-omnichannel"}Sidecar Health Check
curl http://localhost:3001/health{
"status": "healthy",
"service": "fararoni-sidecar-tg",
"channel": "telegram",
"port": 3001,
"bot": {
"id": 1234567890,
"username": "your_bot_username"
}
}End-to-End Test
- Open Telegram
- Search your bot:
@your_bot_username - Start conversation (click "Start" or send
/start) - Send:
Hello, what can you do? - You should receive a response from the Fararoni assistant
Verify Logs
[INFO] [INGRESS] 123456789 -> "Hello, what can you do?" (HTTP 202)
[INFO] [EGRESS] 123456789 <- "Hello! I'm Fararoni, your assistant..."Security
Group Filter
By default, the sidecar ONLY responds to private chats (1:1).
| Chat Type | Processed? |
|---|---|
| Private (1:1) | YES |
| Group | NO |
| Supergroup | NO |
| Channel | NO |
Enable Specific Groups
const ALLOWED_GROUPS = ['-123456789', '-987654321'];
if (chat.type !== 'private' && !ALLOWED_GROUPS.includes(chat.id.toString())) {
return;
}Protect the Token
- NEVER push the token to git
- Use environment variables or
.envfile - The
.envfile should be in.gitignore
Access Control
Option A: Public Bot — Anyone can chat (default behavior).
Option B: Restrict Users — Get your User ID with @userinfobot and configure:
const ALLOWED_USERS = [
'123456789',
'987654321',
];
if (ALLOWED_USERS.length > 0 && !ALLOWED_USERS.includes(senderId.toString())) {
return;
}Troubleshooting
Bot doesn't respond
# Verify Gateway
curl http://localhost:7071/gateway/v1/health
# Verify Sidecar
curl http://localhost:3001/healthIf you see 401 Unauthorized in logs, the token is invalid. Regenerate with /token in @BotFather.
Error "ECONNREFUSED"
Cause: Gateway not running.
java --enable-preview -jar fararoni-core-1.0.0.jar --serverError "409 Conflict"
Cause: Another process is using the same bot. Close any other sidecar instance.
Bot responds in groups
Verify index.js has the filter:
if (chat.type !== 'private') {
return;
}Useful Commands
# Gateway health
curl http://localhost:7071/gateway/v1/health
# Sidecar health
curl http://localhost:3001/health
# Detailed status
curl http://localhost:3001/status
# Real-time logs
tail -f ~/.fararoni/logs/fararoni.log | grep -E "(OmniChannel|TELEGRAM)"
# Stop services
pkill -f "fararoni-core"
pkill -f "fararoni-sidecar-tg"BotFather Commands
/token - View current token
/setname - Change bot name
/setdescription - Change description
/revoke - Regenerate tokenAppendices
Implementation Checklist
REQUIREMENTS
[ ] Node.js 18+ installed
[ ] Fararoni Core installed
[ ] Java 25+ with --enable-preview
TELEGRAM
[ ] Bot created in @BotFather
[ ] Token saved securely
INSTALLATION
[ ] npm install executed
[ ] .env created with TELEGRAM_TOKEN
[ ] modules.yml has telegram.enabled: true
GETTING STARTED
[ ] Gateway running on port 7071
[ ] Sidecar running on port 3001
[ ] Health checks OK
TESTING
[ ] Message sent from Telegram
[ ] Response received from assistantAdvanced Configuration
# Change sidecar port
export SIDECAR_PORT=3002
npm startUpdate modules.yml:
channels:
telegram:
egress_url: "http://localhost:3002/send"Multiple Bots
channels:
telegram_sales:
enabled: true
egress_url: "http://localhost:3001/send"
telegram_support:
enabled: true
egress_url: "http://localhost:3002/send"Author: Fararoni Team | Version: 1.0