2

when i use this command for see contact :

result = client.invoke(GetContactsRequest(""))
print(result)

i see this result :

(contacts.contacts (ID: 0x6f8b8cb2) = (contacts=['(contact (ID: 0xf911c994) = (user_id=334412783, mutual=False))'], users=['(user (ID: 0x2e13f4c3) = (is_self=None, contact=True, mutual_contact=None, deleted=None, bot=None, bot_chat_history=None, bot_nochats=None, verified=None, restricted=None, min=None, bot_inline_geo=None, id=334412783, access_hash=-8113372651091717470, first_name=khood, last_name=None, username=Mosafer575, phone=19132594548, photo=(userProfilePhoto (ID: 0xd559d8c8) = (photo_id=1436291966805583785, photo_small=(fileLocation (ID: 0x53d69076) = (dc_id=1, volume_id=803110857, local_id=86736, secret=1232685751818265379)), photo_big=(fileLocation (ID: 0x53d69076) = (dc_id=1, volume_id=803110857, local_id=86738, secret=3801220285627155105)))), status=(userStatusOffline (ID: 0x8c703f) = (was_online=2017-06-16 13:09:57)), bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None, lang_code=None))']))

now how i can send one message fore this friend with first_name my friend or user_id or phone or other details in my contact??? i see this page but I din't notice. please use simple code for this

netdevil
  • 309
  • 1
  • 7
  • 18
  • I had posted the solution in the other question. Does that help or you still have issues? If yes which part is not working ? – apadana Jun 16 '17 at 16:36
  • hi apadana please answer me this question https://stackoverflow.com/questions/44871661/how-to-send-message-with-id-telegram-using-telethon-library – netdevil Jul 03 '17 at 03:33

3 Answers3

1

If it's your contacts you can use the phone number like you would use an username:

client.send_message('+xx123456789', 'hello')

Old answer:

users=['(user (ID: 0x2e13f4c3) ...`

The users list has the user you want to talk to. So you get that user:

user = result.users[0]

And then you can call .send_message(user, 'your message').

Lonami
  • 5,945
  • 2
  • 20
  • 38
  • lonami please answer this my question https://stackoverflow.com/questions/44605436/how-i-can-restore-sessions-in-telethon-telegram – netdevil Jun 17 '17 at 13:56
0

https://stackoverflow.com/content/img/progress-dots.gif Its easy to show all contact and send messages

from telethon.tl.types import InputPhoneContact
from telethon.tl.functions.contacts import ImportContactsRequest

After import

contacts = client(GetContactsRequest(0))
client.send_message(contact[<You can use indexing>],'<messages>')

You can send message using contact id

Mr Singh
  • 3,936
  • 5
  • 41
  • 60
0

If sending a message all contract number...

all_contacts = await client(GetContactsRequest(hash=0))
for i in range(len(all_contacts.users)):
   if all_contacts.users[i].phone != None:
      await client.send_message(all_contacts.users[i].phone, 'hello')
   else:
      await client.send_message(all_contacts.users[i].username, 'hello')
Jahirul islam
  • 471
  • 5
  • 8