[Python] aiogram, python. how to get the invitation link that a user used to join a group

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a bot that provides chat invitation links. The user id and his link are saved in the database. how to get the link through which the user entered the chat?

    I tried using various methods such as full_name, as_json() and the like, but none of them returned anything that could help me. json when attached returns

    {"id":19..,"is_bot":false,"first_name":"Vansed","last_name":"Dan","username":"...","language_code":" en"}


    and my code is the following:

    invited_user='Vansed Dan' -
    who_invited='{"id":"...,"is_bot":false,"first_name":"Vansed","last_name":"Dan","username":"...","language_code":" en"}'


    I also tried to get the invitation link that was changed, and track all joins and check after each join who joined and what invitation code is incremented by 1. but I could not do this, due to the lack of any method for getting chat invitation links, or information about link. I searched half the Internet but still couldn’t find such a method. and the getChatInviteLink method does not exist, or I don’t know how to use it

    import requests

    TOKEN = ''
    chat_id = ''
    invite_link = ''

    url = f'https://api.telegram.org/bot{TOKEN}/getChatInviteLink?chat_id={chat_id}&invite_link={invite_link}'

    response = requests.get(url)
    data = response.json()
    print(data)

    if data['ok']:
    print(f"{invite_link}:")
    print(data['result'])
    else:
    print("error")

    Continue reading...

Compartilhe esta Página