1
0

👽 Added Bot API 4.4 changes

This commit is contained in:
Maxim Lebedev 2019-07-30 16:15:07 +05:00
parent b9272596e9
commit f898f5f5a0
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
4 changed files with 128 additions and 31 deletions

View File

@ -106,6 +106,7 @@ const (
MethodSendVideoNote = "sendVideoNote"
MethodSendVoice = "sendVoice"
MethodSetChatDescription = "setChatDescription"
MethodSetChatPermissions = "setChatPermissions"
MethodSetChatPhoto = "setChatPhoto"
MethodSetChatStickerSet = "setChatStickerSet"
MethodSetChatTitle = "setChatTitle"

35
restrict.go Normal file
View File

@ -0,0 +1,35 @@
package telegram
type RestrictChatMemberParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Unique identifier of the target user
UserID int `json:"user_id"`
// New user permissions
Permissions ChatPermissions `json:"permissions"`
// Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days
// or less than 30 seconds from the current time, they are considered to be restricted forever
UntilDate int64 `json:"until_date,omitempty"`
}
// restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have
// the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns True on
// success.
func (b *Bot) RestrictChatMember(params RestrictChatMemberParameters) (bool, error) {
dst, err := parser.Marshal(&params)
if err != nil {
return false, err
}
resp, err := b.request(dst, MethodRestrictChatMember)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

27
set.go
View File

@ -119,6 +119,15 @@ type (
// New sticker position in the set, zero-based
Position int `json:"position"`
}
// SetChatPermissionsParameters represents data for SetChatPermissions method.
SetChatPermissionsParameters struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// New default chat permissions
Permissions ChatPermissions `json:"permissions"`
}
)
// NewWebhook creates new SetWebhookParameters only with required parameters.
@ -341,3 +350,21 @@ func (b *Bot) SetStickerPositionInSet(sticker string, position int) (bool, error
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}
// SetChatPermissions set default chat permissions for all members. The bot must be an administrator in the group or a
// supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.
func (b *Bot) SetChatPermissions(params SetChatPermissionsParameters) (bool, error) {
dst, err := parser.Marshal(&params)
if err != nil {
return false, err
}
resp, err := b.request(dst, MethodSetChatPermissions)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

View File

@ -116,14 +116,10 @@ type (
// Last name of the other party in a private chat
LastName string `json:"last_name,omitempty"`
// True if a group has All Members Are Admins enabled.
AllMembersAreAdministrators bool `json:"all_members_are_administrators,omitempty"`
// Chat photo. Returned only in getChat.
Photo *ChatPhoto `json:"photo,omitempty"`
// Description, for supergroups and channel chats. Returned only in
// getChat.
// Description, for groups, supergroups and channel chats. Returned only in getChat.
Description string `json:"description,omitempty"`
// Chat invite link, for supergroups and channel chats. Returned only in
@ -133,6 +129,9 @@ type (
// Pinned message, for groups, supergroups and channels. Returned only in getChat.
PinnedMessage *Message `json:"pinned_message,omitempty"`
// Default chat member permissions, for groups and supergroups. Returned only in getChat.
Permissions *ChatPermissions `json:"permissions,omitempty"`
// For supergroups, name of Group sticker set. Returned only in getChat.
StickerSetName string `json:"sticker_set_name,omitempty"`
@ -763,11 +762,13 @@ type (
// ChatPhoto represents a chat photo.
ChatPhoto struct {
// Unique file identifier of small (160x160) chat photo. This file_id can
// be used only for photo download.
// be used only for photo download. This file_id can be used only for photo download and only for as
// long as the photo is not changed.
SmallFileID string `json:"small_file_id"`
// Unique file identifier of big (640x640) chat photo. This file_id can
// be used only for photo download.
// be used only for photo download. This file_id can be used only for photo download and only for as
// long as the photo is not changed.
BigFileID string `json:"big_file_id"`
}
@ -776,52 +777,46 @@ type (
// Information about the user
User *User `json:"user"`
// The member's status in the chat. Can be "creator", "administrator",
// "member", "restricted", "left" or "kicked"
// The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left"
// or "kicked"
Status string `json:"status"`
// Restictred and kicked only. Date when restrictions will be lifted for
// this user, unix time
// Restictred and kicked only. Date when restrictions will be lifted for this user, unix time
UntilDate int64 `json:"until_date,omitempty"`
// Administrators only. True, if the bot is allowed to edit administrator
// privileges of that user
// Administrators only. True, if the bot is allowed to edit administrator privileges of that user
CanBeEdited bool `json:"can_be_edited,omitempty"`
// Administrators only. True, if the administrator can change the chat
// title, photo and other settings
CanChangeInfo bool `json:"can_change_info,omitempty"`
// Administrators only. True, if the administrator can post in the
// channel, channels only
// Administrators only. True, if the administrator can post in the channel, channels only
CanPostMessages bool `json:"can_post_messages,omitempty"`
// Administrators only. True, if the administrator can edit messages of
// other users, channels only
// Administrators only. True, if the administrator can edit messages of other users, channels only
CanEditMessages bool `json:"can_edit_messages,omitempty"`
// Administrators only. True, if the administrator can delete messages of
// other users
// Administrators only. True, if the administrator can delete messages of other users
CanDeleteMessages bool `json:"can_delete_messages,omitempty"`
// Administrators only. True, if the administrator can invite new users
// to the chat
CanInviteUsers bool `json:"can_invite_users,omitempty"`
// Administrators only. True, if the administrator can restrict, ban or
// unban chat members
CanRestrictMembers bool `json:"can_restrict_members,omitempty"`
// Administrators only. True, if the administrator can pin messages,
// supergroups only
CanPinMessages bool `json:"can_pin_messages,omitempty"`
// Administrators only. True, if the administrator can add new
// administrators with a subset of his own privileges or demote
// administrators that he has promoted, directly or indirectly (promoted
// by administrators that were appointed by the user)
CanPromoteMembers bool `json:"can_promote_members,omitempty"`
// Administrators and restricted only. True, if the user is allowed to change the chat title, photo
// and other settings
CanChangeInfo bool `json:"can_change_info,omitempty"`
// Administrators and restricted only. True, if the user is allowed to invite new users to the chat
CanInviteUsers bool `json:"can_invite_users,omitempty"`
// Administrators and restricted only. True, if the user is allowed to pin messages; groups and
// supergroups only
CanPinMessages bool `json:"can_pin_messages,omitempty"`
// Restricted only. True, if the user is a member of the chat at the moment of the request
IsMember bool `json:"is_member,omitempty"`
@ -833,6 +828,9 @@ type (
// videos, video notes and voice notes, implies can_send_messages
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
// Restricted only. True, if the user is allowed to send polls
CanSendPolls bool `json:"can_send_polls,omitempty"`
// Restricted only. True, if the user can send animations, games,
// stickers and use inline bots, implies can_send_media_messages
CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"`
@ -842,6 +840,36 @@ type (
CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
}
// ChatPermissions describes actions that a non-administrator user is allowed to take in a chat.
ChatPermissions struct {
// True, if the user is allowed to send text messages, contacts, locations and venues
CanSendMessages bool `json:"can_send_messages,omitempty"`
// True, if the user is allowed to send audios, documents, photos, videos, video notes and voice
// notes, implies can_send_messages
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
// True, if the user is allowed to send polls, implies can_send_messages
CanSendPolls bool `json:"can_send_polls,omitempty"`
// True, if the user is allowed to send animations, games, stickers and use inline bots, implies
// can_send_media_messages
CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"`
// True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages
CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
// True, if the user is allowed to change the chat title, photo and other settings. Ignored in public
// supergroups
CanChangeInfo bool `json:"can_change_info,omitempty"`
// True, if the user is allowed to invite new users to the chat
CanInviteUsers bool `json:"can_invite_users,omitempty"`
// True, if the user is allowed to pin messages. Ignored in public supergroups
CanPinMessages bool `json:"can_pin_messages,omitempty"`
}
// ResponseParameters contains information about why a request was
// unsuccessful.
ResponseParameters struct {
@ -2693,6 +2721,9 @@ type (
// For mask stickers, the position where the mask should be placed
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
// true, if the sticker is animated
IsAnimated bool `json:"is_animated"`
}
// StickerSet represents a sticker set.
@ -2708,6 +2739,9 @@ type (
// List of all set stickers
Stickers []Sticker `json:"stickers"`
// true, if the sticker set contains animated stickers
IsAnimated bool `json:"is_animated"`
}
// MaskPosition describes the position on faces where a mask should be placed