Course 01: Your First AI AgentModule 5 of 8

MODULE 05 · COURSE 01: YOUR FIRST AI AGENT

Module 5: Connecting Your Messaging App

Your Gateway is running. Now you need to hook it up to the app you actually use.

We'll cover Telegram first (easiest), then Discord, then WhatsApp.


Option A: Telegram (Recommended for Beginners)

Step 1: Create a Telegram bot

  1. Open Telegram and search for @BotFather
  2. Send it the message: /newbot
  3. Give your bot a name (e.g., "My AI Agent")
  4. Give it a username — must end in "bot" (e.g., "myagent_bot")
  5. BotFather gives you a token that looks like: 7123456789:AAHxyz...
Copy that token. You'll need it.

Step 2: Add the token to OpenClaw

Run:

openclaw channels login

Select Telegram when prompted, then paste your bot token.

Or add it directly to your config file (~/.openclaw/openclaw.json):

{
  "channels": {
    "telegram": {
      "token": "YOURBOTTOKEN_HERE"
    }
  }
}

Step 3: Restrict who can talk to your bot (important)

By default, anyone who finds your bot can message it. Lock it down to just you:

{
  "channels": {
    "telegram": {
      "token": "YOURBOTTOKEN_HERE",
      "allowFrom": ["yourtelegramusername"]
    }
  }
}

Your Telegram username is the @handle you set for your account — not your phone number. Find it in Telegram Settings.

Step 4: Restart the Gateway

openclaw gateway stop
openclaw gateway start

Step 5: Send your first message

Open Telegram, find your bot by the username you created, and send it a message. It should respond.

Option B: Discord

Step 1: Create a Discord application

  1. Go to discord.com/developers/applications
  2. Click New Application — give it a name
  3. Go to the Bot tab, click Add Bot
  4. Under Token, click Reset Token and copy it
  5. Under Privileged Gateway Intents, enable Message Content Intent

Step 2: Invite the bot to your server

  1. Go to OAuth2 → URL Generator
  2. Check bot under Scopes
  3. Check these permissions: Send Messages, Read Message History, View Channels
  4. Copy the generated URL, open it in your browser, and invite the bot to your server

Step 3: Add the token to OpenClaw

{
  "channels": {
    "discord": {
      "token": "YOURDISCORDBOT_TOKEN"
    }
  }
}

Step 4: Configure allowed channels (optional but recommended)

{
  "channels": {
    "discord": {
      "token": "YOURDISCORDBOT_TOKEN",
      "allowFrom": ["yourdiscorduser_id"]
    }
  }
}

Your Discord user ID: in Discord, go to Settings → Advanced → Enable Developer Mode. Then right-click your username anywhere and "Copy User ID."

Step 5: Restart and test

Restart the Gateway, go to Discord, and message your bot in a DM or in a channel it has access to.

Option C: WhatsApp

WhatsApp is slightly more involved because it uses your actual phone number (via WhatsApp Web's protocol), not a bot account.

Step 1: Run the login flow

openclaw channels login

Select WhatsApp. A QR code appears in your terminal.

Step 2: Scan the QR code

Open WhatsApp on your phone → Settings → Linked Devices → Link a Device. Scan the QR code.

That's it. Your WhatsApp is now connected. The Gateway runs as a linked device — your messages go to both your phone and the Gateway.

Step 3: Lock it down

Add an allowlist so only you (and whoever you choose) can trigger the agent:
{
  "channels": {
    "whatsapp": {
      "allowFrom": ["+15555550123"]
    }
  }
}

Use your full international number with country code.


Testing your connection

Once connected, send your agent a simple message:

"Hey, are you there?"

You should get a response. If you don't:

  1. Check openclaw gateway status — is it running?
  2. Check the logs: openclaw logs — any errors?
  3. Make sure your API key is valid and has credits
  4. Check the channel config is correct in ~/.openclaw/openclaw.json

Next up

Module 6: Your First Conversation →