5

Recently I tried to add contact in telegram with telethon, according to this tutorial: 1) Add new contact in api telegram python telethon ,I used this codes:

contact = InputPhoneContact(client_id=0, phone='+989122725691', first_name="user",
                        last_name="test")
result = ImportContactsRequest(contacts=[contact])
print(result)

But I in my output I get this :

ImportContactsRequest(contacts=[InputPhoneContact(client_id=0, phone='+989122725691', first_name='user', last_name='test')])

I can'd find out what is my problem, but when I go to my telegram app, this contact isn't add.

Ali Akhtari
  • 1,211
  • 2
  • 21
  • 42

1 Answers1

7

you should call ImportContactsRequest with your client Instance. e.g.

import random
contact = InputPhoneContact(client_id=random.randint(0,9999), phone='+98912******', 
    first_name="user",
    last_name="test")
result = client(ImportContactsRequest(contacts=[contact]))
print(result.__dict__)

Author note

Official applications use random numbers, and we have had issues with it in the past.

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
tashakori
  • 2,331
  • 1
  • 22
  • 29