An intelligent WordPress chatbot plugin that qualifies leads using OpenAI's GPT models and routes high-intent conversations to you via Discord threads. Features office hours management, away mode, and human takeover capabilities.
- AI-Powered Conversations: Uses OpenAI GPT models to engage visitors naturally
- Discord Integration: Creates dedicated threads for each conversation with live reply capability
- Office Hours Management: Different behavior during/outside business hours
- Away Mode: Collect leads silently during meetings or busy periods
- Human Takeover: Jump into conversations directly from Discord
- Custom Knowledge Base: Train the bot with your business information
- Session Management: Maintains conversation context across interactions
- Responsive Design: Mobile-friendly chat widget
- WordPress 5.0 or higher
- PHP 7.4 or higher
- OpenAI API account
- Discord server and bot
- External Discord listener bot (Node.js, deployed on Railway)
-
Upload the Plugin
-
Activate the Plugin
- Go to WordPress Admin → Plugins
- Find "Click Foundry ChatBoticus"
- Click "Activate"
-
Configure Settings
- Go to Settings → Lead Chatbot
- Fill in all required fields (see Configuration section)
- Get your API key from OpenAI Platform
- Add it to the plugin settings
- The plugin uses
gpt-4o-miniby default (cost-effective)
- Create a Discord server (your private workspace)
- Enable Developer Mode: User Settings → Advanced → Developer Mode
- Create a
#leadschannel - Right-click the channel → Copy Channel ID
- Go to Discord Developer Portal
- Click "New Application"
- Go to "Bot" section
- Click "Reset Token" and copy the bot token
- Critical: Enable these Privileged Gateway Intents:
- MESSAGE CONTENT INTENT
- SERVER MEMBERS INTENT
- Go to OAuth2 → URL Generator
- Select scopes:
bot
- Select permissions:
- Send Messages
- Create Public Threads
- Send Messages in Threads
- Read Message History
- Copy the generated URL and use it to invite the bot to your server
The WordPress plugin needs a companion Discord bot to listen for human replies and send them back to the website chat.
Required Bot Code (Node.js):
// Save as index.js
const { Client, GatewayIntentBits } = require('discord.js');
const axios = require('axios');
const DISCORD_BOT_TOKEN = process.env.DISCORD_BOT_TOKEN;
const WORDPRESS_WEBHOOK_URL = process.env.WORDPRESS_WEBHOOK_URL; // e.g., https://yoursite.com/wp-json/alc/v1/discord-message
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('messageCreate', async (message) => {
// Only process thread messages
if (!message.channel.isThread()) return;
// Don't process bot messages
if (message.author.bot) return;
try {
await axios.post(WORDPRESS_WEBHOOK_URL, {
thread_id: message.channel.id,
message: message.content,
author_is_bot: message.author.bot,
}, {
headers: {
'Authorization': `Bot ${DISCORD_BOT_TOKEN}`,
'Content-Type': 'application/json',
},
});
} catch (error) {
console.error('Error forwarding message:', error.message);
}
});
client.login(DISCORD_BOT_TOKEN);Deploy to Railway.app (Recommended):
- Create account at Railway.app
- Create new project
- Add the code above
- Set environment variables:
DISCORD_BOT_TOKEN(from Discord Developer Portal)WORDPRESS_WEBHOOK_URL(shown in plugin settings:https://yoursite.com/wp-json/alc/v1/discord-message)
- Deploy
Alternative: Deploy to Heroku, DigitalOcean, or any Node.js hosting.
You have two options for setting up your knowledge base:
Option A: Use the included file
- Edit the
knowledgebase.txtfile in the plugin folder - Replace the placeholder text with your actual business information
- Save the file
Option B: Delete the file and use WordPress settings
- Delete
knowledgebase.txtfrom the plugin folder - Use the "Custom Knowledge Base" field in WordPress Admin → Settings → Lead Chatbot
- Paste your business information directly there
Knowledge Base Tips:
- Include your services, pricing, and typical timelines
- List ideal client profiles and qualification questions
- Provide common Q&A
- Describe what makes you different
- The AI will reference this information naturally in conversations
Fill in all fields in WordPress Admin → Settings → Lead Chatbot:
- Your Name: How you want to be referred to
- OpenAI API Key: From OpenAI platform
- Greeting Message (Office Hours): First message visitors see during business hours
- After Hours Message: First message outside office hours
- Custom Knowledge Base: (Optional) Add here instead of using file
- Discord Bot Token: From Discord Developer Portal
- Discord Channel ID: Your #leads channel ID
In the WordPress admin settings, you'll find quick toggle switches:
- Chatbot Enabled: Master on/off switch
- Away Mode: Bot works normally but doesn't ping you (great for meetings)
Office Hours (9am-5pm PT, Monday-Friday):
- Bot identifies high-intent leads
- Pings you in Discord for immediate response
- You can jump in and take over the conversation
Outside Office Hours:
- Bot still qualifies leads
- Creates Discord thread but doesn't ping
- You can follow up when back online
Away Mode (anytime):
- Bot continues qualifying
- No pings sent (silent mode)
- Review conversations when ready
When a high-intent lead appears:
- Discord will create a thread in your #leads channel
- If during office hours (and not in away mode), you'll get pinged
- Simply reply in the thread
- Your message appears instantly in the website chat
- The visitor sees "Typing..." change to your message
- Continue the conversation naturally
The bot considers these signals as high-intent:
- Mentions budget, pricing, or cost
- Says things like "interested," "want to talk," "call me"
- Discusses timeline
- After 8+ messages (long engagement)
Edit chatbot.php, find the OpenAI API call:
'model' => 'gpt-4o-mini', // Change to 'gpt-4' for better quality (higher cost)Edit the alc_is_office_hours() function:
// Monday-Friday, 9am-5pm PT
$is_weekday = $day >= 1 && $day <= 5;
$is_office_hours = $hour >= 9 && $hour < 17;Edit chatbot.css to match your brand:
#alc-chat-toggle {
background: #007bff; /* Change color */
}Edit the system message in chatbot.php function alc_handle_chat() to adjust how the bot qualifies leads.
- Visitor opens chat → Bot greets with appropriate message
- Conversation begins → GPT model responds using your knowledge base
- Bot qualifies lead → Asks about industry, needs, budget, timeline
- Discord thread created → First message creates thread in #leads
- High-intent detected → Bot pings you (if in office hours & not away)
- You respond → Discord listener forwards your reply to website
- Seamless handoff → Visitor continues chat with you
- Never commit your actual
knowledgebase.txtfile - Keep
.envfiles out of version control - Regenerate Discord bot token if exposed
- Use environment variables for sensitive data in production
- WordPress nonces protect AJAX endpoints
Bot not responding:
- Check OpenAI API key is valid and has credits
- Check browser console for JavaScript errors
Discord integration not working:
- Verify bot token and channel ID
- Ensure bot has proper permissions
- Check that Discord listener bot is running
- Verify webhook URL in listener bot matches your site
Human replies not showing:
- Confirm Discord listener bot is deployed and running
- Check Railway/Heroku logs for errors
- Verify webhook authorization header
Chat widget not appearing:
- Check that "Chatbot Enabled" is checked in settings
- Clear WordPress cache
- Check browser console for errors
This plugin is released under GPL v2 or later.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions, please open an issue on GitHub.
Built with OpenAI GPT models and Discord API.