RefferalLib
Use this Lib for referral tracking.

Getting started

Basic function is track. Prefer to call it on /start:
Libs.ReferralLib.currentUser.track(trackOptions);
params trackOptions - it is object with callback functions for:
callback function
description
onTouchOwnLink()
user touch own link
onAlreadyAttracted()
user already attracted
onAttracted()
user was attracted via chanell
onAtractedByUser(refUser)
user was attracted by other user refUser - it is common user data (fields: nickname, first_name and etc)
​
Also have field chatId with chat id for this user.
See @DemoReferalTrackingBot for details

Functions

​

Get Referral link for current user

Libs.ReferralLib.currentUser.getRefLink(bot.name);
will generate link kind http://t.me/botname?start=userUSER_ID
Also you can change prefix. For example remove "user"
Libs.ReferralLib.currentUser.getRefLink(bot.name, "");
will generate link kind http://t.me/botname?start=USER_ID

​

Get attractor for current user

Libs.ReferralLib.currentUser.attractedByUser()
return user data (with chatId)
​

Get attracted channel for current user

Libs.ReferralLib.currentUser.attractedByChannel()
return Channel wich current user was attracted
​

Get refList

Libs.ReferralLib.currentUser.refList.get();
return list with attracted users
​

Clear refList

Libs.ReferralLib.currentUser.refList.clear();

​

Get Top Refferal List

Libs.ReferralLib.topList.get(45)
return first 45 users ordering by referrals count
​

Clear Top Refferal List

Libs.ReferralLib.topList.clear()

How to

Q: How to give bonus to user for attracted friend?
Answer:
We can use ResourcesLib for this.
on /start
1
function onAttracted(refUser){
2
// access to Bonus Res of refUser
3
let refUserBonus = Libs.ResourcesLib.anotherUserRes("money", refUser.telegramid);
4
refUserBonus.add(100); // add 100 bonus for friend
5
}
6
​
7
Libs.ReferralLib.currentUser.track({
8
onAtractedByUser: onAttracted
9
});
Copied!
​
Q: how to give to referrer 5% of referral user deposit?
Answer:
    1.
    You need setup track in first
    2.
    Seems you need use ResourcesLib​
    3.
    On user set balance:
1
let res = Libs.ResourcesLib.userRes("money");
2
let referrer = Libs.ReferralLib.currentUser.attractedByUser();
3
​
4
// if current user was attracted by referrer
5
if(referrer){
6
let referrerRes = Libs.ResourcesLib.anotherUserRes(
7
"money", referrer.telegramid);
8
9
let amount = res.value * 0.05; // it is 5%
10
referrerRes.takeFromAnother(res, amount);
11
}
Copied!
In this example we use userRes. Also it is possible use chatRes. See ResourcesLib for details
Last modified 1yr ago