Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions managed_bots.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tgbotapi

import (
"encoding/json"
"strconv"
)

// GetManagedBotToken retrieves the current token of a bot managed by this bot
// (Bot API 9.6+, Managed Bots). userID is the managed bot's own id (bots are
// Users in the Bot API's type system).
func (bot *BotAPI) GetManagedBotToken(userID int64) (string, error) {
params := Params{"user_id": strconv.FormatInt(userID, 10)}

resp, err := bot.MakeRequest("getManagedBotToken", params)
if err != nil {
return "", err
}

var token string
err = json.Unmarshal(resp.Result, &token)
return token, err
}

// ReplaceManagedBotToken rotates the token of a bot managed by this bot,
// invalidating the previous one (Bot API 9.6+, Managed Bots).
func (bot *BotAPI) ReplaceManagedBotToken(userID int64) (string, error) {
params := Params{"user_id": strconv.FormatInt(userID, 10)}

resp, err := bot.MakeRequest("replaceManagedBotToken", params)
if err != nil {
return "", err
}

var token string
err = json.Unmarshal(resp.Result, &token)
return token, err
}
31 changes: 31 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ type Update struct {
//
// optional
ChatJoinRequest *ChatJoinRequest `json:"chat_join_request,omitempty"`
// ManagedBot is the creation, token update, or owner update of a bot
// managed by the current bot (Bot API 9.6+, Managed Bots).
//
// optional
ManagedBot *ManagedBotUpdated `json:"managed_bot,omitempty"`
}

// SentFrom returns the user who sent an update. Can be nil, if Telegram did not provide information
Expand Down Expand Up @@ -217,6 +222,11 @@ type User struct {
//
// optional
SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"`
// CanManageBots is true, if other bots can be created to be controlled
// by this bot (Bot API 9.6+, Managed Bots). Returned only in getMe.
//
// optional
CanManageBots bool `json:"can_manage_bots,omitempty"`
}

// String displays a simple text version of a user.
Expand Down Expand Up @@ -563,6 +573,11 @@ type Message struct {
//
// optional
MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed,omitempty"`
// ManagedBotCreated is a service message: a bot was created to be
// managed by the current bot (Bot API 9.6+, Managed Bots).
//
// optional
ManagedBotCreated *ManagedBotCreated `json:"managed_bot_created,omitempty"`
// MigrateToChatID is the group has been migrated to a supergroup with the specified identifier.
// This number may be greater than 32 bits and some programming languages
// may have difficulty/silent defects in interpreting it.
Expand Down Expand Up @@ -1181,6 +1196,22 @@ type MessageAutoDeleteTimerChanged struct {
MessageAutoDeleteTime int `json:"message_auto_delete_time"`
}

// ManagedBotCreated contains information about a bot that was created to be
// managed by the current bot (Bot API 9.6+, Managed Bots).
type ManagedBotCreated struct {
// Bot is the newly created managed bot.
Bot User `json:"bot"`
}

// ManagedBotUpdated represents the creation, token update, or owner update of
// a bot managed by the current bot (Bot API 9.6+, Managed Bots).
type ManagedBotUpdated struct {
// User who owns the managed bot.
User User `json:"user"`
// Bot is the managed bot affected by this update.
Bot User `json:"bot"`
}

// VideoChatScheduled represents a service message about a voice chat scheduled
// in the chat.
type VideoChatScheduled struct {
Expand Down