The simplest Telegram bot - OpenServ agent integration.
- Receives
/ask [question]
command from Telegram - Creates a task for the specified agent in OpenServ
- Waits for task completion
- Sends the response to the same chat
npm install
cp .env.example .env
Edit the .env
file:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
OPENSERV_API_KEY=your_openserv_api_key_here
WORKSPACE_ID=your_workspace_id_here
AGENT_ID=your_agent_id_here
# Development
npm run dev
# Production
npm run build
npm start
/start
- Start the bot/ask [question]
- Ask a question/help
- Help
/ask What is OpenServ?
/ask What is the BTC price?
/ask How is the weather?
Variable | Description | Required |
---|---|---|
TELEGRAM_BOT_TOKEN |
Telegram bot token | ✅ |
OPENSERV_API_KEY |
OpenServ API key | ✅ |
WORKSPACE_ID |
OpenServ workspace ID | ✅ |
AGENT_ID |
Agent ID to use | ✅ |
You can use any of the available agents on the platform:
- Research Assistant (ID: 2) - Internet research
- General Assistant (ID: 3) - General questions, code analysis
- Essay Writer (ID: 6) - Article writing
- Coder (ID: 39) - Code writing and analysis
- Copywriter (ID: 41) - Content writing
- Perplexity Research Assistant (ID: 140) - Web research
- Audio transcriber (ID: 155) - Audio transcription
To discover additional agents and their IDs:
-
Marketplace Agents: Visit https://platform.openserv.ai/agents and check the network request
https://api.openserv.ai/marketplace/agents?page=...&pageSize=...
that loads when the page opens. -
Your Own Agents: Visit https://platform.openserv.ai/developer/agents and examine the response from the
https://api.openserv.ai/agents?ownerId=...
request to see your created agents. -
Debug by Logging Available Agents: Add a simple capability to your bot to see all available agents in your workspace:
// Add this temporary capability to see available agents
this.addCapability({
name: 'debugAgents',
description: 'Debug: log all available agents',
schema: z.object({}),
async run({ args, action }) {
if (!action?.workspace?.agents) {
console.log('❌ No workspace agents available')
return 'No workspace context available'
}
console.log('🔍 Available Agents in Workspace:')
action.workspace.agents.forEach((agent, index) => {
console.log(`${index + 1}. Name: "${agent.name}" | ID: ${agent.id}`)
console.log(` Capabilities: ${agent.capabilities_description}`)
console.log('---')
})
return `Found ${action.workspace.agents.length} agents. Check console for details.`
}
})
Then use /ask debug agents
to see all available agents in your console output.
class SimpleTelegramBot {
// 1. Receives Telegram message
// 2. Creates task in OpenServ
// 3. Waits for task completion
// 4. Sends result to Telegram
}
setupHandlers()
- Telegram command handlerswaitForTaskCompletion()
- Wait for task completionstart()
- Start the bot
- Check environment variables
- Is the OpenServ API key valid?
- Is the Agent ID correct?
- Agent might be too busy
- Try a different agent
- Is the Workspace ID correct?
- Check bot token
- Is there an internet connection?
If you don't know which agents are available in your workspace, add the debug capability above and use:
/ask debug agents
This will show all available agents with their IDs and capabilities in your console output.
🔍 Available Agents in Workspace:
1. Name: "Research Assistant" | ID: 2
Capabilities: - Search on the internet about a certain topic...
---
2. Name: "General Assistant" | ID: 3
Capabilities: - Do data analysis, Create PDF reports...
---
3. Name: "Coder" | ID: 39
Capabilities: - Analyze datasets using code, Write python code...
---
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHijklMNOpqrsTUVwxyz
OPENSERV_API_KEY=openserv_key_123abc...
WORKSPACE_ID=123
AGENT_ID=2
- User:
/ask What is OpenServ?
- Bot: Create task (Agent ID: 2)
- OpenServ: Process task
- Bot: Check result
- Bot: Send response to Telegram
Change AGENT_ID
in .env
file:
AGENT_ID=140 # For Perplexity Research
Change maxWaitTime
in src/index.ts
file:
const maxWaitTime = 180000 // 3 minutes