Answer the question
In order to leave comments, you need to log in
How to process a “referral link” for a telegram bot?
As I understand it, this is a link of the format t.me/botname?start=id...
So, how exactly should it be processed? After all, in fact, when a person clicks on a link, he simply gets into a chat with a bot and is prompted to press the "Start" button. And for example, I need the inviting person to receive some kind of notification, etc.
It doesn't matter what language, I think I'll understand. Main idea.
Answer the question
In order to leave comments, you need to log in
When a human visits the link t.me/YourBot?start=user_id and clicks Start, the /start user_id message is sent to the bot. To make the referral link shorter, the user ID can, for example, be converted from decimal to 36.
<?php
// Получаем user_id из ID реферала
function parseRefLink($ref_link) {
$ref_link = strtolower($ref_link);
if (!preg_match('/^r_([0-9a-z]+)$/', $ref_link)) {
return false;
}
$ref_link = substr($ref_link, 2);
return intval(base_convert($ref_link, 36, 10));
}
// Получаем ID реферала из user_id
function getRefLink($tg_user_id) {
return 'r_'.base_convert($tg_user_id, 10, 36);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question