0

How i can send message to new user via WTelegramClient?

var peer = new InputPeerUser(user.id,user.access_hash);
await _client.SendMessageAsync(peer, "hello");

it returns peer_id_invalid. Why?

Wizou
  • 1,336
  • 13
  • 24
Deegar
  • 1
  • 2
  • Are the `user.id` and `user.access_hash` valid? – Raptor Apr 13 '22 at 02:21
  • User ID is not the same as Peer ID. The object `InputUser` (https://core.telegram.org/type/InputUser) is not the same as `InputPeer` (https://core.telegram.org/type/InputPeer). Peer is from a conversation / channel / group. – Raptor Apr 13 '22 at 02:48
  • hash:-3709500452336328166 :userid 5286202569 ------------------------------------------- hash:9103130622756797784 :userid 5201338903 ------------------------------------------- user is from group or channel! – Deegar Apr 13 '22 at 02:50

1 Answers1

0

It depends where the user id/access_hash are coming. A user access_hash is valid only on the logged-in account it was retrieved from.

Also, with WTelegramClient, you do not need to build InputPeerUser manually, just pass a User object where an InputPeerUser is expected, and that structure will be created for you implicitly.

So the solution is to fetch the User structure you want, using any API calls or Updates monitoring, and use that User on your SendMessageAsync call.

For more information, read this FAQ

Wizou
  • 1,336
  • 13
  • 24