Merge branch 'master' into bot-api-6.3

pull/1/head
OvyFlash 2022-11-20 22:04:02 +02:00
commit 2e912ef461
3 changed files with 158 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
coverage.out
tmp/
book/
.vscode/

View File

@ -1166,6 +1166,7 @@ type WebhookConfig struct {
MaxConnections int
AllowedUpdates []string
DropPendingUpdates bool
SecretToken string
}
func (config WebhookConfig) method() string {
@ -1183,6 +1184,7 @@ func (config WebhookConfig) params() (Params, error) {
params.AddNonZero("max_connections", config.MaxConnections)
err := params.AddInterface("allowed_updates", config.AllowedUpdates)
params.AddBool("drop_pending_updates", config.DropPendingUpdates)
params.AddNonEmpty("secret_token", config.SecretToken)
return params, err
}
@ -1788,6 +1790,64 @@ func (config InvoiceConfig) method() string {
return "sendInvoice"
}
// InvoiceLinkConfig contains information for createInvoiceLink method
type InvoiceLinkConfig struct {
Title string //Required
Description string //Required
Payload string //Required
ProviderToken string //Required
Currency string //Required
Prices []LabeledPrice //Required
MaxTipAmount int
SuggestedTipAmounts []int
ProviderData string
PhotoURL string
PhotoSize int
PhotoWidth int
PhotoHeight int
NeedName bool
NeedPhoneNumber bool
NeedEmail bool
NeedShippingAddress bool
SendPhoneNumberToProvider bool
SendEmailToProvider bool
IsFlexible bool
}
func (config InvoiceLinkConfig) params() (Params, error) {
params := make(Params)
params["title"] = config.Title
params["description"] = config.Description
params["payload"] = config.Payload
params["provider_token"] = config.ProviderToken
params["currency"] = config.Currency
if err := params.AddInterface("prices", config.Prices); err != nil {
return params, err
}
params.AddNonZero("max_tip_amount", config.MaxTipAmount)
err := params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
params.AddNonEmpty("provider_data", config.ProviderData)
params.AddNonEmpty("photo_url", config.PhotoURL)
params.AddNonZero("photo_size", config.PhotoSize)
params.AddNonZero("photo_width", config.PhotoWidth)
params.AddNonZero("photo_height", config.PhotoHeight)
params.AddBool("need_name", config.NeedName)
params.AddBool("need_phone_number", config.NeedPhoneNumber)
params.AddBool("need_email", config.NeedEmail)
params.AddBool("need_shipping_address", config.NeedShippingAddress)
params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
params.AddBool("send_email_to_provider", config.SendEmailToProvider)
params.AddBool("is_flexible", config.IsFlexible)
return params, err
}
func (config InvoiceLinkConfig) method() string {
return "createInvoiceLink"
}
// ShippingConfig contains information for answerShippingQuery request.
type ShippingConfig struct {
ShippingQueryID string // required
@ -2008,6 +2068,24 @@ func (config GetStickerSetConfig) params() (Params, error) {
return params, nil
}
// GetCustomEmojiStickersConfig get information about
// custom emoji stickers by their identifiers.
type GetCustomEmojiStickersConfig struct {
CustomEmojiIDs []string
}
func (config GetCustomEmojiStickersConfig) params() (Params, error) {
params := make(Params)
params.AddInterface("custom_emoji_ids", config.CustomEmojiIDs)
return params, nil
}
func (config GetCustomEmojiStickersConfig) method() string {
return "getCustomEmojiStickers"
}
// UploadStickerConfig allows you to upload a sticker for use in a set later.
type UploadStickerConfig struct {
UserID int64
@ -2042,8 +2120,9 @@ type NewStickerSetConfig struct {
Title string
PNGSticker RequestFileData
TGSSticker RequestFileData
StickerType string
Emojis string
ContainsMasks bool
ContainsMasks bool // deprecated
MaskPosition *MaskPosition
}
@ -2057,11 +2136,10 @@ func (config NewStickerSetConfig) params() (Params, error) {
params.AddNonZero64("user_id", config.UserID)
params["name"] = config.Name
params["title"] = config.Title
params["emojis"] = config.Emojis
params.AddBool("contains_masks", config.ContainsMasks)
params.AddNonEmpty("sticker_type", string(config.StickerType))
err := params.AddInterface("mask_position", config.MaskPosition)
return params, err

View File

@ -187,6 +187,10 @@ type User struct {
//
// optional
IsPremium bool `json:"is_premium,omitempty"`
// AddedToAttachmentMenu true, if this user added the bot to the attachment menu
//
// optional
AddedToAttachmentMenu bool `json:"added_to_attachment_menu,omitempty"`
// FirstName user's or bot's first name
FirstName string `json:"first_name"`
// LastName user's or bot's last name
@ -288,6 +292,24 @@ type Chat struct {
//
// optional
HasPrivateForwards bool `json:"has_private_forwards,omitempty"`
// HasRestrictedVoiceAndVideoMessages if the privacy settings of the other party
// restrict sending voice and video note messages
// in the private chat. Returned only in getChat.
//
// optional
HasRestrictedVoiceAndVideoMessages bool `json:"has_restricted_voice_and_video_messages,omitempty"`
// JoinToSendMessages is true, if users need to join the supergroup
// before they can send messages.
// Returned only in getChat
//
// optional
JoinToSendMessages bool `json:"join_to_send_messages,omitempty"`
// JoinByRequest is true, if all users directly joining the supergroup
// need to be approved by supergroup administrators.
// Returned only in getChat.
//
// optional
JoinByRequest bool `json:"join_by_request,omitempty"`
// Description for groups, supergroups and channel chats
//
// optional
@ -765,6 +787,7 @@ type MessageEntity struct {
// “pre” (monowidth block),
// “text_link” (for clickable text URLs),
// “text_mention” (for users without usernames)
// “text_mention” (for inline custom emoji stickers)
Type string `json:"type"`
// Offset in UTF-16 code units to the start of the entity
Offset int `json:"offset"`
@ -782,6 +805,10 @@ type MessageEntity struct {
//
// optional
Language string `json:"language,omitempty"`
// CustomEmojiID for “custom_emoji” only, unique identifier of the custom emoji
//
// optional
CustomEmojiID string `json:"custom_emoji_id"`
}
// ParseURL attempts to parse a URL contained within a MessageEntity.
@ -898,7 +925,7 @@ type Animation struct {
// FileSize file size
//
// optional
FileSize int `json:"file_size,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
}
// Audio represents an audio file to be treated as music by the Telegram clients.
@ -931,7 +958,7 @@ type Audio struct {
// FileSize file size
//
// optional
FileSize int `json:"file_size,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
// Thumbnail is the album cover to which the music file belongs
//
// optional
@ -962,7 +989,7 @@ type Document struct {
// FileSize file size
//
// optional
FileSize int `json:"file_size,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
}
// Video represents a video file.
@ -995,7 +1022,7 @@ type Video struct {
// FileSize file size
//
// optional
FileSize int `json:"file_size,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
}
// VideoNote object represents a video message.
@ -1037,7 +1064,7 @@ type Voice struct {
// FileSize file size
//
// optional
FileSize int `json:"file_size,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
}
// Contact represents a phone contact.
@ -1293,7 +1320,7 @@ type File struct {
// FileSize file size, if known
//
// optional
FileSize int `json:"file_size,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
// FilePath file path
//
// optional
@ -2070,6 +2097,13 @@ type InputMediaDocument struct {
DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"`
}
// Constant values for sticker types
const (
StickerTypeRegular = "regular"
StickerTypeMask = "mask"
StickerTypeCustomEmoji = "custom_emoji"
)
// Sticker represents a sticker.
type Sticker struct {
// FileID is an identifier for this file, which can be used to download or
@ -2079,6 +2113,10 @@ type Sticker struct {
// which is supposed to be the same over time and for different bots.
// Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// Type is a type of the sticker, currently one of “regular”,
// “mask”, “custom_emoji”. The type of the sticker is independent
// from its format, which is determined by the fields is_animated and is_video.
Type string `json:"type"`
// Width sticker width
Width int `json:"width"`
// Height sticker height
@ -2122,6 +2160,21 @@ type Sticker struct {
FileSize int `json:"file_size,omitempty"`
}
// IsRegular returns if the Sticker is regular
func (s Sticker) IsRegular() bool {
return s.Type == StickerTypeRegular
}
// IsMask returns if the Sticker is mask
func (s Sticker) IsMask() bool {
return s.Type == StickerTypeMask
}
// IsCustomEmoji returns if the Sticker is custom emoji
func (s Sticker) IsCustomEmoji() bool {
return s.Type == StickerTypeCustomEmoji
}
// StickerSet represents a sticker set.
type StickerSet struct {
// Name sticker set name
@ -2135,6 +2188,8 @@ type StickerSet struct {
// IsVideo true, if the sticker set contains video stickers
IsVideo bool `json:"is_video"`
// ContainsMasks true, if the sticker set contains masks
//
// deprecated. Use sticker_type instead
ContainsMasks bool `json:"contains_masks"`
// Stickers list of all set stickers
Stickers []Sticker `json:"stickers"`
@ -2142,6 +2197,21 @@ type StickerSet struct {
Thumbnail *PhotoSize `json:"thumb"`
}
// IsRegular returns if the StickerSet is regular
func (s StickerSet) IsRegular() bool {
return s.StickerType == StickerTypeRegular
}
// IsMask returns if the StickerSet is mask
func (s StickerSet) IsMask() bool {
return s.StickerType == StickerTypeMask
}
// IsCustomEmoji returns if the StickerSet is custom emoji
func (s StickerSet) IsCustomEmoji() bool {
return s.StickerType == StickerTypeCustomEmoji
}
// MaskPosition describes the position on faces where a mask should be placed
// by default.
type MaskPosition struct {