Documentation
¶
Overview ¶
This package is designed to work with supergroup topics and to send messages to specific topics instead of sending messages to the main supergroup topic.
Use NewBot to initialize the API
Index ¶
- Constants
- Variables
- type Bot
- func (b *Bot) AsyncSendMessage(ctx context.Context, onError ErrorHandlerFunc, messageText string, ...)
- func (b *Bot) AsyncSendMessageToChat(ctx context.Context, onError ErrorHandlerFunc, chatID ChatID, ...)
- func (b *Bot) AsyncSendMessageToTopic(ctx context.Context, onError ErrorHandlerFunc, topicName TopicName, ...)
- func (b *Bot) AsyncSendMessageToTopicByChatID(ctx context.Context, onError ErrorHandlerFunc, chatID ChatID, ...)
- func (b *Bot) AsyncSendMessageToTopicByID(ctx context.Context, onError ErrorHandlerFunc, chatID ChatID, ...)
- func (b *Bot) Close() error
- func (b *Bot) PreloadChatTopics(ctx context.Context, chatIDs ...ChatID) error
- func (b *Bot) SendMessage(ctx context.Context, messageText string, args ...interface{}) error
- func (b *Bot) SendMessageToChat(ctx context.Context, chatID ChatID, messageText string, args ...interface{}) error
- func (b *Bot) SendMessageToTopic(ctx context.Context, topicName TopicName, messageText string, ...) error
- func (b *Bot) SendMessageToTopicByChatID(ctx context.Context, chatID ChatID, topicName TopicName, messageText string, ...) error
- func (b *Bot) SendMessageToTopicByID(ctx context.Context, chatID ChatID, topicID TopicThreadID, messageText string, ...) error
- type Chat
- type ChatID
- type ErrorHandlerFunc
- type Option
- type ParseMode
- type Storage
- type Topic
- type TopicName
- type TopicThreadID
- type Topics
Constants ¶
const ( ParseModeHTML = types.ParseModeHTML ParseModeMarkdown = types.ParseModeMarkdown ParseModeMarkdownV2 = types.ParseModeMarkdownV2 SuperGroupType = types.SuperGroupType )
const RedisKeyAsset = "TGSGroups:%d" // ChatID
Variables ¶
var ( NewTopic = types.NewTopic EmptyThreadID = types.EmptyTopicID )
Functions ¶
This section is empty.
Types ¶
type Bot ¶
Main structure for operand topics.
Main method : SendMessageToTopicByChatID
The method calls the telegram API, which is responsible for sending a message to a specific topic, and for that it needs the ThreadID of the chat, not the chat name. To find a id, bot has 3 levels of get this id.
The first one is local, the bot hashes chats and topics in the group.
The second is Storage, which stores the group's tops in any database. The library already implements storage using Redis. Storage is configured with the WithStorage option. To get storage via Redis, use the NewRedisStorage function Otherwise, if nothing is found, the bot finds the right topic by enumerating the IDs. The maximum standard value is 100, but this is Option WithMaxSpamThreadIDs
If the desired chat is not found, a new one is created. Make sure that the bot has enough permissions to create topics.
func NewBotsGroup ¶ added in v1.0.3
func (*Bot) AsyncSendMessage ¶
func (b *Bot) AsyncSendMessage(ctx context.Context, onError ErrorHandlerFunc, messageText string, args ...interface{})
Async version of SendMessage
func (*Bot) AsyncSendMessageToChat ¶
func (b *Bot) AsyncSendMessageToChat( ctx context.Context, onError ErrorHandlerFunc, chatID ChatID, messageText string, args ...interface{}, )
Async version of SendMessageToChat
func (*Bot) AsyncSendMessageToTopic ¶
func (b *Bot) AsyncSendMessageToTopic( ctx context.Context, onError ErrorHandlerFunc, topicName TopicName, messageText string, args ...interface{}, )
Async version of SendMessageToTopic
func (*Bot) AsyncSendMessageToTopicByChatID ¶
func (b *Bot) AsyncSendMessageToTopicByChatID( ctx context.Context, onError ErrorHandlerFunc, chatID ChatID, topicName TopicName, messageText string, args ...interface{}, )
Async version of SendMessageToTopicByChatID
func (*Bot) AsyncSendMessageToTopicByID ¶
func (b *Bot) AsyncSendMessageToTopicByID( ctx context.Context, onError ErrorHandlerFunc, chatID ChatID, topicID TopicThreadID, messageText string, args ...interface{}, )
Async version of SendMessageToTopicByID
func (*Bot) PreloadChatTopics ¶
Preload Chat Topics using Storage
func (*Bot) SendMessage ¶
Just send message to prepared chatID
func (*Bot) SendMessageToChat ¶
func (b *Bot) SendMessageToChat(ctx context.Context, chatID ChatID, messageText string, args ...interface{}) error
Just send message to chatID
func (*Bot) SendMessageToTopic ¶
func (b *Bot) SendMessageToTopic( ctx context.Context, topicName TopicName, messageText string, args ...interface{}, ) error
Use this method if you provided chatID in the options during initialization.
Otherwise, use SendMessageToTopicByChatID method.
func (*Bot) SendMessageToTopicByChatID ¶
func (b *Bot) SendMessageToTopicByChatID( ctx context.Context, chatID ChatID, topicName TopicName, messageText string, args ...interface{}, ) error
Sends a message to a group's topic by its name.
func (*Bot) SendMessageToTopicByID ¶
func (b *Bot) SendMessageToTopicByID( ctx context.Context, chatID ChatID, topicID TopicThreadID, messageText string, args ...interface{}, ) error
May be useful if you have a threadID
type ErrorHandlerFunc ¶
Handler type for async versions of sending messages
type Option ¶
type Option func(*Bot)
List: WithHTTPClient, WithStorage, WithChatID, WithMaxSpamThreadIDs, WithContext, WithParseMode, WithBotName
func WithChatID ¶
Configure default chatID, if you need to operand only with this chat.
func WithContext ¶
Configure context.Context. Default: context.Background
func WithHTTPClient ¶
Configure http.Client. Default: http.DefaultClient
func WithMaxSpamThreadIDs ¶
Configure max attemps to find a need topic. Default: 100
func WithParseMode ¶
Configure ParseMode. Default: ParseModeMarkdownV2
func WithStorage ¶
Configure Storage to save TopicThreadID. Use NewRedisStorage if you're comfortable using redis.
May be nil. (No Storage)
type Storage ¶
type Storage interface {
GetAll(ctx context.Context, chatID ChatID) (*Topics, error)
Save(ctx context.Context, topic *Topic) error
GetByName(ctx context.Context, chatID ChatID, name TopicName) (*Topic, error)
}
func NewRedisStorage ¶
func NewRedisStorage(client redis.UniversalClient) Storage
Initiates Storage using the redis.Client
type TopicThreadID ¶
type TopicThreadID = types.TopicThreadID