Warsaw, Poland
Warsaw, Poland
Miami, USA
São Paulo, Brazil
São Paulo, Brazil
São Paulo, Brazil
São Paulo, Brazil
Yerevan, Armenia
Limassol, Cyprus
Pasay, Philippines
Bucharest, Romania
Ibiza, Spain
Budapest, Hungary
Marsa, Malta
Dubai, UAE

Telegram channel ad with optimization for subscribers (conversions) on Facebook Ads

A step-by-step instruction on how to set up Telegram channels’ ads for conversions on Facebook Ads. After each successful subscription to our channel on Facebook you will get conversion. It is implemented due to the Python script (written by Adam) that tracks information about new subscribers via the Telethon library. Conversions are sent to the Keitaro tracker and through Facebook’s Conversion API.

To install and properly run the script we will need:

  • VDS server; 
  • Telegram account;
  • Keitaro tracker;
  • Facebook account.

Server installation and preparation

Buy a VDS-server, for example on FriendHosting, choose Start tariff plan (you can choose another one), then the operating system Ubuntu 22.04 64 bit and FastPanel.

After 30 minutes you should get an activation email:

Follow the address from the FastPanel email, log in with the username and password:

Click Create a website:

Choose manual creation of a website:

In the “Which domain to connect” field, type “” – we will use it in commands for the terminal/console in the future. Click to proceed to the next step:

Turn off the database by clicking on the appropriate toggle switch and click Create a website:

The website is created, now go to the website card:

Scroll down and go to FTP accounts:

Click on Edit an already created FTP account on the right side:

Generate or enter your own password. Save the login and password in the notepad to avoid losing data. Save:

Next, use an FTP client. We use Filezilla, click on the Site Manager on the top left of the program:

Select a protocol – FTP. Add IP-servers to the Host field. Add the login of the FTP account to the User field. Click connect:

In the new window enter the password of the FTP account and click OK:

After logging in, delete the files in the root directory:

Script preparation

Download the ready-to-use script from the “Adam’s Blog” Telegram channel:

You need to add the missing text file “links.txt” to the archive with the script. To do this unzip the downloaded archive and create an empty file “links.txt” in the “invites_rotator_php” folder:

Zip all the script files and upload them to the server via FileZilla:

Return to the FastPanel tab, go to Files:

Click on the uploaded file, then click on the triplet on the right and select “Unzip”:

Open the file “”:

The data we need to change:

Next, let’s see where to get this data.

How to get data from Telegram and Keitaro

  • api_id = ‘20212727’
  • api_hash = ‘1fa0ce4a271a1971a396ff26316f0112’

Go to, enter the phone number from Telegram and click Next:

Enter the code that you receive via Telegram, click Sign In:

Enter random names in App title and Short name lines. Choose Platform -> Android and click Create application:

The api_id and api_hash data is obtained:

  • phone_number = “+123467890”

Enter the phone number from your Telegram account.

  • channel_id = -123467890

In the same Telegram account create a Telegram channel with a private access by an invite link (the script’s performance depends on it):

Go to the Telegram-bot and forward the message from the Telegram channel to find out the ID:

  • kt_address = ‘’

Enter the domain that is linked to the Keitaro tracker and uses the https protocol.

  • kt_token = ’37d3312100te0s9a1a01e999f7d92e3e’

To create an API key in the Keitaro tracker, go to Admin -> Profile -> API keys -> Create a new key:

  • kt_timezone = ‘Europe/Moscow’

Set the timezone that you have in the Keitaro tracker profile:

After entering all the data, save the “” file:

Creating invite links and saving hashes

Create 10 or more invite links on the Telegram channel for the script to work correctly with the Keitaro tracker:

Open Fastpanel and go to the “invites_rotator_php” folder and open the “links.txt” file:

Copy all the created invite links into it in hash format (without and click Save:

Installing the script in the server

Next, open Console (Windows) or Terminal (macOS), in our case it is Terminal:

Connect to the server using the command:


In the example:

ssh [email protected]**.**3.26 -p 3333

Enter the password:

Enter the command:

cd root directory

In the example:

cd /var/www/telegram_kei_usr74/data/www/

Take the address of the root directory from FastPanel -> Site Map:

Installing Python:

Command for macOS:

apt install python3-pip

Command for Windows:

apt install python-pip

Install dependencies:

Command for macOS:

pip3 install -r requirements.txt

Command for Windows

pip install -r requirements.txt

Update packages:

sudo apt-get update

Install the screen package:

sudo apt-get install screen

Create a new session in console/terminal to run the script offline:

screen -S telegram-keitaro-capi

After the new tab appears in the console or terminal enter the command:

Command for macOS:


Command for Windows:


Enter the password that you have received via your Telegram account:

*If you have errors after signing up, you may have logged out of your Telegram account or entered incorrect data in the “” file.

**We do not recommend creating a Telegram account with a virtual number as you can lose access to it after logging out.

Offline mode

IMPORTANT: After logging in to the Telegram account, press the following key combination in the opened Terminal or Console tab to run the script in the offline mode:

  • CONTROL + A + D (on macO)
  • CTRL + A + D (on Windows)

Setting up a Facebook source in Keitaro

Create or edit a source for Facebook:

In “External ID” remove the value “{fblid}” in the “fbclid” parameter, since Facebook passes this value automatically:

Put the parameters into “sud_id_7

  • Name: pixel ID;
  • Parameter: pixel;
  • Value: insert the pixel from the Facebook ad account (from which you’ll drive the traffic);

Put the parameters into “sud_id_14

  • Name: Campaign Domain;
  • Parameter: domain;
  • Value: Specify the campaign domain (without the protocol) for which you run ads from Facebook;

Put parameters into “sud_id_15”

  • Name: FB Token;
  • Parameter: token;
  • Value: In the example, the token is taken from the Facebook app. Instructions on how to create it;

*Do not change other parameters and leave them as standard.

Configuring Offers in Keitaro

Next, you need to create local offers for each invite in the tracker and customize them.

Detailed instructions on how to add local offers in the Keitaro tracker:

First, follow each previously prepared invite link from the Telegram channel and download the pages opened in your browser with the plugin:

Each downloaded page will be uploaded to a separate local offer in the tracker. Before downloading, be sure to change “index.html” to “index.php”:

Then in each local offer in the file “index.php” put the following code at the beginning:


function updateParams($params) {

    global $rawClick;


    if (!empty($subId)) {

      $result = file_get_contents('http://ТРЕКЕР_ДОМЕН/?_update_tokens=1&sub_id=' . urlencode($subId) . '&' . http_build_query($params));




  'sub_id_13' => 'ХЭШ ссылки Telegram-канала' ,



In this code it is necessary to put the IP address of your Keitaro tracker instead of “TRACKER_DOMAIN” and enter the invite hash (corresponding to the downloaded page) in the parameter “sub_id_13” instead of “Telegram channel link hash”.

Important! For each downloaded landing page, you need to put the corresponding hash into the code. Example: if we downloaded a page by following the link, we should insert the hash from this link as sub_id_13, i.e. wfla4raHVVAyM2NI.

You can do this before uploading the file to the tracker or in the tracker itself by clicking the “<>” icon in the Keitaro’s offer editing mode:

Make the necessary edits in the editor:

Setting up a campaign in Keitaro

  • Select the domain from which the ads traffic will drive to Facebook;
  • Select the customized Facebook source;
  • Select localized offers;
  • Choose to rotate streams by weight and link them to streams, landings, and offers.

Facebook ad launch settings

Copy the link from the Keitaro campaign and paste it into the Website URL but without parameters (

Go below and paste all the parameters into the “URL parameters” field:

After all the settings we launch the campaign.

Transferring leads via API from Telegram to Facebook

When a user subscribes via our Keitaro link, the script sends an API event to the Facebook campaign:

Data transfer to Keitaro tracker

The script passes the following data about the user who has subscribed to Keitaro: first name, last name, @username (nickname), phone number (if not hidden), etc.

Additional commands

The following commands may be useful while working with the script.

Check open sessions

screen -ls

Go to an open session

screen -r telegram-keitaro-capi

A working session is opened:

Create a new session

screen -S telegram-keitaro-capi

Quit the session

screen -X -S SESSION NAME quit

Example: screen -X -S 57612.telegram-keitaro-capi quit


Like it? Share with your friends!
Affiliate - Our assessment
Min. sum
CPA network in the gambling and betting verticals with 200+ offers available, including exclusives such as Olymp Casino, Elon, etc. It receives traffic from 40+ GEOs. Clicklead cooperates using the CPA model: FTD, FTD + KPi, QFTD.
$100 pay
An affiliate program from the direct advertiser They accept gambling and betting traffic worldwide. CPA on popular GEO is $20-50, Revshare - from 30% to 70%. They share apps and deeplinks upon request. They also offer a large selection of proxies.
$50 pay
Affiliate network in the iGaming vertical. They work only with direct advertisers, and the lion's share of offers are presented exclusively. Huffson has individual conditions, own platform, detailed statistics, PWA applications, and custom promo.
$100 pay
V.Partners review
It’s a direct advertiser of the popular European casino “Vulkan Vegas” established back in 2016. They operate in the gambling vertical within CPA, RevShare, and Hybrid partnership models.
€100 pay
A CPA network that has been on the market since 2013. They have over 1500 offers and offer dynamic bids. Key GEOs: CIS, Europe, and LatAm, Africa. They also have a loyalty program with bonuses for leads.
$50 pay
It’s our affiliate program with gambling and nutra offers. We are currently in beta but we accept traffic.
$20 pay