简体   繁体   English

PEER_ID_INVALID向用户ID发送消息

[英]PEER_ID_INVALID in sending Message to userid

I'm using TLSharp to create a client for Telegram and i want to send messages to some telegram users. 我正在使用TLSharp为电报创建客户端,我想向一些电报用户发送消息。
i have their username and userid to use, but i can't find a way to just use their username to send them a message (although in telegram api you can do this but i couldn't find a way to do it with TLSharp ), so i use their userid to send them a message with this code: 我有要使用的usernameuserid username ,但是我找不到一种使用他们的username向他们发送消息的方法(尽管在电报API中,您可以执行此操作,但我找不到使用TLSharp ) ,因此我使用他们的userid向他们发送包含以下代码的消息:

await client.SendMessageAsync(new TLInputPeerUser() { user_id = someOneUserid }, "This is My Message");  

this code works find with people that i have them in my contact list but with the others i got PEER_ID_INVALID exception. 此代码适用于与我联系在一起的人,但与其他人PEER_ID_INVALID例外。

is there a way to add these people to contact list before sending them a message? 有没有办法在向他们发送消息之前将这些人添加到联系人列表? or is there a way to just use their username ? 或者有没有办法只使用他们的username

thanks in Advance. 提前致谢。

I know that the thread is not active anymore but for who viewing this page in future : 我知道该线程不再处于活动状态,但是将来有谁查看此页面:

You need AccessHash to send message : 您需要AccessHash来发送消息:

await client.SendMessageAsync( new TLInputPeerUser() { UserId = xxx, AccessHash = yyyyy}, "This is My Message");

If you don't know the access hash , just try to resolve the user with username or phone number. 如果您不知道访问哈希,请尝试使用用户名或电话号码解析用户。 (TLUser class) (TLUser类)

If you have the TLUser object you can use this : 如果您拥有TLUser对象,则可以使用以下命令:

UserId = user.Id
AccessHash = user.AccessHash.Value

Best regards. 最好的祝福。

Use this to import a list of contacts by mobile number: 使用此工具可以通过手机号码导入联系人列表:

contacts.importContacts#da30b32d contacts:Vector<InputContact> replace:Bool = contacts.ImportedContacts;

Use this to resolve by username: 使用它来按用户名解析:

contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM