Skip to content

Commit 05cb53e

Browse files
authored
Merge pull request #6 from OvyFlash/bot-api-6.5
Implement Bot API 6.5 changes.
2 parents 8c46c34 + 16635e5 commit 05cb53e

File tree

2 files changed

+210
-13
lines changed

2 files changed

+210
-13
lines changed

configs.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ func (config GetGameHighScoresConfig) method() string {
10221022
type ChatActionConfig struct {
10231023
BaseChat
10241024
MessageThreadID int
1025-
Action string // required
1025+
Action string // required
10261026
}
10271027

10281028
func (config ChatActionConfig) params() (Params, error) {
@@ -1400,8 +1400,9 @@ type KickChatMemberConfig = BanChatMemberConfig
14001400
// RestrictChatMemberConfig contains fields to restrict members of chat
14011401
type RestrictChatMemberConfig struct {
14021402
ChatMemberConfig
1403-
UntilDate int64
1404-
Permissions *ChatPermissions
1403+
UntilDate int64
1404+
UseIndependentChatPermissions bool
1405+
Permissions *ChatPermissions
14051406
}
14061407

14071408
func (config RestrictChatMemberConfig) method() string {
@@ -1413,6 +1414,7 @@ func (config RestrictChatMemberConfig) params() (Params, error) {
14131414

14141415
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
14151416
params.AddNonZero64("user_id", config.UserID)
1417+
params.AddBool("use_independent_chat_permissions", config.UseIndependentChatPermissions)
14161418

14171419
err := params.AddInterface("permissions", config.Permissions)
14181420
params.AddNonZero64("until_date", config.UntilDate)
@@ -1578,7 +1580,8 @@ func (ChatAdministratorsConfig) method() string {
15781580
// restrict members.
15791581
type SetChatPermissionsConfig struct {
15801582
ChatConfig
1581-
Permissions *ChatPermissions
1583+
UseIndependentChatPermissions bool
1584+
Permissions *ChatPermissions
15821585
}
15831586

15841587
func (SetChatPermissionsConfig) method() string {
@@ -1589,6 +1592,7 @@ func (config SetChatPermissionsConfig) params() (Params, error) {
15891592
params := make(Params)
15901593

15911594
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1595+
params.AddBool("use_independent_chat_permissions", config.UseIndependentChatPermissions)
15921596
err := params.AddInterface("permissions", config.Permissions)
15931597

15941598
return params, err

types.go

Lines changed: 202 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ type Chat struct {
340340
//
341341
// optional
342342
MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"`
343-
// HasAggressiveAntiSpamEnabled is true if aggressive anti-spam checks are enabled
344-
// in the supergroup. The field is only available to chat administrators.
343+
// HasAggressiveAntiSpamEnabled is true if aggressive anti-spam checks are enabled
344+
// in the supergroup. The field is only available to chat administrators.
345345
// Returned only in getChat.
346346
//
347347
// optional
@@ -654,6 +654,14 @@ type Message struct {
654654
//
655655
// optional
656656
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
657+
// UserShared is a service message: a user was shared with the bot
658+
//
659+
// optional
660+
UserShared *UserShared `json:"user_shared,omitempty"`
661+
// ChatShared is a service message: a chat was shared with the bot
662+
//
663+
// optional
664+
ChatShared *ChatShared `json:"chat_shared,omitempty"`
657665
// ConnectedWebsite is the domain name of the website on which the user has
658666
// logged in;
659667
//
@@ -1323,6 +1331,24 @@ type GeneralForumTopicHidden struct {
13231331
type GeneralForumTopicUnhidden struct {
13241332
}
13251333

1334+
// UserShared object contains information about the user whose identifier
1335+
// was shared with the bot using a KeyboardButtonRequestUser button.
1336+
type UserShared struct {
1337+
// RequestID is an indentifier of the request.
1338+
RequestID int `json:"request_id"`
1339+
// UserID in an identifier of the shared user.
1340+
UserID int64
1341+
}
1342+
1343+
// ChatShared contains information about the chat whose identifier
1344+
// was shared with the bot using a KeyboardButtonRequestChat button.
1345+
type ChatShared struct {
1346+
// RequestID is an indentifier of the request.
1347+
RequestID int `json:"request_id"`
1348+
// ChatID is an identifier of the shared chat.
1349+
ChatID int64
1350+
}
1351+
13261352
// WriteAccessAllowed represents a service message about a user
13271353
// allowing a bot added to the attachment menu to write messages.
13281354
// Currently holds no information.
@@ -1455,6 +1481,20 @@ type KeyboardButton struct {
14551481
// Text of the button. If none of the optional fields are used,
14561482
// it will be sent as a message when the button is pressed.
14571483
Text string `json:"text"`
1484+
// RequestUser if specified, pressing the button will open
1485+
// a list of suitable users. Tapping on any user will send
1486+
// their identifier to the bot in a "user_shared" service message.
1487+
// Available in private chats only.
1488+
//
1489+
// optional
1490+
RequestUser *KeyboardButtonRequestUser `json:"request_user,omitempty"`
1491+
// RequestChat if specified, pressing the button will open
1492+
// a list of suitable chats. Tapping on a chat will send
1493+
// its identifier to the bot in a "chat_shared" service message.
1494+
// Available in private chats only.
1495+
//
1496+
// optional
1497+
RequestChat *KeyboardButtonRequestChat `json:"request_chat,omitempty"`
14581498
// RequestContact if True, the user's phone number will be sent
14591499
// as a contact when the button is pressed.
14601500
// Available in private chats only.
@@ -1480,6 +1520,72 @@ type KeyboardButton struct {
14801520
WebApp *WebAppInfo `json:"web_app,omitempty"`
14811521
}
14821522

1523+
// KeyboardButtonRequestUser defines the criteria used to request
1524+
// a suitable user. The identifier of the selected user will be shared
1525+
// with the bot when the corresponding button is pressed.
1526+
type KeyboardButtonRequestUser struct {
1527+
// RequestID is a signed 32-bit identifier of the request.
1528+
RequestID int `json:"request_id"`
1529+
// UserIsBot pass True to request a bot,
1530+
// pass False to request a regular user.
1531+
// If not specified, no additional restrictions are applied.
1532+
//
1533+
// optional
1534+
UserIsBot bool `json:"user_is_bot,omitempty"`
1535+
// UserIsPremium pass True to request a premium user,
1536+
// pass False to request a non-premium user.
1537+
// If not specified, no additional restrictions are applied.
1538+
//
1539+
// optional
1540+
UserIsPremium bool `json:"user_is_premium,omitempty"`
1541+
}
1542+
1543+
// KeyboardButtonRequestChat defines the criteria used to request
1544+
// a suitable chat. The identifier of the selected chat will be shared
1545+
// with the bot when the corresponding button is pressed.
1546+
type KeyboardButtonRequestChat struct {
1547+
// RequestID is a signed 32-bit identifier of the request.
1548+
RequestID int `json:"request_id"`
1549+
// ChatIsChannel pass True to request a channel chat,
1550+
// pass False to request a group or a supergroup chat.
1551+
ChatIsChannel bool `json:"chat_is_channel"`
1552+
// ChatIsForum pass True to request a forum supergroup,
1553+
// pass False to request a non-forum chat.
1554+
// If not specified, no additional restrictions are applied.
1555+
//
1556+
// optional
1557+
ChatIsForum bool `json:"chat_is_forum,omitempty"`
1558+
// ChatHasUsername pass True to request a supergroup or a channel with a username,
1559+
// pass False to request a chat without a username.
1560+
// If not specified, no additional restrictions are applied.
1561+
//
1562+
// optional
1563+
ChatHasUsername bool `json:"chat_has_username,omitempty"`
1564+
// ChatIsCreated pass True to request a chat owned by the user.
1565+
// Otherwise, no additional restrictions are applied.
1566+
//
1567+
// optional
1568+
ChatIsCreated bool `json:"chat_is_created,omitempty"`
1569+
// UserAdministratorRights is a JSON-serialized object listing
1570+
// the required administrator rights of the user in the chat.
1571+
// If not specified, no additional restrictions are applied.
1572+
//
1573+
// optional
1574+
UserAdministratorRights *ChatAdministratorRights `json:"user_administrator_rights,omitempty"`
1575+
// BotAdministratorRights is a JSON-serialized object listing
1576+
// the required administrator rights of the bot in the chat.
1577+
// The rights must be a subset of user_administrator_rights.
1578+
// If not specified, no additional restrictions are applied.
1579+
//
1580+
// optional
1581+
BotAdministratorRights *ChatAdministratorRights `json:"bot_administrator_rights,omitempty"`
1582+
// BotIsMember pass True to request a chat with the bot as a member.
1583+
// Otherwise, no additional restrictions are applied.
1584+
//
1585+
// optional
1586+
BotIsMember bool `json:"bot_is_member,omitempty"`
1587+
}
1588+
14831589
// KeyboardButtonPollType represents type of poll, which is allowed to
14841590
// be created and sent when the corresponding button is pressed.
14851591
type KeyboardButtonPollType struct {
@@ -1852,11 +1958,36 @@ type ChatMember struct {
18521958
//
18531959
// optional
18541960
CanSendMessages bool `json:"can_send_messages,omitempty"`
1855-
// CanSendMediaMessages restricted only.
1856-
// True, if the user is allowed to send text messages, contacts, locations and venues
1961+
// CanSendAudios restricted only.
1962+
// True, if the user is allowed to send audios
1963+
//
1964+
// optional
1965+
CanSendAudios bool
1966+
// CanSendDocuments restricted only.
1967+
// True, if the user is allowed to send documents
1968+
//
1969+
// optional
1970+
CanSendDocuments bool
1971+
// CanSendPhotos is restricted only.
1972+
// True, if the user is allowed to send photos
18571973
//
18581974
// optional
1859-
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
1975+
CanSendPhotos bool
1976+
// CanSendVideos restricted only.
1977+
// True, if the user is allowed to send videos
1978+
//
1979+
// optional
1980+
CanSendVideos bool
1981+
// CanSendVideoNotes restricted only.
1982+
// True, if the user is allowed to send video notes
1983+
//
1984+
// optional
1985+
CanSendVideoNotes bool
1986+
// CanSendVoiceNotes restricted only.
1987+
// True, if the user is allowed to send voice notes
1988+
//
1989+
// optional
1990+
CanSendVoiceNotes bool
18601991
// CanSendPolls restricted only.
18611992
// True, if the user is allowed to send polls
18621993
//
@@ -1887,6 +2018,27 @@ func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
18872018
// WasKicked returns if the ChatMember was kicked from the chat.
18882019
func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
18892020

2021+
// SetCanSendMediaMessages is a method to replace field "can_send_media_messages".
2022+
// It sets CanSendAudio, CanSendDocuments, CanSendPhotos, CanSendVideos,
2023+
// CanSendVideoNotes, CanSendVoiceNotes to passed value.
2024+
func (chat *ChatMember) SetCanSendMediaMessages(b bool) {
2025+
chat.CanSendAudios = b
2026+
chat.CanSendDocuments = b
2027+
chat.CanSendPhotos = b
2028+
chat.CanSendVideos = b
2029+
chat.CanSendVideoNotes = b
2030+
chat.CanSendVoiceNotes = b
2031+
}
2032+
2033+
// CanSendMediaMessages method to replace field "can_send_media_messages".
2034+
// It returns true if CanSendAudio and CanSendDocuments and CanSendPhotos and CanSendVideos and
2035+
// CanSendVideoNotes and CanSendVoiceNotes are true.
2036+
func (chat *ChatMember) CanSendMediaMessages() bool {
2037+
return chat.CanSendAudios && chat.CanSendDocuments &&
2038+
chat.CanSendPhotos && chat.CanSendVideos &&
2039+
chat.CanSendVideoNotes && chat.CanSendVoiceNotes
2040+
}
2041+
18902042
// ChatMemberUpdated represents changes in the status of a chat member.
18912043
type ChatMemberUpdated struct {
18922044
// Chat the user belongs to.
@@ -1912,6 +2064,8 @@ type ChatJoinRequest struct {
19122064
Chat Chat `json:"chat"`
19132065
// User that sent the join request.
19142066
From User `json:"from"`
2067+
// UserChatID identifier of a private chat with the user who sent the join request.
2068+
UserChatID int64 `json:"user_chat_id"`
19152069
// Date the request was sent in Unix time.
19162070
Date int `json:"date"`
19172071
// Bio of the user.
@@ -1932,12 +2086,30 @@ type ChatPermissions struct {
19322086
//
19332087
// optional
19342088
CanSendMessages bool `json:"can_send_messages,omitempty"`
1935-
// CanSendMediaMessages is true, if the user is allowed to send audios,
1936-
// documents, photos, videos, video notes and voice notes, implies
1937-
// can_send_messages
2089+
// CanSendAudios is true, if the user is allowed to send audios
2090+
//
2091+
// optional
2092+
CanSendAudios bool
2093+
// CanSendDocuments is true, if the user is allowed to send documents
2094+
//
2095+
// optional
2096+
CanSendDocuments bool
2097+
// CanSendPhotos is true, if the user is allowed to send photos
19382098
//
19392099
// optional
1940-
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
2100+
CanSendPhotos bool
2101+
// CanSendVideos is true, if the user is allowed to send videos
2102+
//
2103+
// optional
2104+
CanSendVideos bool
2105+
// CanSendVideoNotes is true, if the user is allowed to send video notes
2106+
//
2107+
// optional
2108+
CanSendVideoNotes bool
2109+
// CanSendVoiceNotes is true, if the user is allowed to send voice notes
2110+
//
2111+
// optional
2112+
CanSendVoiceNotes bool
19412113
// CanSendPolls is true, if the user is allowed to send polls, implies
19422114
// can_send_messages
19432115
//
@@ -1975,6 +2147,27 @@ type ChatPermissions struct {
19752147
CanManageTopics bool `json:"can_manage_topics,omitempty"`
19762148
}
19772149

2150+
// SetCanSendMediaMessages is a method to replace field "can_send_media_messages".
2151+
// It sets CanSendAudio, CanSendDocuments, CanSendPhotos, CanSendVideos,
2152+
// CanSendVideoNotes, CanSendVoiceNotes to passed value.
2153+
func (c *ChatPermissions) SetCanSendMediaMessages(b bool) {
2154+
c.CanSendAudios = b
2155+
c.CanSendDocuments = b
2156+
c.CanSendPhotos = b
2157+
c.CanSendVideos = b
2158+
c.CanSendVideoNotes = b
2159+
c.CanSendVoiceNotes = b
2160+
}
2161+
2162+
// CanSendMediaMessages method to replace field "can_send_media_messages".
2163+
// It returns true if CanSendAudio and CanSendDocuments and CanSendPhotos and CanSendVideos and
2164+
// CanSendVideoNotes and CanSendVoiceNotes are true.
2165+
func (c *ChatPermissions) CanSendMediaMessages() bool {
2166+
return c.CanSendAudios && c.CanSendDocuments &&
2167+
c.CanSendPhotos && c.CanSendVideos &&
2168+
c.CanSendVideoNotes && c.CanSendVoiceNotes
2169+
}
2170+
19782171
// ChatLocation represents a location to which a chat is connected.
19792172
type ChatLocation struct {
19802173
// Location is the location to which the supergroup is connected. Can't be a

0 commit comments

Comments
 (0)