Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add contact with telethon in python

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.

like image 970
Ali Akhtari Avatar asked Nov 22 '18 19:11

Ali Akhtari


1 Answers

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.

like image 55
tashakori Avatar answered Sep 25 '22 00:09

tashakori