add contact with telethon in python
Asked Answered
K

1

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.

Kinlaw answered 22/11, 2018 at 19:9 Comment(0)
M
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.

Mentality answered 23/11, 2018 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.