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
- Open Telegram and search for @BotFather
- Send it the message:
/newbot - Give your bot a name (e.g., "My AI Agent")
- Give it a username — must end in "bot" (e.g., "myagent_bot")
- BotFather gives you a token that looks like:
7123456789:AAHxyz...
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
- Go to discord.com/developers/applications
- Click New Application — give it a name
- Go to the Bot tab, click Add Bot
- Under Token, click Reset Token and copy it
- Under Privileged Gateway Intents, enable Message Content Intent
Step 2: Invite the bot to your server
- Go to OAuth2 → URL Generator
- Check bot under Scopes
- Check these permissions: Send Messages, Read Message History, View Channels
- 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:
- Check
openclaw gateway status— is it running? - Check the logs:
openclaw logs— any errors? - Make sure your API key is valid and has credits
- Check the channel config is correct in
~/.openclaw/openclaw.json