Skip to content

Commit 10a9f26

Browse files
committed
Implement Bot API 6.0 changes.
1 parent f399a24 commit 10a9f26

File tree

4 files changed

+228
-30
lines changed

4 files changed

+228
-30
lines changed

bot.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,7 @@ func (bot *BotAPI) GetMyCommandsWithConfig(config GetMyCommandsConfig) ([]BotCom
681681
// forwardMessage, but the copied message doesn't have a link to the original
682682
// message. Returns the MessageID of the sent message on success.
683683
func (bot *BotAPI) CopyMessage(config CopyMessageConfig) (MessageID, error) {
684-
params, err := config.params()
685-
if err != nil {
686-
return MessageID{}, err
687-
}
688-
689-
resp, err := bot.MakeRequest(config.method(), params)
684+
resp, err := bot.Request(config)
690685
if err != nil {
691686
return MessageID{}, err
692687
}
@@ -697,6 +692,33 @@ func (bot *BotAPI) CopyMessage(config CopyMessageConfig) (MessageID, error) {
697692
return messageID, err
698693
}
699694

695+
// AnswerWebAppQuery sets the result of an interaction with a Web App and send a
696+
// corresponding message on behalf of the user to the chat from which the query originated.
697+
func (bot *BotAPI) AnswerWebAppQuery(config AnswerWebAppQueryConfig) (SentWebAppMessage, error) {
698+
var sentWebAppMessage SentWebAppMessage
699+
700+
resp, err := bot.Request(config)
701+
if err != nil {
702+
return sentWebAppMessage, err
703+
}
704+
705+
err = json.Unmarshal(resp.Result, &sentWebAppMessage)
706+
return sentWebAppMessage, err
707+
}
708+
709+
// GetMyDefaultAdministratorRights gets the current default administrator rights of the bot.
710+
func (bot *BotAPI) GetMyDefaultAdministratorRights(config GetMyDefaultAdministratorRightsConfig) (ChatAdministratorRights, error) {
711+
var rights ChatAdministratorRights
712+
713+
resp, err := bot.Request(config)
714+
if err != nil {
715+
return rights, err
716+
}
717+
718+
err = json.Unmarshal(resp.Result, &rights)
719+
return rights, err
720+
}
721+
700722
// EscapeText takes an input text and escape Telegram markup symbols.
701723
// In this way we can send a text without being afraid of having to escape the characters manually.
702724
// Note that you don't have to include the formatting style in the input text, or it will be escaped too.

configs.go

+100-2
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,29 @@ func (config InlineConfig) params() (Params, error) {
12421242
return params, err
12431243
}
12441244

1245+
// AnswerWebAppQueryConfig is used to set the result of an interaction with a
1246+
// Web App and send a corresponding message on behalf of the user to the chat
1247+
// from which the query originated.
1248+
type AnswerWebAppQueryConfig struct {
1249+
// WebAppQueryID is the unique identifier for the query to be answered.
1250+
WebAppQueryID string `json:"web_app_query_id"`
1251+
// Result is an InlineQueryResult object describing the message to be sent.
1252+
Result interface{} `json:"result"`
1253+
}
1254+
1255+
func (config AnswerWebAppQueryConfig) method() string {
1256+
return "answerWebAppQuery"
1257+
}
1258+
1259+
func (config AnswerWebAppQueryConfig) params() (Params, error) {
1260+
params := make(Params)
1261+
1262+
params["web_app_query_id"] = config.WebAppQueryID
1263+
err := params.AddInterface("result", config.Result)
1264+
1265+
return params, err
1266+
}
1267+
12451268
// CallbackConfig contains information on making a CallbackQuery response.
12461269
type CallbackConfig struct {
12471270
CallbackQueryID string `json:"callback_query_id"`
@@ -1355,7 +1378,7 @@ type PromoteChatMemberConfig struct {
13551378
CanPostMessages bool
13561379
CanEditMessages bool
13571380
CanDeleteMessages bool
1358-
CanManageVoiceChats bool
1381+
CanManageVideoChats bool
13591382
CanInviteUsers bool
13601383
CanRestrictMembers bool
13611384
CanPinMessages bool
@@ -1378,7 +1401,7 @@ func (config PromoteChatMemberConfig) params() (Params, error) {
13781401
params.AddBool("can_post_messages", config.CanPostMessages)
13791402
params.AddBool("can_edit_messages", config.CanEditMessages)
13801403
params.AddBool("can_delete_messages", config.CanDeleteMessages)
1381-
params.AddBool("can_manage_voice_chats", config.CanManageVoiceChats)
1404+
params.AddBool("can_manage_video_chats", config.CanManageVideoChats)
13821405
params.AddBool("can_invite_users", config.CanInviteUsers)
13831406
params.AddBool("can_restrict_members", config.CanRestrictMembers)
13841407
params.AddBool("can_pin_messages", config.CanPinMessages)
@@ -2315,6 +2338,81 @@ func (config DeleteMyCommandsConfig) params() (Params, error) {
23152338
return params, err
23162339
}
23172340

2341+
// SetChatMenuButtonConfig changes the bot's menu button in a private chat,
2342+
// or the default menu button.
2343+
type SetChatMenuButtonConfig struct {
2344+
ChatID int64
2345+
ChannelUsername string
2346+
2347+
MenuButton *MenuButton
2348+
}
2349+
2350+
func (config SetChatMenuButtonConfig) method() string {
2351+
return "setChatMenuButton"
2352+
}
2353+
2354+
func (config SetChatMenuButtonConfig) params() (Params, error) {
2355+
params := make(Params)
2356+
2357+
if err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername); err != nil {
2358+
return params, err
2359+
}
2360+
err := params.AddInterface("menu_button", config.MenuButton)
2361+
2362+
return params, err
2363+
}
2364+
2365+
type GetChatMenuButtonConfig struct {
2366+
ChatID int64
2367+
ChannelUsername string
2368+
}
2369+
2370+
func (config GetChatMenuButtonConfig) method() string {
2371+
return "getChatMenuButton"
2372+
}
2373+
2374+
func (config GetChatMenuButtonConfig) params() (Params, error) {
2375+
params := make(Params)
2376+
2377+
err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2378+
2379+
return params, err
2380+
}
2381+
2382+
type SetMyDefaultAdministratorRightsConfig struct {
2383+
Rights ChatAdministratorRights
2384+
ForChannels bool
2385+
}
2386+
2387+
func (config SetMyDefaultAdministratorRightsConfig) method() string {
2388+
return "setMyDefaultAdministratorRights"
2389+
}
2390+
2391+
func (config SetMyDefaultAdministratorRightsConfig) params() (Params, error) {
2392+
params := make(Params)
2393+
2394+
err := params.AddInterface("rights", config.Rights)
2395+
params.AddBool("for_channels", config.ForChannels)
2396+
2397+
return params, err
2398+
}
2399+
2400+
type GetMyDefaultAdministratorRightsConfig struct {
2401+
ForChannels bool
2402+
}
2403+
2404+
func (config GetMyDefaultAdministratorRightsConfig) method() string {
2405+
return "getMyDefaultAdministratorRights"
2406+
}
2407+
2408+
func (config GetMyDefaultAdministratorRightsConfig) params() (Params, error) {
2409+
params := make(Params)
2410+
2411+
params.AddBool("for_channels", config.ForChannels)
2412+
2413+
return params, nil
2414+
}
2415+
23182416
// prepareInputMediaParam evaluates a single InputMedia and determines if it
23192417
// needs to be modified for a successful upload. If it returns nil, then the
23202418
// value does not need to be included in the params. Otherwise, it will return

0 commit comments

Comments
 (0)