AI-powered Discord bot that intelligently extracts lead information from natural language messages, enriches them with LinkedIn data, and automatically creates structured leads in Attio CRM.
- π€ Natural Language Processing: Uses Google Gemini AI to extract structured lead data from casual messages
- π LinkedIn Support: Include LinkedIn URLs in your messages for automatic extraction
- π Attio CRM Integration: Creates fully structured leads in your Attio workspace
- π Simple API Key Authentication: Easy setup with Google AI Studio API key
- β‘ Real-time Processing: Instant lead creation with visual feedback in Discord
- π‘οΈ Production-Ready: Comprehensive error handling, logging, and security best practices
- Mention the bot in Discord with lead information
- Google Gemini AI extracts structured data from your natural language message
- Attio CRM receives a complete, structured lead record
- Confirmation posted back to Discord with all details
@LeadBot I just met Sarah Johnson, she's the VP of Sales at Acme Corp
The bot will:
- Extract: Name, company, job title
- Create a complete lead in Attio
- Reply with confirmation and all extracted details
Pro tip: Include LinkedIn URLs for richer data:
@LeadBot Met John Doe from TechCorp, linkedin.com/in/johndoe, email: john@techcorp.com
Before you begin, you'll need:
- Python 3.10+ installed on your system
- Discord Bot Token - Create a Discord bot
- Google AI Studio API Key - Get from Google AI Studio
- Attio API Key - Get from Attio Settings
git clone <your-repo-url>
cd onflow-attiopython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCopy the example environment file and fill in your credentials:
cp .env.example .envEdit .env with your credentials:
# Discord Bot Token
DISCORD_BOT_TOKEN=your_discord_bot_token_here
# Google AI Studio API Key
GOOGLE_API_KEY=your_google_api_key_here
# Attio CRM Configuration
ATTIO_API_KEY=your_attio_api_key_here- Go to Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" section
- Click "Add Bot"
- Under "TOKEN", click "Copy" to get your bot token
- Under "Privileged Gateway Intents", enable:
- MESSAGE CONTENT INTENT
- SERVER MEMBERS INTENT
- Go to "OAuth2" β "URL Generator"
- Select scopes:
bot - Select bot permissions:
- Read Messages/View Channels
- Send Messages
- Add Reactions
- Read Message History
- Use the generated URL to invite the bot to your server
- Go to Google AI Studio
- Sign in with your Google account
- Click "Get API Key" in the left sidebar
- Click "Create API Key"
- Copy your API key and add it to your
.envfile
Note: Google AI Studio provides a generous free tier for Gemini API usage. Monitor your usage in the Google AI Studio dashboard.
- Log in to Attio
- Go to Settings β API
- Click "Create API Key" and copy it
Simply run:
python bot.pyThe bot will:
- Validate your environment configuration
- Connect to Discord
- Start listening for mentions
No OAuth flow needed - just set your GOOGLE_API_KEY in the .env file!
Mention the bot in any Discord channel with lead information:
@LeadBot I just met Sarah Johnson, VP of Sales at Acme Corp
@LeadBot Met John Smith from TechCo, email: john@techco.com, phone: 555-1234
@LeadBot Talked to Mary Williams, CTO at StartupXYZ, located in San Francisco
@LeadBot Contact: Jane Doe, linkedin.com/in/janedoe, works at StartupXYZ as CEO
The bot will:
- Show reaction emojis to indicate progress:
- π€ Processing with Gemini
- πΎ Saving to Attio
- β Success!
- Reply with a formatted summary of the created lead
!help- Display help information!status- Check bot and API connection status
onflow-attio/
βββ bot.py # Main Discord bot entry point
βββ gemini_processor.py # Google Gemini AI integration
βββ attio_client.py # Attio CRM API client
βββ config.py # Configuration management
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ README.md # This file
Discord Message
β
Google Gemini AI (Extract structured data including LinkedIn URLs)
β
Attio CRM (Create lead record)
β
Discord Confirmation
- Google Gemini API integration
- Natural language β structured JSON extraction
- LinkedIn URL extraction from messages
- Pydantic validation for data integrity
- Error handling and retry logic
- Attio API client
- Lead creation with attribute mapping
- Multi-object type support (person, company, deal, user)
- Error handling and validation
- Discord bot main loop
- Message handling
- Command processing
- Workflow orchestration
Error: Configuration validation failed
Solution: Check your .env file has all required variables set
Error: Failed to login to Discord
Solution: Verify your DISCORD_BOT_TOKEN is correct
Error: Google Gemini API: Not configured
Solution: Verify your GOOGLE_API_KEY is set correctly in .env file
Check:
- Bot has proper permissions in Discord server
- Message Content Intent is enabled in Discord Developer Portal
- Bot is actually online (check Discord server member list)
Error: Failed to create lead in Attio
Solution:
- Verify
ATTIO_API_KEYis valid - Ensure
ATTIO_LIST_IDis correct - Check you have permission to create records in that list
- Review Attio API attribute names match your list configuration
Check:
PROXYCURL_API_KEYis set and valid- You have remaining API credits in Proxycurl
- Check logs for specific error messages
Note: LinkedIn enrichment is optional - leads will still be created without it
Set log level in .env:
LOG_LEVEL=INFO # Options: DEBUG, INFO, WARNING, ERRORDefault model is gemini-2.0-flash-exp (fast and capable). To change, edit config.py:
GOOGLE_MODEL = "gemini-1.5-pro" # Or another model- β
.envfile in.gitignore(never commit secrets) - β API keys never logged or exposed
- β Input validation with Pydantic
- β Error messages don't leak sensitive data
Test individual components:
# Test Gemini processor
python gemini_processor.py
# Test Attio client
python attio_client.pyTo add custom fields to leads:
- Update
LeadDatamodel in gemini_processor.py - Update
SYSTEM_PROMPTto extract the new field - Update
_build_attio_payload()in attio_client.py
- Free tier: 15 requests per minute, 1,500 requests per day
- Paid tier: Available for higher usage
- Typical lead extraction: ~200-500 tokens
- Monitor usage in Google AI Studio dashboard
- Free to host and run
- No Discord API costs
For issues, questions, or contributions:
- π Report bugs: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Email: [your-email@example.com]
[Your chosen license - MIT, Apache 2.0, etc.]
- Google AI Studio - Gemini AI
- Attio - CRM platform
- discord.py - Discord API wrapper
Built with β€οΈ using Google Gemini AI