skip to Main Content

I’m using TLSharp to create a client for Telegram and i want to send messages to some telegram users.
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:

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.

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?

thanks in Advance.

2

Answers


  1. 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;
    
    Login or Signup to reply.
  2. I know that the thread is not active anymore but for who viewing this page in future :

    You need AccessHash to send message :

    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)

    If you have the TLUser object you can use this :

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

    Best regards.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search