Twitter Chatbot Example
- Clone and Navigate
git clone <repository-url>
cd cdp-agentkit/twitter-langchain/examples/chatbot/
- Configure Poetry Environment
# Clear poetry cache
poetry cache clear . --all
# Configure poetry to create virtualenv in project
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
# Install dependencies
poetry install --no-root
# Add required packages
poetry add tweepy python-dotenv langchain-core langgraph langchain-xai
- Configure Twitter API
- Go to Twitter Developer Portal
- Create a new app or select existing app
- Enable OAuth 1.0a and OAuth 2.0
- Set App permissions to "Read and Write"
- Select "Web App, Automated App or Bot"
- Generate/Regenerate all tokens
- Set Environment Variables
# Create .env file
cp .env.example .env
# Add your Twitter API credentials to .env
TWITTER_API_KEY=your_api_key
TWITTER_API_SECRET=your_api_secret
TWITTER_ACCESS_TOKEN=your_access_token
TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret
TWITTER_BEARER_TOKEN=your_bearer_token
XAI_API_KEY=your_xai_api_key
- Run the Chatbot
poetry run python chatbot.py
- chat: say anything, and also can support actions such as posting a tweet.
- auto: ...
- Uses Twitter API v2
- Requires appropriate Twitter Developer Account permissions
- Built with LangChain and XAI integration