AI AgentOpenClawMoltbookTelegram BotAutomation

Deploying an AI Agent from Scratch: A Complete Hands-On Guide with OpenClaw + Moltbook + Telegram

· 44 min read

Why Run Your Own AI Agent?

In 2026, AI Agents are no longer a lab experiment. They post and interact on Moltbook, reply to clients on Telegram, and manage brand presence across social platforms.

Ultra Lab decided to deploy our own AI Agent for straightforward reasons:

  • Brand exposure: Have the Agent represent the brand on Moltbook (an AI-native social platform)
  • Customer service: Provide instant consultation via a Telegram Bot
  • Technical showcase: Prove we don't just talk -- we build
  • Cost: Completely free (Gemini 2.5 Flash free quota + open-source framework)

Tech Stack Selection

Component Choice Reason
Agent framework OpenClaw 2026.3.2 Open-source, 191K+ GitHub stars, multi-platform support
AI model Gemini 2.5 Flash Generous free quota (1,500 requests/day)
Runtime environment WSL2 Ubuntu Isolated and secure, doesn't affect the host system
Social platform Moltbook AI Agent-native social platform, brand visibility
Messaging Telegram Real-time interaction, mature Bot API

Step 1: Prepare an Isolated Environment (WSL2)

Security first. We don't run the Agent directly on the host machine -- we create an isolated environment inside WSL2.

# Verify WSL2 is installed
wsl --list --verbose

Key step: Modify /etc/wsl.conf to prevent the Agent from accessing the Windows filesystem:

[boot]
systemd=true

[automount]
enabled=false

[interop]
appendWindowsPath=false

Restart WSL to apply the settings:

wsl --shutdown
wsl -d Ubuntu

Now the Agent is fully isolated within the Linux environment and cannot read your Windows files.

Step 2: Install OpenClaw

# Verify Node.js 22+
node --version

# Install OpenClaw
sudo npm install -g openclaw@latest

# Create symlink (if the openclaw command isn't found)
sudo ln -sf /usr/lib/node_modules/openclaw/openclaw.mjs /usr/local/bin/openclaw
sudo chmod +x /usr/local/bin/openclaw

# Verify installation
openclaw --version

Step 3: Configure Gemini API

OpenClaw supports multiple AI models. We chose Gemini 2.5 Flash -- free, fast, and strong multilingual capabilities.

# Set the model
openclaw config set agents.defaults.model google/gemini-2.5-flash

Create an auth profile (~/.openclaw/agents/main/agent/auth-profiles.json):

{
  "version": 1,
  "profiles": {
    "google:gemini": {
      "type": "api_key",
      "apiKey": "YOUR_GEMINI_API_KEY",
      "provider": "google"
    }
  }
}

Also add the API key to environment variables (for the systemd service):

mkdir -p ~/.config/systemd/user/openclaw-gateway.service.d
cat > ~/.config/systemd/user/openclaw-gateway.service.d/env.conf << 'EOF'
[Service]
Environment=GEMINI_API_KEY=YOUR_GEMINI_API_KEY
Environment=GOOGLE_GENERATIVE_AI_API_KEY=YOUR_GEMINI_API_KEY
EOF

Step 4: Configure Agent Identity

OpenClaw uses markdown files in the workspace to define an Agent's personality and knowledge base.

Create ~/.openclaw/workspace/IDENTITY.md:

# UltraLabTW

## Identity
- Name: UltraLabTW
- Brand: Ultra Lab (ultralab.tw)
- Origin: Taiwan

## Personality
A technical but approachable AI assistant. Shares insights on AI security, automation, and SaaS development.

## Topics of Expertise
- AI Security (Prompt Injection, vulnerability scanning)
- Social Media Automation
- SaaS Development (React + Firebase + Vercel)
- Prompt Engineering

Set the name and emoji:

openclaw agents set-identity --agent main --name "UltraLabTW" --emoji "⚑"

Step 5: Launch the Gateway

Configure it as a systemd service for automatic startup:

# Start
systemctl --user start openclaw-gateway
systemctl --user enable openclaw-gateway

# Verify it's running
systemctl --user status openclaw-gateway

Test whether the Agent responds properly:

openclaw agent --agent main --message "Hello, introduce yourself"

Success! The Agent replied: "Hello, my name is UltraLabTW ⚑..."

Step 6: Register on Moltbook

Moltbook is a social platform for AI Agents -- think Reddit, but where all the users are AIs.

# Register
curl -X POST "https://www.moltbook.com/api/v1/agents/register" \
  -H "Content-Type: application/json" \
  -d '{"name": "UltraLabTW", "description": "Ultra Lab AI agent from Taiwan"}'

The API returns:

  • api_key: Authentication token
  • claim_url: Link for you (the human) to claim the Agent
  • verification_code: Verification code

Important: You must click the claim URL, verify your email, and publish a post to complete the claiming process. The Agent cannot post until it's claimed.

After claiming, publish the first post:

curl -X POST "https://www.moltbook.com/api/v1/posts" \
  -H "Authorization: Bearer YOUR_MOLTBOOK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"submolt_name": "general", "title": "Hello from Taiwan", "content": "..."}'

Moltbook will present a math verification challenge (to prevent bot spam). Solve it and your post goes live.

Note: The API must use www.moltbook.com. The non-www version strips the Authorization header.

Step 7: Connect Telegram

The final step -- let the Agent communicate with you through Telegram.

Create a Telegram Bot

  1. Search for @BotFather on Telegram
  2. Send /newbot
  3. Set the name and username
  4. Receive the Bot Token

Connect to OpenClaw

# Set the bot token
openclaw config set channels.telegram.accounts.default.botToken "YOUR_BOT_TOKEN"

# Open DMs (default is pairing mode, which blocks all messages)
openclaw config set channels.telegram.dmPolicy "open"
openclaw config set channels.telegram.allowFrom '["*"]'
openclaw config set channels.telegram.accounts.default.dmPolicy "open"
openclaw config set channels.telegram.accounts.default.allowFrom '["*"]'

# Restart the gateway
systemctl --user restart openclaw-gateway

# Verify status
openclaw channels status --probe

The output should show: Telegram default: enabled, configured, running

Now send a message to your bot on Telegram and the Agent will reply using Gemini.

Cost Analysis

Item Monthly Cost
OpenClaw $0 (open-source)
Gemini 2.5 Flash $0 (free quota)
WSL2 $0 (built into Windows)
Moltbook $0 (free platform)
Telegram Bot $0 (free API)
Total $0/month

That's right -- zero cost. Gemini's free quota of 1,500 requests per day is more than enough for individuals or small brands.

Pitfalls We Hit

1. OpenClaw auth-profiles.json Format

OpenClaw's auth file has a specific schema:

{
  "version": 1,
  "profiles": {
    "google:gemini": { ... }
  }
}

It's NOT { "google": { "apiKey": "..." } }. Getting the format wrong produces a "No API key found for provider google" error.

2. Telegram DM Policy

OpenClaw's default Telegram DM policy is "pairing" (pairing mode), which blocks all messages from strangers. If you want anyone to be able to chat with the bot, you must change it to "open" and set allowFrom: ["*"].

3. Moltbook's www Trap

moltbook.com (without www) strips the Authorization header. All API calls must use www.moltbook.com. This is nearly impossible to discover without documentation.

4. ClawHub Rate Limit

You may encounter rate limits when installing skills via ClawHub. Workaround: use clawhub inspect --file to download files individually and manually place them in the skills directory.

5. Gemini JSON Truncation

If the Agent needs to output long JSON (like our competitor analysis feature), setting maxOutputTokens too low will cause JSON truncation. Set it to at least 8192 and add JSON repair logic.

Final Result

After one afternoon of setup, our UltraLabTW Agent can now:

  • Post, comment, and like on Moltbook, representing the Ultra Lab brand
  • Reply to messages in real-time via Telegram, using Gemini 2.5 Flash for response generation
  • Know who it is (UltraLabTW), what brand it serves (Ultra Lab), and its areas of expertise
  • Run securely in a WSL2 isolated environment without affecting the host system
  • Start automatically on boot as a systemd service -- no manual management needed

AI Agents are no longer exclusive to big companies. With open-source tools and free APIs, you can get your brand active in AI communities in a single afternoon.


Want to learn more about AI automation solutions? Contact Ultra Lab or try our AI Security Scanner.

Weekly AI Automation Playbook

No fluff β€” just templates, SOPs, and technical breakdowns you can use right away.

Join the Solo Lab Community

Free resource packs, daily build logs, and AI agents you can talk to. A community for solo devs who build with AI.

Need Technical Help?

Free consultation β€” reply within 24 hours.