Arman92 / go-tdlib

Golang Telegram TdLib JSON bindings
GNU General Public License v3.0
436 stars 100 forks source link

How to get supergroup_id in *tdlib.Chat #49

Open Lifelong-Study opened 4 years ago

Lifelong-Study commented 4 years ago

Hello guys, I want get supergroup info, but I don't know how to get the supergroup_id form *tdlib.Chat

My develop language is: Golang

Lifelong-Study commented 4 years ago

share how to get supergroup_id

import "github.com/fatih/structs"

// Code
chat, err := client.GetChat(chatID)
if err != nil {
    panic(err)
}

if chat.Type.GetChatTypeEnum() == tdlib.ChatTypeSupergroupType {

    Map          := structs.Map(chat)
    Type         := Map["Type"].(map[string]interface {})
    SupergroupID     := Type["SupergroupID"].(int32)
    IsChannel    := Type["IsChannel"].(bool)

    log.Printf("%s: %v, %d", chat.Title, IsChannel, SupergroupID)

    group, err := client.GetSupergroup(SupergroupID)
    if err != nil {
        panic(err)
    }

    log.Print(group.Username)
}