This service provides a bridge between Chatwoot and Gupshup, enabling seamless WhatsApp communication through Chatwoot's interface. It handles message synchronization, media transfers, and conversation management between both platforms.
- Bidirectional message sync between Chatwoot and Gupshup
- Support for various message types:
- Text messages
- Images with captions
- Audio messages
- Video messages
- Document files
- Contact cards
- Location sharing
- Button responses
- List responses
- Automatic contact creation and management
- Conversation state management
- Support for customer satisfaction surveys
- Node.js (v14 or higher)
- npm or yarn
- A Chatwoot instance with API access
- A Gupshup WhatsApp Business API account
- Environment variables configuration
- Clone the repository:
git clone https://github.com/hirotadev/chatwoot-gupshup-integration.git
cd chatwoot-gupshup-integration
- Install dependencies:
npm install
- Create a
.env
file in the root directory with the following variables:
# Server Configuration
PORT=3000
# Chatwoot Configuration
CHATWOOT_BASE_URL=https://your-chatwoot-instance.com
CHATWOOT_API_TOKEN=your_chatwoot_api_token
CHATWOOT_ACCOUNT_ID=your_chatwoot_account_id
INBOX_ID=your_chatwoot_inbox_id
# Gupshup Configuration
GUPSHUP_API_KEY=your_gupshup_api_key
GUPSHUP_PHONE=your_whatsapp_phone_number
GUPSHUP_SRC_NAME=your_gupshup_source_name
GUPSHUP_APP_ID=your_gupshup_app_id
- Start the service:
# Development mode
npm run dev
# Production mode
npm start
- Log in to your Gupshup dashboard
- Navigate to WhatsApp API > Configuration
- Set the webhook URL to:
https://your-domain.com/webhook/gupshup
- Go to your Chatwoot installation
- Navigate to Settings > Integrations > Webhooks
- Add a new webhook with the URL:
https://your-domain.com/webhook/chatwoot
- Enable the following events:
- Message Created
- Conversation Updated
The service is built using a modular architecture with the following components:
src/config
: Environment configurationsrc/services
: Core business logic for Chatwoot and Gupshup integrationsrc/utils
: Utility functions for message parsing and phone number formattingsrc/routes
: API endpoint definitions
.
├── README.md
├── index.js
├── package.json
└── src
├── config
│ └── environment.js
├── routes
│ └── webhooks.js
├── services
│ ├── chatwootService.js
│ └── gupshupService.js
└── utils
├── messageParser.js
└── phoneUtils.js
TODO
This project uses ESLint and Prettier for code formatting. Run the following commands:
TODO
The service implements comprehensive error handling:
- All API endpoints return 200 status codes to acknowledge webhook receipt
- Errors are logged but don't interrupt service operation
- Failed message deliveries are logged for manual review
- Phone number validation ensures E.164 format compliance
- Build the Docker image:
docker build -t chatwoot-gupshup-integration .
- Run the container:
docker run -d \
--name chatwoot-gupshup \
-p 3000:3000 \
--env-file .env \
chatwoot-gupshup-integration
- Install PM2:
sudo npm install -g pm2
- Start the service:
pm2 start npm --name "chatwoot-gupshup" -- start
If using Nginx as a reverse proxy:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
- All environment variables should be kept secure
- Use HTTPS for webhook endpoints
- Implement rate limiting in production
- Regular security audits recommended
- Keep dependencies updated
The service includes basic logging through Fastify's logger. For production monitoring:
-
Use tools like:
- PM2 for process management
- Datadog or New Relic for application monitoring
- ELK Stack for log management
-
Monitor key metrics:
- Message delivery rates
- API response times
- Error rates
- System resource usage
Common issues and solutions:
-
Message not being delivered:
- Check webhook configurations
- Verify API credentials
- Check phone number format
-
Connection errors:
- Verify network connectivity
- Check API endpoint availability
- Validate environment variables
-
Media upload failures:
- Check file size limits
- Verify supported file types
- Ensure proper URL formatting
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support:
- Check the issues section for known problems
- Create a new issue for unreported problems
- Contact the maintainers for critical issues
- Chatwoot team for their excellent platform
- Gupshup team for their WhatsApp Business API
- Contributors and community members
Future planned features:
- Support for template messages
- Advanced message queueing
- Dashboard for monitoring
- Automated testing improvements
- Multi-language support