2017-06-16 52 views
1

当我使用详见联系下面的命令:我怎么能发送消息给我的接触丝毫募捐活动API的Python电报

result = client.invoke(GetContactsRequest("")) 
print(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))'])) 

现在怎么我可以给一个这个朋友与first_name我的朋友或user_id或电话或我的联系中的其他细节消息? 我看到这page但我没有注意到。 请使用此

+0

发送消息我在其他问题上发布了解决方案。这有帮助还是你仍然有问题?如果是,哪部分不起作用? – apadana

+0

嗨apadana请回答我这个问题 https://stackoverflow.com/questions/44871661/how-to-send-message-with-id-telegram-using-telethon-library – netdevil

回答

1

简单的代码,如果这是你的联系人,你可以使用的电话号码,就像您使用的用户名:

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

老答案:

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

users列表中包含要与之通话的用户。所以你得到那个用户:

user = result.users[0] 

然后你可以拨打.send_message(user, 'your message')

+0

lonami请回答这个我的问题https:///stackoverflow.com/questions/44605436/how-i-can-restore-sessions-in-telethon-telegram – netdevil

0

https://stackoverflow.com/content/img/progress-dots.gif它很容易显示所有联系人和发送消息

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

进口后

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

可以使用接触式ID

相关问题