Python – Add new contact in api telegram python telethon


How do I save a number in my contacts in telethon python?

from telethon import TelegramClient
from import GetContactsRequest
from import InputPeerUser
client = TelegramClient('arta0', api_id, api_hash)
#name='ali karimi'

What module do I need to add contact?

Best Solution

You can create a contact like this:

contact = InputPhoneContact(client_id = 0, phone = "+12345678", first_name="ABC", last_name="abc")

result = client.invoke(ImportContactsRequest([contact], replace=True))

To create a new contact you need to pass 0 for the client_id.