Answer the question
In order to leave comments, you need to log in
How to add a user to contacts using telethon?
I'm trying to add a contact using the telethon library.
from telethon.tl.functions.contacts import GetContactsRequest
from telethon.tl.types import InputPeerUser
from telethon.tl.types import InputPhoneContact
from telethon import TelegramClient, events, sync
api_id = xxxx
api_hash = 'xxxx'
phone_number='xxxx'
client = TelegramClient('session_name', api_id, api_hash)
client.connect()
contact = InputPhoneContact(client_id=0, phone=phone_number, first_name="xxx", last_name="xxx")
result = client.invoke(ImportContactsRequest([contact]))
contact_info = client.get_entity(phone_number)
print(contact_info.username)
File "tg.py", line 17, in <module>
result = client.invoke(ImportContactsRequest([contact]))
AttributeError: 'TelegramClient' object has no attribute 'invoke'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question