A simple chatbot application that integrates with the Fanvue API using OAuth 2.0 authentication.
Before you begin, make sure you have:
-
Python 3.8 or later installed on your computer
- Check by running:
python3 --versionorpython --version - Download from: https://www.python.org/downloads/
- Check by running:
-
A Fanvue account with API access
- Request API access at: https://help.fanvue.com/en/articles/11363222-request-api-keys
-
An OAuth application created in the Fanvue Developer area
- You'll need: Client ID, Client Secret, and Redirect URI
First, choose a name for your app. This will be used for your local domain. For example:
my-chatbotfanvue-bottest-app
Important: Replace your-app-name in all the following steps with the name you choose. Use lowercase letters, numbers, and hyphens only (no spaces).
- Go to the Fanvue Developer Area
- Click "Create New App" or "New OAuth Application"
- Fill in the application details:
- App Name: Give it a name like "My Chatbot"
- Redirect URI:
https://your-app-name.dev:5001/callback(replaceyour-app-namewith your chosen name) - Scopes: Select these scopes:
read:self- To read your own profileread:chat- To read chat conversationswrite:chat- To send messages
- Save your application and copy these values:
- Client ID (looks like:
abc123def456...) - Client Secret (looks like:
xyz789secret...)
- Client ID (looks like:
Note: We'll set up HTTPS in the next step, so you can come back and update the Redirect URI after generating the SSL certificate if needed.
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux) and navigate to this directory:
cd pythonInstall the required packages:
pip3 install -r requirements.txtIf pip3 doesn't work, try pip instead.
OAuth requires HTTPS redirect URIs, even in local development. We'll use mkcert to create local SSL certificates.
On macOS:
brew install mkcertOn Linux:
# Ubuntu/Debian
sudo apt install libnss3-tools
# Then download mkcert from: https://github.com/FiloSottile/mkcert/releases
# Or use the install script:
curl -JLO "https://dl.filippo.io/mkcert/latest?for=linux/amd64"
chmod +x mkcert-v*-linux-amd64
sudo mv mkcert-v*-linux-amd64 /usr/local/bin/mkcertOn Windows: Download from: https://github.com/FiloSottile/mkcert/releases
-
Install the local CA:
mkcert -install
-
Generate certificates (replace
your-app-namewith your chosen app name):mkcert your-app-name.dev
This creates two files:
your-app-name.dev.pem(certificate)your-app-name.dev-key.pem(private key)
Add your local domain to your hosts file:
On macOS/Linux:
echo "127.0.0.1 your-app-name.dev" | sudo tee -a /etc/hostsOn Windows:
- Open Notepad as Administrator
- Open
C:\Windows\System32\drivers\etc\hosts - Add this line:
127.0.0.1 your-app-name.dev - Save the file
-
Copy the example environment file:
cp .env.example .env
-
Open the
.envfile in a text editor (Notepad, TextEdit, VS Code, etc.) -
Fill in your values (replace
your-app-namewith your chosen app name):
OAUTH_CLIENT_ID=your_actual_client_id_here
OAUTH_CLIENT_SECRET=your_actual_client_secret_here
OAUTH_REDIRECT_URI=https://your-app-name.dev:5001/callback
OAUTH_SCOPES=openid offline offline_access read:self read:chat write:chat
SESSION_SECRET=make-this-a-random-string-at-least-16-characters-long-12345
OAUTH_ISSUER_BASE_URL=https://auth.fanvue.com
API_BASE_URL=https://api.fanvue.com
API_VERSION=2025-06-26Important Notes:
- Replace
your-app-namewith your chosen app name inOAUTH_REDIRECT_URI - Replace
your_actual_client_id_herewith your actual Client ID from Step 2 - Replace
your_actual_client_secret_herewith your actual Client Secret from Step 2 - For
SESSION_SECRET, use a random string. You can generate one at: https://randomkeygen.com/ (use the "CodeIgniter Encryption Keys" option) - Never share your
.envfile - it contains sensitive information!
- Update your OAuth application Redirect URI in the Fanvue Developer area to match:
https://your-app-name.dev:5001/callback
You'll need two terminal windows for this step.
In your terminal (in the python directory), run:
python3 app.pyOr if that doesn't work:
python app.pyYou should see output like:
* Running on http://127.0.0.1:5000
* Debug mode: on
Keep this terminal window open.
Open a new terminal window, navigate to the python directory, and run (replace your-app-name with your chosen app name):
npx local-ssl-proxy --source 5001 --target 5000 --cert ./your-app-name.dev.pem --key ./your-app-name.dev-key.pemYou should see output like:
Proxying https://your-app-name.dev:5001 -> http://localhost:5000
Keep this terminal window open too.
- Open your web browser
- Go to:
https://your-app-name.dev:5001(replaceyour-app-namewith your chosen app name) - You may see a security warning - click "Advanced" and then "Proceed to your-app-name.dev" (this is normal for local development)
- Click "Login with Fanvue"
- You'll be redirected to Fanvue to authorize the application
- After authorizing, you'll be redirected back to the chatbot
- Start chatting!
- Authentication: When you click "Login with Fanvue", the app redirects you to Fanvue's OAuth page
- Authorization: You authorize the app to access your Fanvue account
- Token Exchange: Fanvue sends back an authorization code, which the app exchanges for an access token
- Chat: The app uses the access token to send messages through the Fanvue API
- Make sure you ran
pip3 install -r requirements.txt - Try:
pip install -r requirements.txtinstead
- Make sure the Redirect URI in your Fanvue OAuth app settings exactly matches:
https://your-app-name.dev:5001/callback(replaceyour-app-namewith your chosen app name) - Check your
.envfile has the correctOAUTH_REDIRECT_URIwith HTTPS - Verify the domain matches exactly (including the
.devextension and port5001)
- Double-check your
OAUTH_CLIENT_IDandOAUTH_CLIENT_SECRETin the.envfile - Make sure there are no extra spaces or quotes around the values
- Another application might be using port 5000 or 5001
- For port 5000: You can change the port in
app.py(last line:app.run(debug=True, port=5000)) - For port 5001: Change the
--sourceparameter in thelocal-ssl-proxycommand - If you change ports, also update
OAUTH_REDIRECT_URIin.envand your Fanvue OAuth app settings
- Run
mkcert -installto install the local CA certificate - Make sure you're accessing the app via
https://your-app-name.dev:5001(nothttp://) - Try clearing your browser cache and cookies
- Verify the hosts file entry:
cat /etc/hosts | grep your-app-name.dev(should show127.0.0.1 your-app-name.dev) - Make sure both terminal windows are running (Flask app and SSL proxy)
- Try accessing
https://127.0.0.1:5001instead
- Ensure the Flask app is running on port 5000 before starting the SSL proxy
- Check that both terminal windows are still running
- Verify the certificate files exist:
ls -la your-app-name.dev*.pem
- Check that you selected the
write:chatscope in your OAuth app settings - Make sure your
.envfile includeswrite:chatin theOAUTH_SCOPES
- Never commit your
.envfile to version control (Git, GitHub, etc.) - The
.envfile is already in.gitignoreto prevent accidental commits - Keep your Client Secret secure - treat it like a password
- In production, use environment variables provided by your hosting service instead of a
.envfile
The chatbot includes a webhook endpoint at /webhook that can receive real-time notifications from Fanvue. According to the Fanvue Webhooks documentation, Fanvue supports 5 event types:
- Message Received - When a new message arrives
- New Follower - When someone follows a creator
- New Subscriber - When someone subscribes to a creator
- Purchase Received - When a purchase is made
- Tip Received - When a tip is received
- Deploy your application to a publicly accessible URL (required for webhooks)
- Navigate to Fanvue Developer Area → Your App → Webhooks tab
- Enter your webhook URL:
https://your-domain.com/webhook - Select the events you want to receive (e.g., "Message Received")
- Save and enable the webhook
For local development, use a tunneling tool like ngrok:
ngrok http 5001Then use the HTTPS URL provided by ngrok in the Fanvue Webhooks UI.
The webhook endpoint automatically handles all event types and logs the received data to the console for debugging.
Once you have the basic chatbot working, you can:
- Customize the chatbot's responses in
app.py - Add more features like message history
- Deploy to a hosting service (Heroku, Railway, etc.)
- Add more sophisticated AI responses using OpenAI, Anthropic, or other AI services
- Implement webhook handlers to respond to real-time events
If you encounter issues:
- Check the troubleshooting section above
- Review the Fanvue API documentation: https://api.fanvue.com/docs
- Make sure all your environment variables are set correctly
- Check that your OAuth app settings match your
.envfile
python/
├── app.py # Main application file
├── requirements.txt # Python dependencies
├── .env.example # Example environment variables
├── .env # Your actual environment variables (create this)
└── README.md # This file