skip to Main Content

I use Client.Channels_InviteToChannel but it asks for access_hash.
How do I suppose to get access_hash if I never interacted with bot before ?

Note that I’m admin of channel. Also have bot’s token.
I can do that manually using telegram app.

Dim BotFullUser = Await Client.Users_GetFullUser(New InputUser(BotId, 0)) 
'FAILS HERE
'TL.RpcException: 400 USER_ID_INVALID

Dim BotUser = New InputUser(BotId, BotFullUser.users.ElementAt(0).Value.access_hash)
Dim Ch = "{channel_id}:{channel_hash}".Split(":")
Await Client.Channels_InviteToChannel(New InputChannel(Long.Parse(Ch(0)), Long.Parse(Ch(1))), BotUser)

Edit: Second attempt:

Dim BotUser = (Await Client.Contacts_ResolveUsername(BotUserName)).User

Dim Ch = "{channel_id}:{channel_hash}".Split(":")
Await Client.Channels_InviteToChannel(New InputChannel(Long.Parse(Ch(0)), Long.Parse(Ch(1))), BotUser)
'FAILS HERE
'TL.RpcException: 400 USER_BOT

2

Answers


  1. Chosen as BEST ANSWER

    This works now. Actually we can't add bot without making admin. So just Channels_EditAdmin is enough to invite bot.

    Dim BotUsername = ...
    Dim channelId = ...
    Dim Channel_Access_Hash = ...
    
    Dim Bot = Client.Contacts_ResolveUsername(BotUsername)
    Dim InputChanell = New InputChannel(channelId, Channel_Access_Hash)
    Dim C = Await Client.Channels_GetFullChannel(InputChanell)
    Dim PreviewChannel = C.chats.First.Value
    Dim channel = CType(PreviewChannel, Channel)
    Await Client.Channels_EditAdmin(InputChanell, user, channel.admin_rights, "Administrator")
    

    Thanks @Wizou for help


  2. use Contacts_ResolveUsername to get user structure for your bot

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