Search code examples
gotelegram

Can't find the channel using tdlib with gogram


I'm using github.com/amarnathcjd/gogram/telegram to get channel messages, I've installed the tdlib build and I'm using this code:

func main() {
    client, err := telegram.NewClient(telegram.ClientConfig{
        AppID: appID, AppHash: appHash,
    })
    if err != nil {
        fmt.Println(err)
        return
    }

    client.Login(phone)

    tgchannel, err := client.GetChannel(channelIDint)
    if err != nil {
        fmt.Println(err)
        return
    }

    client.Idle() 
}

Login is fine. But when I try to get the channel I get this error message: no channel with id -10020055**** or missing from cache

I've tried to add a Join before, just in case:

    err = client.JoinChannel(channelIDint)
    if err != nil {
        fmt.Println(err)
        return
    }

but I get a similar error message: there is no peer with id 112094*** or missing from cache This id seems to omit the first three number and the minus (-100) of the channel id, don't know why.

What I'm missing?


Solution

  • In Telegram, channel IDs are typically represented in the format -100xxxxxxxxxx, where xxxxxxxxxx is the actual channel ID. However, based on this issue, it appears that the gogram library expects the channel ID to be provided as an integer without the -100 prefix.

    I dunno where u got the channelIDint but something like this piece of could should works:

    func main() {
        client, err := telegram.NewClient(telegram.ClientConfig{
            AppID: appID, AppHash: appHash,
        })
        if err != nil {
            fmt.Println(err)
            return
        }
    
        client.Login(phone)
    
        // remove the "-100" prefix from the channel ID
        channelIDint := 2005512345 // your actual channel ID without the "-100" prefix
    
        tgchannel, err := client.GetChannelFull(channelIDint)
        if err != nil {
            fmt.Println(err)
            return
        }
    
        // print the channel information
        fmt.Println(tgchannel.Title)
        fmt.Println(tgchannel.Description)
    
        client.Idle()
    }