steavy29 / Telegram.Net

Telegram (http://telegram.org) client library implemented in C#.
17 stars 6 forks source link

Error when trying to send a message #24

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello,

I am trying to send a message to a telegram bot using the following code:

   public async Task SendMessageByUserName(TelegramClient client, string command)
    {
        var user = await client.ResolveUsername(userName) as UserForeignConstructor;
        var peer = new InputPeerForeignConstructor() { userId = user.id };
        var message = await client.SendMessage(peer, command);
    }

I am getting the following error: {"BadRequest - PEER_ID_INVALID"} Would you please clarify what I am doing wrong?

I also see that there is the second parameter in the InputPeerForeignConstructor class (accessHash) but I am not sure how to get it and whether I need it.

Thanks

ghost commented 7 years ago

RESOLVED. This is the correct code: var peer = new InputPeerForeignConstructor(user.id, user.accessHash);

steavy29 commented 7 years ago

Yes, for such contracts you should use constructors, they'll give you a correct list of fields needed for creation. Empty constructors are mainly supported for internal needs like object creation via reflection.