A Node.js service that bridges communication between Telegram channels and Intercom conversations, enabling two-way messaging between the platforms.
- Two-way message synchronization between Telegram channels and Intercom conversations
- Real-time message delivery using Intercom webhooks
- Support for text messages and file attachments
- Automatic conversation mapping and management
- Redis-based message queue for reliable message delivery
- HTML message formatting and sanitization
- Error handling and retry mechanisms
- Scalable architecture
- Node.js (v14 or higher)
- Redis server
- Telegram Bot Token (from @BotFather)
- Intercom Access Token
- ngrok or similar tool for webhook development
-
Clone the repository:
git clone [email protected]:coldfire-x/telegram-intercom-bridge.git cd telegram-intercom-bridge
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory:TELEGRAM_BOT_TOKEN=your_telegram_bot_token INTERCOM_ACCESS_TOKEN=your_intercom_access_token REDIS_URL=redis://localhost:6379 WEBHOOK_PORT=3000
-
Start ngrok to create a tunnel for Intercom webhooks:
ngrok http 3000
Copy the HTTPS URL provided by ngrok (e.g.,
https://your-subdomain.ngrok.io
) -
Build the TypeScript code:
npm run build
-
Start the service:
npm start
The service will start listening for messages from both Telegram channels and Intercom conversations.
- Create a new bot using @BotFather
- Get the bot token
- Add the bot to your Telegram channel as an administrator
- Enable the following permissions for the bot:
- Read messages
- Send messages
- Edit messages
- Delete messages
- Post messages
- Create an Intercom app or use an existing one
- Generate an access token with the following permissions:
- Read conversations
- Write conversations
- Read admins
- Write admins
- Set up webhooks:
- In your Intercom app settings, go to "Webhooks" under "Developer Tools"
- Add a new webhook with the URL:
https://your-ngrok-subdomain/webhook/intercom
- Subscribe to the following topics:
conversation.admin.replied
conversation.admin.noted
conversation.admin.single.created
- Save the webhook configuration
The service will now receive real-time updates from Intercom through the webhook endpoint.
The service consists of the following components:
- TelegramService: Handles Telegram bot interactions
- IntercomService: Manages Intercom API communications
- RedisService: Handles message queuing and channel mapping
- BridgeService: Coordinates message flow between platforms
-
Start the service in development mode:
npm run dev
-
Run tests:
npm test
The service implements the following error handling mechanisms:
- Automatic retry for failed message deliveries
- Error logging for debugging
- Graceful shutdown handling
- Connection error recovery
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
If you find this project helpful and would like to support its development, you can buy me a coffee! Your support helps maintain and improve the project.
This project is licensed under the MIT License - see the LICENSE file for details.