A simple chatbot application that integrates with the Fanvue API using OAuth 2.0 authentication, built with Node.js and Express.
Before you begin, make sure you have:
-
Node.js 18 or later installed on your computer
- Check by running:
node --version - Download from: https://nodejs.org/
- Check by running:
-
pnpm package manager installed
- Install with:
npm install -g pnpm - Check by running:
pnpm --version
- Install with:
-
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:3001/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 javascript
Install the required packages using pnpm:
pnpm install
Important: Always use pnpm instead of npm or yarn for this project.
OAuth requires HTTPS redirect URIs, even in local development. We'll use mkcert to create local SSL certificates.
On macOS:
brew install mkcert
On 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/mkcert
On 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.devThis 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/hosts
On 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 .envOn Windows (Command Prompt):
copy .env.example .envOn Windows (PowerShell):
Copy-Item .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:3001/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-26
PORT=3000
Important 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:3001/callback
You'll need two terminal windows for this step.
In your terminal (in the javascript directory), run:
pnpm start
Or:
node app.js
You should see output like:
Fanvue Chatbot running at http://localhost:3000
Press Ctrl+C to stop the server
Keep this terminal window open.
Open a new terminal window, navigate to the javascript directory, and run (replace your-app-name with your chosen app name):
npx local-ssl-proxy --source 3001 --target 3000 --cert ./your-app-name.dev.pem --key ./your-app-name.dev-key.pem
You should see output like:
Proxying https://your-app-name.dev:3001 -> http://localhost:3000
Keep this terminal window open too.
- Open your web browser
- Go to:
https://your-app-name.dev:3001(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
pnpm install - Delete the
node_modulesfolder and runpnpm installagain
- Make sure the Redirect URI in your Fanvue OAuth app settings exactly matches:
https://your-app-name.dev:3001/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 port3001)
- Double-check your
OAUTH_CLIENT_IDandOAUTH_CLIENT_SECRETin the.envfile - Make sure there are no extra spaces or quotes around the values
- Ensure your OAuth app is active in the Fanvue Developer area
- Another application might be using port 3000 or 3001
- For port 3000: Change
PORT=3000in your.envfile to a different number (e.g.,PORT=3002) - For port 3001: 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:3001(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 (Node.js app and SSL proxy)
- Try accessing
https://127.0.0.1:3001instead
- Ensure the Node.js app is running on port 3000 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 - Check the terminal for error messages
- Port 3000 or 3001 is already in use by another application
- Stop the other application or change the ports (update both
.envand the proxy command)
- 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 - Never expose your Client Secret in client-side code
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 3001
Then 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.js - Add more features like message history
- Deploy to a hosting service (Vercel, Railway, Heroku, etc.)
- Add more sophisticated AI responses using OpenAI, Anthropic, or other AI services
- Implement webhook handlers to respond to real-time events
- Add WebSocket support for real-time messaging
When deploying to production:
- Set environment variables in your hosting provider's dashboard
- Update the Redirect URI in your Fanvue OAuth app to your production URL
- Use HTTPS for your production URL (required for OAuth)
- Set a strong
SESSION_SECRET(use a secure random generator) - Consider using a session store like Redis for production
- Vercel: Great for Node.js apps, easy deployment
- Railway: Simple deployment, good for beginners
- Heroku: Well-established platform with good documentation
- Render: Free tier available, easy setup
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 - Look at the terminal output for error messages
javascript/
├── app.js # Main application file
├── package.json # Node.js dependencies and scripts
├── .env.example # Example environment variables
├── .env # Your actual environment variables (create this)
├── .gitignore # Git ignore file
└── README.md # This file
- Fanvue API Documentation: https://api.fanvue.com/docs
- Node.js Documentation: https://nodejs.org/docs
- Express.js Documentation: https://expressjs.com/
- pnpm Documentation: https://pnpm.io/