Skip to content

Commit 24d4f79

Browse files
committed
Updates for Bot API 5.1.
1 parent 4064ced commit 24d4f79

File tree

3 files changed

+209
-16
lines changed

3 files changed

+209
-16
lines changed

configs.go

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ func (config UnbanChatMemberConfig) params() (Params, error) {
10671067
// KickChatMemberConfig contains extra fields to kick user
10681068
type KickChatMemberConfig struct {
10691069
ChatMemberConfig
1070-
UntilDate int64
1070+
UntilDate int64
1071+
RevokeMessages bool
10711072
}
10721073

10731074
func (config KickChatMemberConfig) method() string {
@@ -1080,6 +1081,7 @@ func (config KickChatMemberConfig) params() (Params, error) {
10801081
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
10811082
params.AddNonZero("user_id", config.UserID)
10821083
params.AddNonZero64("until_date", config.UntilDate)
1084+
params.AddBool("revoke_messages", config.RevokeMessages)
10831085

10841086
return params, nil
10851087
}
@@ -1110,15 +1112,17 @@ func (config RestrictChatMemberConfig) params() (Params, error) {
11101112
// PromoteChatMemberConfig contains fields to promote members of chat
11111113
type PromoteChatMemberConfig struct {
11121114
ChatMemberConfig
1113-
IsAnonymous bool
1114-
CanChangeInfo bool
1115-
CanPostMessages bool
1116-
CanEditMessages bool
1117-
CanDeleteMessages bool
1118-
CanInviteUsers bool
1119-
CanRestrictMembers bool
1120-
CanPinMessages bool
1121-
CanPromoteMembers bool
1115+
IsAnonymous bool
1116+
CanManageChat bool
1117+
CanChangeInfo bool
1118+
CanPostMessages bool
1119+
CanEditMessages bool
1120+
CanDeleteMessages bool
1121+
CanManageVoiceChats bool
1122+
CanInviteUsers bool
1123+
CanRestrictMembers bool
1124+
CanPinMessages bool
1125+
CanPromoteMembers bool
11221126
}
11231127

11241128
func (config PromoteChatMemberConfig) method() string {
@@ -1132,10 +1136,12 @@ func (config PromoteChatMemberConfig) params() (Params, error) {
11321136
params.AddNonZero("user_id", config.UserID)
11331137

11341138
params.AddBool("is_anonymous", config.IsAnonymous)
1139+
params.AddBool("can_manage_chat", config.CanManageChat)
11351140
params.AddBool("can_change_info", config.CanChangeInfo)
11361141
params.AddBool("can_post_messages", config.CanPostMessages)
11371142
params.AddBool("can_edit_messages", config.CanEditMessages)
11381143
params.AddBool("can_delete_messages", config.CanDeleteMessages)
1144+
params.AddBool("can_manage_voice_chats", config.CanManageVoiceChats)
11391145
params.AddBool("can_invite_users", config.CanInviteUsers)
11401146
params.AddBool("can_restrict_members", config.CanRestrictMembers)
11411147
params.AddBool("can_pin_messages", config.CanPinMessages)
@@ -1246,6 +1252,77 @@ func (config ChatInviteLinkConfig) params() (Params, error) {
12461252
return params, nil
12471253
}
12481254

1255+
// CreateChatInviteLinkConfig allows you to create an additional invite link for
1256+
// a chat. The bot must be an administrator in the chat for this to work and
1257+
// must have the appropriate admin rights. The link can be revoked using the
1258+
// RevokeChatInviteLinkConfig.
1259+
type CreateChatInviteLinkConfig struct {
1260+
ChatConfig
1261+
ExpireDate int
1262+
MemberLimit int
1263+
}
1264+
1265+
func (CreateChatInviteLinkConfig) method() string {
1266+
return "createChatInviteLink"
1267+
}
1268+
1269+
func (config CreateChatInviteLinkConfig) params() (Params, error) {
1270+
params := make(Params)
1271+
1272+
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1273+
params.AddNonZero("expire_date", config.ExpireDate)
1274+
params.AddNonZero("member_limit", config.MemberLimit)
1275+
1276+
return params, nil
1277+
}
1278+
1279+
// EditChatInviteLinkConfig allows you to edit a non-primary invite link created
1280+
// by the bot. The bot must be an administrator in the chat for this to work and
1281+
// must have the appropriate admin rights.
1282+
type EditChatInviteLinkConfig struct {
1283+
ChatConfig
1284+
InviteLink string
1285+
ExpireDate int
1286+
MemberLimit int
1287+
}
1288+
1289+
func (EditChatInviteLinkConfig) method() string {
1290+
return "editChatInviteLink"
1291+
}
1292+
1293+
func (config EditChatInviteLinkConfig) params() (Params, error) {
1294+
params := make(Params)
1295+
1296+
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1297+
params["invite_link"] = config.InviteLink
1298+
params.AddNonZero("expire_date", config.ExpireDate)
1299+
params.AddNonZero("member_limit", config.MemberLimit)
1300+
1301+
return params, nil
1302+
}
1303+
1304+
// RevokeChatInviteLinkConfig allows you to revoke an invite link created by the
1305+
// bot. If the primary link is revoked, a new link is automatically generated.
1306+
// The bot must be an administrator in the chat for this to work and must have
1307+
// the appropriate admin rights.
1308+
type RevokeChatInviteLinkConfig struct {
1309+
ChatConfig
1310+
InviteLink string
1311+
}
1312+
1313+
func (RevokeChatInviteLinkConfig) method() string {
1314+
return "revokeChatInviteLink"
1315+
}
1316+
1317+
func (config RevokeChatInviteLinkConfig) params() (Params, error) {
1318+
params := make(Params)
1319+
1320+
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1321+
params["invite_link"] = config.InviteLink
1322+
1323+
return params, nil
1324+
}
1325+
12491326
// LeaveChatConfig allows you to leave a chat.
12501327
type LeaveChatConfig struct {
12511328
ChatID int64
@@ -1885,8 +1962,9 @@ func (config SetMyCommandsConfig) params() (Params, error) {
18851962
type DiceConfig struct {
18861963
BaseChat
18871964
// Emoji on which the dice throw animation is based.
1888-
// Currently, must be one of “🎲”, “🎯”, or “🏀”.
1889-
// Dice can have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”.
1965+
// Currently, must be one of 🎲, 🎯, 🏀, ⚽, 🎳, or 🎰.
1966+
// Dice can have values 1-6 for 🎲, 🎯, and 🎳, values 1-5 for 🏀 and ⚽,
1967+
// and values 1-64 for 🎰.
18901968
// Defaults to “🎲”
18911969
Emoji string
18921970
}

types.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ type Update struct {
9696
//
9797
// optional
9898
PollAnswer *PollAnswer `json:"poll_answer,omitempty"`
99+
// MyChatMember is the bot's chat member status was updated in a chat. For
100+
// private chats, this update is received only when the bot is blocked or
101+
// unblocked by the user.
102+
//
103+
// optional
104+
MyChatMember *ChatMemberUpdated `json:"my_chat_member"`
105+
// ChatMember is a chat member's status was updated in a chat. The bot must
106+
// be an administrator in the chat and must explicitly specify "chat_member"
107+
// in the list of allowed_updates to receive these updates.
108+
//
109+
// optional
110+
ChatMember *ChatMemberUpdated `json:"chat_member"`
99111
}
100112

101113
// UpdatesChannel is the channel for getting updates.
@@ -463,6 +475,11 @@ type Message struct {
463475
//
464476
// optional
465477
ChannelChatCreated bool `json:"channel_chat_created,omitempty"`
478+
// MessageAutoDeleteTimerChanged is a service message: auto-delete timer
479+
// settings changed in the chat.
480+
//
481+
// optional
482+
MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed"`
466483
// MigrateToChatID is the group has been migrated to a supergroup with the specified identifier.
467484
// This number may be greater than 32 bits and some programming languages
468485
// may have difficulty/silent defects in interpreting it.
@@ -508,6 +525,19 @@ type Message struct {
508525
//
509526
// optional
510527
ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered"`
528+
// VoiceChatStarted is a service message: voice chat started.
529+
//
530+
// optional
531+
VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started"`
532+
// VoiceChatEnded is a service message: voice chat ended.
533+
//
534+
// optional
535+
VoiceChatEnded *VoiceChatEnded `json:"voice_chat_ended"`
536+
// VoiceChatParticipantsInvited is a service message: new participants
537+
// invited to a voice chat.
538+
//
539+
// optional
540+
VoiceChatParticipantsInvited *VoiceChatParticipantsInvited `json:"voice_chat_participants_invited"`
511541
// ReplyMarkup is the Inline keyboard attached to the message.
512542
// login_url buttons are represented as ordinary url buttons.
513543
//
@@ -1037,6 +1067,33 @@ type ProximityAlertTriggered struct {
10371067
Distance int `json:"distance"`
10381068
}
10391069

1070+
// MessageAutoDeleteTimerChanged represents a service message about a change in
1071+
// auto-delete timer settings.
1072+
type MessageAutoDeleteTimerChanged struct {
1073+
// New auto-delete time for messages in the chat.
1074+
MessageAutoDeleteTime int `json:"message_auto_delete_time"`
1075+
}
1076+
1077+
// VoiceChatStarted represents a service message about a voice chat started in
1078+
// the chat.
1079+
type VoiceChatStarted struct{}
1080+
1081+
// VoiceChatEnded represents a service message about a voice chat ended in the
1082+
// chat.
1083+
type VoiceChatEnded struct {
1084+
// Voice chat duration; in seconds.
1085+
Duration int `json:"duration"`
1086+
}
1087+
1088+
// VoiceChatParticipantsInvited represents a service message about new members
1089+
// invited to a voice chat.
1090+
type VoiceChatParticipantsInvited struct {
1091+
// New members that were invited to the voice chat.
1092+
//
1093+
// optional
1094+
Users []User `json:"users"`
1095+
}
1096+
10401097
// UserProfilePhotos contains a set of user profile photos.
10411098
type UserProfilePhotos struct {
10421099
// TotalCount total number of profile pictures the target user has
@@ -1336,6 +1393,29 @@ type ChatPhoto struct {
13361393
BigFileUniqueID string `json:"big_file_unique_id"`
13371394
}
13381395

1396+
// ChatInviteLink represents an invite link for a chat.
1397+
type ChatInviteLink struct {
1398+
// InviteLink is the invite link. If the link was created by another chat
1399+
// administrator, then the second part of the link will be replaced with “…”.
1400+
InviteLink string `json:"invite_link"`
1401+
// Creator of the link.
1402+
Creator User `json:"creator"`
1403+
// IsPrimary is true, if the link is primary.
1404+
IsPrimary bool `json:"is_primary"`
1405+
// IsRevoked is true, if the link is revoked.
1406+
IsRevoked bool `json:"is_revoked"`
1407+
// ExpireDate is the point in time (Unix timestamp) when the link will
1408+
// expire or has been expired.
1409+
//
1410+
// optional
1411+
ExpireDate int `json:"expire_date"`
1412+
// MemberLimit is the maximum number of users that can be members of the
1413+
// chat simultaneously after joining the chat via this invite link; 1-99999.
1414+
//
1415+
// optional
1416+
MemberLimit int `json:"member_limit"`
1417+
}
1418+
13391419
// ChatMember contains information about one member of a chat.
13401420
type ChatMember struct {
13411421
// User information about the user
@@ -1369,6 +1449,14 @@ type ChatMember struct {
13691449
//
13701450
// optional
13711451
CanBeEdited bool `json:"can_be_edited,omitempty"`
1452+
// CanManageChat administrators only.
1453+
// True, if the administrator can access the chat event log, chat
1454+
// statistics, message statistics in channels, see channel members, see
1455+
// anonymous administrators in supergoups and ignore slow mode. Implied by
1456+
// any other administrator privilege.
1457+
//
1458+
// optional
1459+
CanManageChat bool `json:"can_manage_chat"`
13721460
// CanPostMessages administrators only.
13731461
// True, if the administrator can post in the channel;
13741462
// channels only.
@@ -1386,6 +1474,11 @@ type ChatMember struct {
13861474
//
13871475
// optional
13881476
CanDeleteMessages bool `json:"can_delete_messages,omitempty"`
1477+
// CanManageVoiceChats administrators only.
1478+
// True, if the administrator can manage voice chats.
1479+
//
1480+
// optional
1481+
CanManageVoiceChats bool `json:"can_manage_voice_chats"`
13891482
// CanRestrictMembers administrators only.
13901483
// True, if the administrator can restrict, ban or unban chat members.
13911484
//
@@ -1455,6 +1548,25 @@ func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
14551548
// WasKicked returns if the ChatMember was kicked from the chat.
14561549
func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
14571550

1551+
// ChatMemberUpdated represents changes in the status of a chat member.
1552+
type ChatMemberUpdated struct {
1553+
// Chat the user belongs to.
1554+
Chat Chat `json:"chat"`
1555+
// From is the performer of the action, which resulted in the change.
1556+
From User `json:"from"`
1557+
// Date the change was done in Unix time.
1558+
Date int `json:"date"`
1559+
// Previous information about the chat member.
1560+
OldChatMember ChatMember `json:"old_chat_member"`
1561+
// New information about the chat member.
1562+
NewChatMember ChatMember `json:"new_chat_member"`
1563+
// InviteLink is the link which was used by the user to join the chat;
1564+
// for joining by invite link events only.
1565+
//
1566+
// optional
1567+
InviteLink *ChatInviteLink `json:"invite_link"`
1568+
}
1569+
14581570
// ChatPermissions describes actions that a non-administrator user is
14591571
// allowed to take in a chat. All fields are optional.
14601572
type ChatPermissions struct {

types_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,20 @@ var (
282282
_ Chattable = AnimationConfig{}
283283
_ Chattable = AudioConfig{}
284284
_ Chattable = CallbackConfig{}
285-
_ Chattable = ChatAdministratorsConfig{}
286285
_ Chattable = ChatActionConfig{}
286+
_ Chattable = ChatAdministratorsConfig{}
287287
_ Chattable = ChatInfoConfig{}
288288
_ Chattable = ChatInviteLinkConfig{}
289289
_ Chattable = CloseConfig{}
290-
_ Chattable = CopyMessageConfig{}
291290
_ Chattable = ContactConfig{}
291+
_ Chattable = CopyMessageConfig{}
292+
_ Chattable = CreateChatInviteLinkConfig{}
292293
_ Chattable = DeleteChatPhotoConfig{}
293294
_ Chattable = DeleteChatStickerSetConfig{}
294295
_ Chattable = DeleteMessageConfig{}
296+
_ Chattable = DeleteWebhookConfig{}
295297
_ Chattable = DocumentConfig{}
298+
_ Chattable = EditChatInviteLinkConfig{}
296299
_ Chattable = EditMessageCaptionConfig{}
297300
_ Chattable = EditMessageLiveLocationConfig{}
298301
_ Chattable = EditMessageMediaConfig{}
@@ -315,17 +318,17 @@ var (
315318
_ Chattable = PinChatMessageConfig{}
316319
_ Chattable = PreCheckoutConfig{}
317320
_ Chattable = PromoteChatMemberConfig{}
318-
_ Chattable = DeleteWebhookConfig{}
319321
_ Chattable = RestrictChatMemberConfig{}
322+
_ Chattable = RevokeChatInviteLinkConfig{}
320323
_ Chattable = SendPollConfig{}
321324
_ Chattable = SetChatDescriptionConfig{}
322325
_ Chattable = SetChatPhotoConfig{}
323326
_ Chattable = SetChatTitleConfig{}
324327
_ Chattable = SetGameScoreConfig{}
325328
_ Chattable = ShippingConfig{}
326329
_ Chattable = StickerConfig{}
327-
_ Chattable = StopPollConfig{}
328330
_ Chattable = StopMessageLiveLocationConfig{}
331+
_ Chattable = StopPollConfig{}
329332
_ Chattable = UnbanChatMemberConfig{}
330333
_ Chattable = UnpinChatMessageConfig{}
331334
_ Chattable = UpdateConfig{}

0 commit comments

Comments
 (0)