This guide will help you set up the two-way Telegram integration for your portfolio's live chat feature.
- Real-time messaging: Visitors can chat with you directly from your portfolio
- Telegram notifications: You receive all visitor messages in Telegram
- Two-way communication: You can reply from Telegram and messages appear in the visitor's chat
- Session management: Each visitor gets a unique ID for targeted replies
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow the prompts:
- Choose a name for your bot (e.g., "Portfolio Chat Bot")
- Choose a username (must end with 'bot', e.g., "myportfolio_chat_bot")
- BotFather will give you a bot token (keep this secret!)
- Start a chat with your bot (search for your bot's username)
- Send any message to your bot
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Look for your
chat_idin the response (it's a number like123456789)
- Copy
server/env.templatetoserver/.env - Add your bot credentials:
TELEGRAM_BOT_TOKEN=your_bot_token_here TELEGRAM_ADMIN_CHAT_ID=your_chat_id_here
cd server
npm startYou should see:
🤖 Telegram bot initialized
🤖 Telegram Bot: Connected
- Click the chat bubble (💬) on your portfolio
- Type messages and send them
- Messages are delivered to your Telegram
- Reply to specific visitor:
/reply visitor_id your message - Send to all visitors: Just type your message normally
- Example:
/reply visitor_1234567890_abc123 Hello! Thanks for visiting my portfolio.
- Start the backend:
cd server && npm start - Start the frontend:
npm run dev - Open admin chat: Open
admin-chat.htmlin your browser - Test the flow:
- Send a message from your portfolio (visitor)
- See it appear in both admin chat and Telegram
- Reply from either admin chat or Telegram
- See the reply in the visitor's chat
- Check your bot token is correct
- Make sure you've started a chat with your bot
- Verify your chat ID is correct
- Check the server console for errors
- Ensure both frontend and backend are running
- Verify Socket.IO connection in browser console
- Make sure you're using the correct format:
/reply visitor_id message - Check that the visitor is still connected
- Verify the bot has permission to send messages
- Keep your bot token secret
- Don't commit
.envfiles to version control - Consider rate limiting for production use
- Monitor for spam/abuse
For production, consider:
- Using environment variables in your hosting platform
- Setting up SSL/TLS for secure WebSocket connections
- Adding rate limiting and spam protection
- Implementing user authentication if needed
- Adding message persistence/database storage
If you encounter issues:
- Check the server console for error messages
- Verify all environment variables are set correctly
- Test with the admin chat interface first
- Check Telegram bot permissions and settings