This integration enables interaction with WhatsApp in Telegram through the GREEN-API platform. It is built on the Universal Integration Platform from GREEN-API and consists of an adapter that converts messages between Telegram and WhatsApp.
- TelegramAdapter - Express.js application that handles message conversion between Telegram and WhatsApp
- TelegramHandler - Processes Telegram commands and user interactions
- TelegramTransformer - Transforms messages between platforms
- PartnerApiClient - Client for working with GREEN-API Partner API
- Localization - Multi-language support system (English/Russian)
- SQLiteStorage - Database for storing user data and instances
The bot provides the following commands:
/help- Command reference/start- Start working with the bot/me- Information about current user/instance[idInstance] [apiTokenInstance] - Connect GREEN-API instance/resetInstance- Reconnect instance/statusor/getStateInstance- Check instance status/notifications[type] [on|off] - Manage notifications (receiving incoming messages, statuses of sent messages, and instance status)/setchat[chat_id] — Set up forwarding to another Telegram chat/replyor/sendMessage[WhatsApp number] [text] - Send message to WhatsApp/setpartnertoken[token] - Set partner token/createinstance- Create new instance/getinstances- Get list of instances/deleteinstance[idInstance] - Delete instance/languageor/lang- Change language
- Multi-language support (English/Russian)
- Notification management
- Partner API integration
- Instance management via bot
- Webhook handling for both platforms
- SQLite database for data persistence
- .js 20 or higher
- GREEN-API account and instance
- Telegram bot (get from @BotFather)
- Publicly accessible URL for webhooks (when deploying on server)
- Clone or create the project:
mkdir greenapi-integration-telegram- Clone the repository:
git clone https://github.com/green-api/greenapi-integration-telegram.git- Install dependencies:
npm install- Configure environment variables in .env file:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
PORT=3000
WEBHOOK_URL= https://your-webhook-url/TELEGRAM_BOT_TOKEN- via @BotFatherPORT- by default 3000WEBHOOK_URL- public server adress
- Start the application:
npm startCreate Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]And docker-compose.yml:
version: '3.8'
services:
adapter:
build: .
ports:
- "3000:3000"
environment:
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- PORT=3000
volumes:
- ./storage.db:/app/storage.dbStart:
docker-compose up -d- Getting Started
Send the /start command to the bot in Telegram to register.
- Connect GREEN-API instance
/instance [idInstance] [apiTokenInstance]
- idInstance: Your GREEN-API instance ID
- apiTokenInstance: Your GREEN-API instance API token
Example:
/instance 1101111111 abcdef123456789abcdef123456789
- Checking Instance Status
/status
или
/getStateInstance
- Replying to WhatsApp Messages
/reply [WhatsApp number] [message text]
or
/sendMessage [WhatsApp number] [message text]
- Reset connected instance
/resetInstance
- Change language
/language en
or
/language ru
- Manage notifications
-
Enable all notifications
/notifications all on -
Disable all notifications:
/notifications all off -
Enable notifications about incoming messages
/notifications incoming on -
Disable notifications about incoming messages
/notifications incoming off -
Enable notifications about sent message statuses
/notifications outgoing on -
Disable notifications about sent message statuses
/notifications outgoing off -
Enable notifications about instance status
/notifications status on -
Disable notifications about instance status
/notifications status off
- Help
/help
For the integration to work, you will need:
idInstance- ID of your instance in GREEN-APIapiTokenInstance- Access token of your instance
These credentials can be obtained in the GREEN-API console after creating an instance.
The integration forwards the following types of messages from WhatsApp to Telegram:
- Text messages
- Images (with captions)
- Videos (with captions)
- Audio (with captions)
- Documents (with captions)
- Locations
- Contacts
- Polls
The integration forwards the following types of messages from Telegram to WhatsApp:
- Text messages
The integration uses SQLite database to store:
- Telegram user data
- GREEN-API instance connections
- User settings and preferences
- Language preferences
- Settings and states
The database file storage.db is created automatically on first run.
- Check that TELEGRAM_BOT_TOKEN is set correctly
- Make sure the Telegram webhook is configured properly
- Check application logs for errors
- Check instance status with /status command
- Make sure the instance is authorized in GREEN-API
- Check webhook settings in GREEN-API personal account
- Make sure your adapter URL is publicly accessible
- Check file size (Telegram and GREEN-API limitations)
- Make sure the file type is supported
- Check the correctness of the partner token
- Ensure the partner API is accessible
- Check the logs for authentication errors
- Ensure the localization files are present
- Check the language installation using the /language command