Skip to content

Integrating WhatsApp into Telegram using the GREEN API#

Want to combine the power of WhatsApp with the convenience of the Telegram platform? It's easy with our greenapi-integration-telegram library!

In this guide, you'll create a Telegram bot that will receive WhatsApp messages and allow you to reply to them without leaving the comfort of your Telegram chat.

Contents#

Step 1. Preparing WhatsApp via Green-API#

To use the GREEN-API application, you need to obtain a registration token and instance ID in your console.

  1. Log in or register an account with GREEN-API.
  2. Create an instance. For testing, we recommend using the free Developer plan.

    • In your console, click the Create instance button and select a plan.

    Create instance
    Developer plan

  3. Authorize the instance. To do this:

    • Click the Get QR button on the instance setup page.
    • In the WhatsApp or WhatsApp Business mobile app, sign in to your linked devices and scan the received QR code.

    Get QR

    After successful authorization, the instance should receive the 'Authorized' status.
    You can check the instance status using the GetStateInstance method.

  4. Copy the idInstance and apiTokenInstance values ​​and save them for integration setup

    Instance parameters

Step 2. Preparing Telegram#

  1. Find the official bot channel @BotFather with a blue checkmark in Telegram.
  2. Click the button. Start or send the /start command
  3. Send the /newbot command to create a new bot
  4. Send a name for the bot - this is the name users will see in the chat
  5. Create and send a nickname, which must be unique and end in bot (e.g., telegram_bot)
  6. BotFather will create your bot and send you a message with a token and a link to it
  7. Save this token for integration setup

Step 3. Preparing the local server#

This step is only for those testing the bot locally.

You'll need this if:

  • You're running the bot on your own computer
  • You're working from home/office without a public IP
  • You want to test webhooks on a local machine

Not needed if:

  • The bot is already hosted on a server/VPS
  • You have a public IP address
  • You're using cloud hosting
  1. Go to dashboard.ngrok.com
    You'll need to create an account to use the service.

  2. In the left menu, select Setup & Installation

    Setup & Installation

  3. Download the appropriate version for your OS, unzip the archive, and install the contents.

    Select OS

  4. On the ngrok website, select Your Authtoken

    Your Authtoken

  5. Copy the token shown at the top of the screen.

    Copy token

  6. Run the following in the command line:

    ngrok config add-authtoken YOUR_AUTH_TOKEN # token obtained from the website
    
  7. Run ngrok

    ngrok http 3000
    
  8. A session will open for forwarding requests from an external address.
    Find the Forwarding line (second from the bottom) and save this address for integration setup

    Forwarding https://your-address.ngrok-free.dev -> http://localhost:3000
    

Step 4. Installing the Integration#

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 the file .env:

TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here   # token obtained from BotFather
PORT=3000                                         # port, default 3000
WEBHOOK_URL= https://your-webhook-url/            # public server address for receiving notifications

Step 5. Launching the application#

The application is launched with the command:

npm start

Step 6 Getting Started#

Start a conversation with the bot:

/start

Connect a Green-API instance to receive messages from WhatsApp:

/instance [idInstance] [apiTokenInstance]

Example:

/instance 1101111111 abcdef123456789abcdef123456789

Now the bot will receive and send you messages from the WhatsApp account connected to Green-API instance, in a Telegram chat with the bot.

Full list of bot commands

Conclusion#

By following these simple steps, you can create a Telegram bot that will receive WhatsApp messages and allow you to send responses.

GREEN-API is always happy to help you integrate WhatsApp with other platforms.