Guides5 min read

WhatsApp as AI Bot Control Interface

Use WhatsApp to control your OpenClaw or OpenClaw from anywhere. Set up WhatsApp as a personal AI command center.

Published: 27/01/2025

Overview

WhatsApp provides an ideal personal control interface for your AI bot. With your phone always nearby, you can issue commands, receive alerts, and interact with your AI from anywhere - no need to open Discord or Telegram.

Why WhatsApp?

| Advantage | Description | |-----------|-------------| | Always Available | Phone is always with you | | Personal | Private 1:1 conversation | | Notifications | Instant push alerts | | Universal | Works on any phone | | End-to-End Encrypted | Secure communication |

Architecture

WhatsApp on Phone
    ↓
[WhatsApp Business API / Bridge]
    ↓
[Your VPS - OpenClaw/OpenClaw]
    ↓
[Actions: Home Assistant, Notes, Commands]

Setup Options

Option 1: WhatsApp Business API (Recommended for Production)

For legitimate business use:

  1. Apply for WhatsApp Business API access
  2. Use a BSP (Business Solution Provider) like Twilio or MessageBird
  3. Connect to your bot via webhooks
WHATSAPP_ENABLED=true
WHATSAPP_PROVIDER=twilio
TWILIO_ACCOUNT_SID=your-sid
TWILIO_AUTH_TOKEN=your-token
TWILIO_WHATSAPP_NUMBER=whatsapp:+14155238886

Option 2: WhatsApp Web Bridge (Personal Use)

For personal assistant use, bridge WhatsApp Web to your bot:

# Using whatsapp-web.js
npm install whatsapp-web.js qrcode-terminal
const { Client, LocalAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');

const client = new Client({
  authStrategy: new LocalAuth()
});

client.on('qr', qr => {
  qrcode.generate(qr, { small: true });
});

client.on('ready', () => {
  console.log('WhatsApp client ready!');
});

client.on('message', async msg => {
  // Only respond to your own number
  if (msg.from === 'YOUR_NUMBER@c.us') {
    const response = await processWithAI(msg.body);
    msg.reply(response);
  }
});

client.initialize();

Control Commands

Set up command shortcuts for quick actions:

Basic Commands

| Command | Action | |---------|--------| | /status | Get bot and server status | | /home lights off | Control Home Assistant | | /note Meeting at 3pm | Create Obsidian note | | /remind 2h Check oven | Set reminder | | /ask [question] | Ask AI anything |

Example Implementation

async function processCommand(message) {
  const text = message.body.toLowerCase();

  if (text.startsWith('/status')) {
    return await getSystemStatus();
  }

  if (text.startsWith('/home ')) {
    const command = text.replace('/home ', '');
    return await controlHomeAssistant(command);
  }

  if (text.startsWith('/note ')) {
    const note = text.replace('/note ', '');
    return await createObsidianNote(note);
  }

  // Default: send to AI
  return await askAI(message.body);
}

Use Cases

Personal AI Assistant

Your WhatsApp becomes a direct line to your AI:

You: "What's on my calendar today?" Bot: "You have 3 events:

  • 10:00 - Team standup
  • 14:00 - Client call
  • 16:30 - Dentist appointment"

Home Control

You: "Turn on the bedroom lights and set AC to 21" Bot: "Done! Bedroom lights are on and AC set to 21°C."

Quick Notes

You: "Note: API key for project X is in LastPass" Bot: "Created note in your Inbox: 'API key for project X is in LastPass' with tags #quick-note #reference"

Alerts and Monitoring

Bot proactively messages you:

Bot: "⚠️ Server alert: Memory usage at 92%. Consider restarting services."

Bot: "📬 New form submission on aineversleeps.co.uk from john@example.com"

Security Setup

Whitelist Your Number

Only respond to your own number:

WHATSAPP_ALLOWED_NUMBERS=447123456789
WHATSAPP_ADMIN_NUMBER=447123456789

Command Authentication

Add PIN for sensitive commands:

const SENSITIVE_COMMANDS = ['/delete', '/restart', '/admin'];

async function validateCommand(message, command) {
  if (SENSITIVE_COMMANDS.some(c => command.startsWith(c))) {
    // Require PIN
    const pin = command.split(' ').pop();
    if (pin !== process.env.ADMIN_PIN) {
      return "This command requires your PIN.";
    }
  }
  return null; // Validation passed
}

Rate Limiting

Prevent abuse:

const rateLimit = new Map();

function checkRateLimit(from) {
  const now = Date.now();
  const limit = rateLimit.get(from) || [];
  const recent = limit.filter(t => now - t < 60000);

  if (recent.length >= 10) {
    return false; // Too many messages
  }

  recent.push(now);
  rateLimit.set(from, recent);
  return true;
}

Integration Examples

Morning Routine

Set up automatic morning briefing:

// Cron job at 7 AM
async function sendMorningBrief() {
  const brief = await generateMorningBrief();
  await whatsappClient.sendMessage(
    process.env.WHATSAPP_ADMIN_NUMBER + '@c.us',
    brief
  );
}

Error Notifications

Get instant alerts for issues:

process.on('uncaughtException', async (error) => {
  await whatsappClient.sendMessage(
    process.env.WHATSAPP_ADMIN_NUMBER + '@c.us',
    `🚨 Bot Error: ${error.message}`
  );
});

Daily Summary

End-of-day report:

// Cron at 6 PM
async function dailySummary() {
  const stats = await getDailyStats();
  await whatsappClient.sendMessage(
    process.env.WHATSAPP_ADMIN_NUMBER + '@c.us',
    `📊 Daily Summary:
- Messages processed: ${stats.messages}
- Commands executed: ${stats.commands}
- API cost: £${stats.cost.toFixed(2)}`
  );
}

VPS Requirements

WhatsApp bridge requires:

| Resource | Requirement | |----------|-------------| | RAM | +512MB for WhatsApp client | | Storage | +1GB for session data | | Network | Stable connection required |

Troubleshooting

Session disconnects

client.on('disconnected', (reason) => {
  console.log('Client disconnected:', reason);
  // Auto-reconnect
  client.initialize();
});

QR code not scanning

  1. Clear session: rm -rf .wwebjs_auth
  2. Restart bot
  3. Scan new QR code

Messages not sending

Check WhatsApp is connected:

const state = await client.getState();
console.log('WhatsApp state:', state); // Should be 'CONNECTED'

Limitations

  • WhatsApp Web bridges may violate ToS
  • Business API has messaging limits
  • Requires phone to stay connected
  • Group messages need careful handling

Best Practices

  1. Personal use only for Web bridges
  2. Business API for customer-facing bots
  3. Clear command syntax for reliability
  4. Error handling for all commands
  5. Logging for debugging

Related Guides

Need Help?

Setting up WhatsApp integration requires careful configuration. Our premium service includes messaging platform setup and testing.

Need a VPS for Your Bot?

We recommend Hostinger KVM 2 VPS - reliable, fast, and perfect for AI chatbots. Get started with our recommended setup.

Get Hostinger VPS

Need Help With Setup?

Got your VPS? Let us handle the technical work. Professional setup and maintenance for OpenClaw (formerly Clawd.bot).