Advanced

Forums & topics

Forum mode turns a supergroup into a topic-based forum. Each topic is a separate thread with its own message list and own pinned messages. Same TL methods as regular groups, plus a topic id on every send.

Forum mode

Forum mode is a flag on a supergroup. When on, messages are organised by topic; users see a sidebar of topics and pick which to read. Each topic gets its own pinned messages and its own "read up to" bookmark.

Forum mode requires the supergroup to have at least 200 members or to be a public supergroup, then can be flipped via EnableForum / DisableForum if you are an admin with appropriate rights.

// tabs=true shows the sidebar; false keeps the classic layout
if err := client.EnableForum("@my_forum", true); err != nil {
	log.Fatal(err)
}
// later:
client.DisableForum("@my_forum")
// tabs=true shows the sidebar; false keeps the classic layout
if err := client.EnableForum("@my_forum", true); err != nil {
	log.Fatal(err)
}
// later:
client.DisableForum("@my_forum")

Creating topics

topicID, err := client.CreateTopic("@my_forum", "Random", &telegram.CreateTopicOptions{
	IconColor:   0x6FB9F0,
	IconEmojiID: 0,
})

fmt.Println("topic id:", topicID)
topicID, err := client.CreateTopic("@my_forum", "Random", &telegram.CreateTopicOptions{
	IconColor:   0x6FB9F0,
	IconEmojiID: 0,
})

fmt.Println("topic id:", topicID)

IconColor is one of the documented header colours; IconEmojiID is a custom emoji document id for the topic icon. Topic id 1is always "General" and cannot be deleted.

Listing topics

topics, err := client.ListTopics("@my_forum")
for _, t := range topics {
	if obj, ok := t.(*telegram.ForumTopicObj); ok {
		fmt.Println(obj.ID, obj.Title)
	}
}
topics, err := client.ListTopics("@my_forum")
for _, t := range topics {
	if obj, ok := t.(*telegram.ForumTopicObj); ok {
		fmt.Println(obj.ID, obj.Title)
	}
}

ListTopics paginates via ListTopicsOptions(OffsetDate, OffsetID, OffsetTopic, Limit, Query). For a fixed set of ids use GetTopics(channel, ids...).

Posting into a topic

client.SendMessage("@my_forum", "first post", &telegram.SendOptions{
	TopicID: topicID,
})
client.SendMessage("@my_forum", "first post", &telegram.SendOptions{
	TopicID: topicID,
})

SendOptions.TopicID is honoured by every send method (SendMessage, SendMedia, SendAlbum, …). Skip it and the message goes to General.

Closing and pinning

closed := true
client.EditTopic("@my_forum", topicID, &telegram.EditTopicOptions{
	Closed: &closed,
})
// shorthand:
client.CloseTopic("@my_forum", topicID)
client.ReopenTopic("@my_forum", topicID)
closed := true
client.EditTopic("@my_forum", topicID, &telegram.EditTopicOptions{
	Closed: &closed,
})
// shorthand:
client.CloseTopic("@my_forum", topicID)
client.ReopenTopic("@my_forum", topicID)

Closing a topic prevents new posts but leaves existing ones visible. PinTopic / UnpinTopic control the pinned strip; HideTopic / UnhideTopic hide the topic from the list without deleting it. DeleteTopic wipes the topic and its messages permanently.