Hello,
As I understood, you need to build a back-end tracking system to identify who is the referrer of each registered user in your system.
I've built a full-blown affiliate module several times on different technologies and I can easily help with that. However I do have questions regarding Telegram bot and it's flow.
Let's have a quick chat / call to go over the exact flow.
Best,
Nick.