Telegram users gain a personal AI assistant through OpenClaw integration. Moltbot responds instantly to messages, manages tasks, and provides information on demand. Setup requires just 10 minutes, making it the fastest platform to integrate with OpenClaw.
Prerequisites
- OpenClaw CLI installed (
npm install -g openclaw-cli) - Telegram account
- Node.js 16+ and npm 8+
- Basic command line knowledge
1Create Telegram Bot
Use BotFather to create your bot:
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Choose a name (e.g., "Personal Assistant")
- Choose a username (must end in 'bot', e.g., "my_assistant_bot")
- Copy the bot token provided by BotFather
BotFather will respond with:
Done! Congratulations on your new bot.
You will find it at t.me/my_assistant_bot
Use this token to access the HTTP API:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
2Configure Bot Settings
Customize your bot with BotFather commands:
/setdescription - Set bot description
/setabouttext - Set about text
/setuserpic - Upload bot profile picture
/setcommands - Set command list
Example command list:
start - Start the bot
help - Show help message
status - Check bot status
settings - Configure preferences
3Initialize OpenClaw for Telegram
Create a new OpenClaw project for Telegram:
openclaw init telegram-bot --platform telegram
cd telegram-bot
Project structure:
telegram-bot/
├── openclaw.config.js
├── .env.example
├── commands/
│ ├── start.js
│ ├── help.js
│ └── settings.js
├── handlers/
│ ├── message.js
│ └── callback.js
└── package.json
4Configure Environment Variables
Create .env file with your bot token:
# Telegram Configuration
TELEGRAM_BOT_TOKEN=your_bot_token_here
# OpenClaw Settings
OPENCLAW_API_KEY=your_openclaw_api_key
OPENCLAW_MODE=production
OPENCLAW_LANGUAGE=en
# Optional Features
ENABLE_INLINE_MODE=true
ENABLE_WEBHOOKS=false
LOG_LEVEL=info
5Customize Bot Configuration
Edit openclaw.config.js:
module.exports = {
name: 'Personal Assistant',
// AI Configuration
ai: {
model: 'openclaw-v2',
temperature: 0.7,
maxTokens: 500,
contextWindow: 20
},
// Telegram-specific settings
telegram: {
polling: true,
parseMode: 'Markdown',
webPreview: false
},
// Feature toggles
features: {
inlineMode: true,
callbackQueries: true,
fileHandling: true,
voiceMessages: false
},
// Response templates
responses: {
start: 'Welcome! 👋 I\'m your personal AI assistant.',
help: 'I can help you with:\n• Answering questions\n• Managing tasks\n• Providing information',
error: '❌ Something went wrong. Please try again.',
processing: '⏳ Processing your request...'
}
};
6Create Bot Commands
Implement the /start command in commands/start.js:
module.exports = {
command: 'start',
description: 'Start the bot',
async execute(ctx) {
const keyboard = {
inline_keyboard: [
[
{ text: '❓ Help', callback_data: 'help' },
{ text: '⚙️ Settings', callback_data: 'settings' }
],
[
{ text: '📊 Status', callback_data: 'status' }
]
]
};
await ctx.reply(
`*Welcome to OpenClaw!* 🎉\n\n` +
`I'm your personal AI assistant. Ask me anything!\n\n` +
`Try these commands:\n` +
`/help - Show available commands\n` +
`/status - Check bot status\n` +
`/settings - Configure preferences`,
{
parse_mode: 'Markdown',
reply_markup: keyboard
}
);
}
};
7Handle Messages
Process user messages in handlers/message.js:
module.exports = async (ctx, openclaw) => {
const message = ctx.message.text;
const userId = ctx.from.id;
// Show typing indicator
await ctx.sendChatAction('typing');
try {
// Generate AI response
const response = await openclaw.generateResponse(
message,
userId,
{
platform: 'telegram',
chatId: ctx.chat.id
}
);
// Send response
await ctx.reply(response, {
parse_mode: 'Markdown',
disable_web_page_preview: true
});
} catch (error) {
await ctx.reply('Sorry, I encountered an error. Please try again.');
}
};
8Start Your Bot
Launch OpenClaw in development mode:
openclaw dev
Expected output:
🚀 OpenClaw Telegram Bot Starting...
✓ Configuration loaded
✓ Commands registered: 4
✓ Handlers loaded: 2
✓ Connected to Telegram
✓ Bot online: @my_assistant_bot
✓ Polling for updates
→ Ready to receive messages!
/start to begin.
Advanced Features
Inline Mode
Enable inline queries for quick responses:
// handlers/inline.js
module.exports = async (ctx, openclaw) => {
const query = ctx.inlineQuery.query;
if (!query) {
return ctx.answerInlineQuery([]);
}
const response = await openclaw.generateResponse(query);
const results = [{
type: 'article',
id: '1',
title: 'OpenClaw Response',
input_message_content: {
message_text: response
},
description: response.substring(0, 100)
}];
await ctx.answerInlineQuery(results);
};
Callback Queries
Handle button clicks:
// handlers/callback.js
module.exports = async (ctx) => {
const action = ctx.callbackQuery.data;
await ctx.answerCbQuery();
switch (action) {
case 'help':
await ctx.editMessageText('📚 *Help Menu*\n\nAvailable commands...');
break;
case 'settings':
await ctx.editMessageText('⚙️ *Settings*\n\nConfigure your preferences...');
break;
case 'status':
await ctx.editMessageText('✅ *Status*\n\nBot is online and ready!');
break;
}
};
File Handling
Process documents and images:
// handlers/document.js
module.exports = async (ctx, openclaw) => {
const file = ctx.message.document || ctx.message.photo[0];
await ctx.reply('📄 Processing your file...');
const fileLink = await ctx.telegram.getFileLink(file.file_id);
const analysis = await openclaw.analyzeFile(fileLink);
await ctx.reply(`Analysis complete:\n${analysis}`);
};
Production Deployment
Deploy with PM2 for reliability:
# Install PM2
npm install -g pm2
# Start bot
pm2 start openclaw --name telegram-bot -- start
# Enable auto-restart
pm2 startup
pm2 save
# Monitor logs
pm2 logs telegram-bot
ENABLE_WEBHOOKS=true and configure your server URL.
Troubleshooting
- Bot doesn't respond: Verify bot token is correct and bot is not blocked
- Commands not working: Ensure commands are registered with BotFather
- Inline mode not working: Enable inline mode in BotFather settings
- Connection timeout: Check network connectivity and firewall settings
For more help, visit the OpenClaw Telegram community or check our comprehensive documentation.