diff --git a/configs.go b/configs.go index 268c937..030d3c6 100644 --- a/configs.go +++ b/configs.go @@ -60,6 +60,19 @@ const ( // UpdateTypeEditedChannelPost is new version of a channel post that is known to the bot and was edited UpdateTypeEditedChannelPost = "edited_channel_post" + // UpdateTypeBusinessConnection is the bot was connected to or disconnected from a business account, + // or a user edited an existing connection with the bot + UpdateTypeBusinessConnection = "business_connection" + + // UpdateTypeBusinessMessage is a new non-service message from a connected business account + UpdateTypeBusinessMessage = "business_message" + + // UpdateTypeEditedBusinessMessage is a new version of a message from a connected business account + UpdateTypeEditedBusinessMessage = "edited_business_message" + + // UpdateTypeDeletedBusinessMessages are the messages were deleted from a connected business account + UpdateTypeDeletedBusinessMessages = "deleted_business_messages" + // UpdateTypeMessageReactionis is a reaction to a message was changed by a user UpdateTypeMessageReaction = "message_reaction" @@ -2216,7 +2229,6 @@ type NewStickerSetConfig struct { Name string Title string Stickers []InputSticker - StickerFormat string StickerType string NeedsRepainting bool //optional; Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only } @@ -2231,7 +2243,6 @@ func (config NewStickerSetConfig) params() (Params, error) { params.AddNonZero64("user_id", config.UserID) params["name"] = config.Name params["title"] = config.Title - params["sticker_format"] = config.StickerFormat params.AddBool("needs_repainting", config.NeedsRepainting) params.AddNonEmpty("sticker_type", string(config.StickerType)) @@ -2363,6 +2374,33 @@ func (config DeleteStickerConfig) params() (Params, error) { return params, nil } +// ReplaceStickerInSetConfig allows you to replace an existing sticker in a sticker set +// with a new one. The method is equivalent to calling deleteStickerFromSet, +// then addStickerToSet, then setStickerPositionInSet. +// Returns True on success. +type ReplaceStickerInSetConfig struct { + UserID int64 + Name string + OldSticker string + Sticker InputSticker +} + +func (config ReplaceStickerInSetConfig) method() string { + return "replaceStickerInSet" +} + +func (config ReplaceStickerInSetConfig) params() (Params, error) { + params := make(Params) + + params.AddNonZero64("user_id", config.UserID) + params["name"] = config.Name + params["old_sticker"] = config.OldSticker + + err := params.AddInterface("sticker", config.Sticker) + + return params, err +} + // SetStickerEmojiListConfig allows you to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot type SetStickerEmojiListConfig struct { Sticker string @@ -2425,6 +2463,7 @@ type SetStickerSetThumbConfig struct { Name string UserID int64 Thumb RequestFileData + Format string } func (config SetStickerSetThumbConfig) method() string { @@ -2435,6 +2474,8 @@ func (config SetStickerSetThumbConfig) params() (Params, error) { params := make(Params) params["name"] = config.Name + params["format"] = config.Format + params.AddNonZero64("user_id", config.UserID) return params, nil @@ -2739,6 +2780,29 @@ func (config GetUserChatBoostsConfig) params() (Params, error) { return params, err } +type ( + GetBusinessConnectionConfig struct { + BusinessConnectionID BusinessConnectionID + } + BusinessConnectionID string +) + +func (GetBusinessConnectionConfig) method() string { + return "getBusinessConnection" +} + +func (config GetBusinessConnectionConfig) params() (Params, error) { + return config.BusinessConnectionID.params() +} + +func (config BusinessConnectionID) params() (Params, error) { + params := make(Params) + + params["business_connection_id"] = string(config) + + return params, nil +} + // GetMyCommandsConfig gets a list of the currently registered commands. type GetMyCommandsConfig struct { Scope *BotCommandScope diff --git a/helper_methods.go b/helper_methods.go index 93901d9..db78644 100644 --- a/helper_methods.go +++ b/helper_methods.go @@ -1075,6 +1075,13 @@ func NewSetMyName(languageCode, name string) SetMyNameConfig { } } +// NewGetBusinessConnection gets business connection request struct +func NewGetBusinessConnection(id string) GetBusinessConnectionConfig { + return GetBusinessConnectionConfig{ + BusinessConnectionID: BusinessConnectionID(id), + } +} + // NewGetMyCommandsWithScope allows you to set the registered commands for a // given scope. func NewGetMyCommandsWithScope(scope BotCommandScope) GetMyCommandsConfig { diff --git a/helper_structs.go b/helper_structs.go index 008fc47..921099e 100644 --- a/helper_structs.go +++ b/helper_structs.go @@ -19,6 +19,7 @@ func (base ChatConfig) paramsWithKey(key string) (Params, error) { // BaseChat is base type for all chat config types. type BaseChat struct { ChatConfig + BusinessConnectionID BusinessConnectionID MessageThreadID int ProtectContent bool ReplyMarkup interface{} @@ -31,6 +32,11 @@ func (chat *BaseChat) params() (Params, error) { if err != nil { return params, err } + p1, err := chat.BusinessConnectionID.params() + if err != nil { + return params, err + } + params.Merge(p1) params.AddNonZero("message_thread_id", chat.MessageThreadID) params.AddBool("disable_notification", chat.DisableNotification) diff --git a/types.go b/types.go index 2da8b9c..51aa333 100644 --- a/types.go +++ b/types.go @@ -61,6 +61,26 @@ type Update struct { // // optional EditedChannelPost *Message `json:"edited_channel_post,omitempty"` + // BusinessConnection the bot was connected to or disconnected from a + // business account, or a user edited an existing connection with the bot + // + // optional + BusinessConnection *BusinessConnection `json:"business_connection,omitempty"` + // BusinessMessage is a new non-service message from a + // connected business account + // + // optional + BusinessMessage *Message `json:"business_message,omitempty"` + // EditedBusinessMessage is a new version of a message from a + // connected business account + // + // optional + EditedBusinessMessage *Message `json:"edited_business_message,omitempty"` + // DeletedBusinessMessages are the messages were deleted from a + // connected business account + // + // optional + DeletedBusinessMessages *BusinessMessagesDeleted `json:"deleted_business_messages,omitempty"` // MessageReaction is a reaction to a message was changed by a user. // // optional @@ -237,6 +257,12 @@ type User struct { // // optional SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` + // CanConnectToBusiness is true, if the bot can be connected to a + // Telegram Business account to receive its messages. + // Returned only in getMe. + // + // optional + CanConnectToBusiness bool `json:"can_connect_to_business,omitempty"` } // String displays a simple text version of a user. @@ -292,6 +318,31 @@ type Chat struct { // // optional ActiveUsernames []string `json:"active_usernames,omitempty"` + // Birthdate for private chats, the date of birth of the user. + // Returned only in getChat. + // + // optional + Birthdate *Birthdate `json:"birthdate,omitempty"` + // BusinessIntro is for private chats with business accounts, the intro of the business. + // Returned only in getChat. + // + // optional + BusinessIntro *BusinessIntro `json:"business_intro,omitempty"` + // BusinessLocation is for private chats with business accounts, the location + // of the business. Returned only in getChat. + // + // optional + BusinessLocation *BusinessLocation `json:"business_location,omitempty"` + // BusinessOpeningHours is for private chats with business accounts, + // the opening hours of the business. Returned only in getChat. + // + // optional + BusinessOpeningHours *BusinessOpeningHours `json:"business_opening_hours,omitempty"` + // PersonalChat is for private chats, the personal channel of the user. + // Returned only in getChat. + // + // optional + PersonalChat *Chat `json:"personal_chat,omitempty"` // AvailableReactions is a list of available reactions allowed in the chat. // If omitted, then all emoji reactions are allowed. Returned only in getChat. // @@ -426,8 +477,8 @@ type Chat struct { // // optional CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` - // CustomEmojiStickerSetName is for supergroups, the name of the group's - // custom emoji sticker set. Custom emoji from this set can be used by all + // CustomEmojiStickerSetName is for supergroups, the name of the group's + // custom emoji sticker set. Custom emoji from this set can be used by all // users and bots in the group. Returned only in getChat. // // optional @@ -505,8 +556,21 @@ type Message struct { // // optional SenderBoostCount int `json:"sender_boost_count,omitempty"` + // SenderBusinessBot is the bot that actually sent the message on behalf of + // the business account. Available only for outgoing messages sent on + // behalf of the connected business account. + // + // optional + SenderBusinessBot *User `json:"sender_business_bot,omitempty"` // Date of the message was sent in Unix time Date int `json:"date"` + // BusinessConnectionID is an unique identifier of the business connection + // from which the message was received. If non-empty, the message belongs to + // a chat of the corresponding business account that is independent from + // any potential bot chat which might share the same identifier. + // + // optional + BusinessConnectionID string `json:"business_connection_id,omitempty"` // Chat is the conversation the message belongs to Chat Chat `json:"chat"` // ForwardOrigin is information about the original message for forwarded messages @@ -553,6 +617,11 @@ type Message struct { // // optional HasProtectedContent bool `json:"has_protected_content,omitempty"` + // IsFromOffline is True, if the message was sent by an implicit action, + // for example, as an away or a greeting business message, or as a scheduled message + // + // optional + IsFromOffline bool `json:"is_from_offline,omitempty"` // MediaGroupID is the unique identifier of a media message group this message belongs to; // // optional @@ -1663,13 +1732,37 @@ type GeneralForumTopicHidden struct { type GeneralForumTopicUnhidden struct { } +// SharedUser contains information about a user that was +// shared with the bot using a KeyboardButtonRequestUsers button. +type SharedUser struct { + // UserID is the identifier of the shared user. + UserID int64 `json:"user_id"` + // FirstName of the user, if the name was requested by the bot. + // + // optional + FirstName *string `json:"first_name,omitempty"` + // LastName of the user, if the name was requested by the bot. + // + // optional + LastName *string `json:"last_name,omitempty"` + // Username of the user, if the username was requested by the bot. + // + // optional + UserName *string `json:"username,omitempty"` + // Photo is array of available sizes of the chat photo, + // if the photo was requested by the bot + // + // optional + Photo []PhotoSize `json:"photo,omitempty"` +} + // UsersShared object contains information about the user whose identifier // was shared with the bot using a KeyboardButtonRequestUser button. type UsersShared struct { // RequestID is an indentifier of the request. RequestID int `json:"request_id"` - // UserIDs are identifiers of the shared user. - UserIDs []int64 `json:"user_ids"` + // Users shared with the bot. + Users []SharedUser `json:"users"` } // ChatShared contains information about the chat whose identifier @@ -1679,6 +1772,20 @@ type ChatShared struct { RequestID int `json:"request_id"` // ChatID is an identifier of the shared chat. ChatID int64 `json:"chat_id"` + // Title of the chat, if the title was requested by the bot. + // + // optional + Title *string `json:"title,omitempty"` + // UserName of the chat, if the username was requested by + // the bot and available. + // + // optional + UserName *string `json:"username,omitempty"` + // Photo is array of available sizes of the chat photo, + // if the photo was requested by the bot + // + // optional + Photo []PhotoSize `json:"photo,omitempty"` } // WriteAccessAllowed represents a service message about a user allowing a bot @@ -2016,6 +2123,18 @@ type KeyboardButtonRequestUsers struct { // // optional MaxQuantity int `json:"max_quantity,omitempty"` + // RequestName pass True to request the users' first and last names + // + // optional + RequestName bool `json:"request_name,omitempty"` + // RequestUsername pass True to request the users' usernames + // + // optional + RequestUsername bool `json:"request_username,omitempty"` + // RequestPhoto pass True to request the users' photos + // + // optional + RequestPhoto bool `json:"request_photo,omitempty"` } // KeyboardButtonRequestChat defines the criteria used to request @@ -2062,6 +2181,18 @@ type KeyboardButtonRequestChat struct { // // optional BotIsMember bool `json:"bot_is_member,omitempty"` + // RequestTitle pass True to request the chat's title + // + // optional + RequestTitle bool `json:"request_title,omitempty"` + // RequestUsername pass True to request the chat's username + // + // optional + RequestUsername bool `json:"request_username,omitempty"` + // RequestPhoto pass True to request the chat's photo + // + // optional + RequestPhoto bool `json:"request_photo,omitempty"` } // KeyboardButtonPollType represents type of poll, which is allowed to @@ -2688,6 +2819,64 @@ func (c *ChatPermissions) CanSendMediaMessages() bool { c.CanSendVideoNotes && c.CanSendVoiceNotes } +// Birthdate represents a user's birthdate +type Birthdate struct { + // Day of the user's birth; 1-31 + Day int `json:"day"` + // Month of the user's birth; 1-12 + Month int `json:"month"` + // Year of the user's birth + // + // optional + Year *int `json:"year,omitempty"` +} + +// BusinessIntro represents a basic information about your business +type BusinessIntro struct { + // Title text of the business intro + // + // optional + Title *string `json:"title,omitempty"` + // Message text of the business intro + // + // optional + Message *string `json:"message,omitempty"` + // Sticker of the business intro + // + // optional + Sticker *Sticker `json:"sticker,omitempty"` +} + +// BusinessLocation represents a business geodata +type BusinessLocation struct { + // Address of the business + Address string `json:"address"` + // Location of the business + // + // optional + Location *Location `json:"location,omitempty"` +} + +// BusinessOpeningHoursInterval represents a business working interval +type BusinessOpeningHoursInterval struct { + // OpeningMinute is the minute's sequence number in a week, starting on Monday, + // marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60 + OpeningMinute int `json:"opening_minute"` + // ClosingMinute is the minute's sequence number in a week, starting on Monday, + // marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60 + ClosingMinute int `json:"closing_minute"` +} + +// BusinessOpeningHours represents a set of business working intervals +type BusinessOpeningHours struct { + // TimeZoneName is the unique name of the time zone + // for which the opening hours are defined + TimeZoneName string `json:"time_zone_name"` + // OpeningHours is the list of time intervals describing + // business opening hours + OpeningHours []BusinessOpeningHoursInterval `json:"opening_hours"` +} + // ChatLocation represents a location to which a chat is connected. type ChatLocation struct { // Location is the location to which the supergroup is connected. Can't be a @@ -2904,6 +3093,38 @@ type UserChatBoosts struct { Boosts []ChatBoost `json:"boosts"` } +// BusinessConnection describes the connection of the bot with a business account. +type BusinessConnection struct { + // ID is an unique identifier of the business connection + ID string `json:"id"` + // User is a business account user that created the business connection + User User `json:"user"` + // UserChatID identifier of a private chat with the user who + // created the business connection. + UserChatID int64 `json:"user_chat_id"` + // Date the connection was established in Unix time + Date int64 `json:"date"` + // CanReply is True, if the bot can act on behalf of the + // business account in chats that were active in the last 24 hours + CanReply bool `json:"can_reply"` + // IsEnabled is True, if the connection is active + IsEnabled bool `json:"is_enabled"` +} + +// BusinessMessagesDeleted is received when messages are deleted +// from a connected business account. +type BusinessMessagesDeleted struct { + // BusinessConnectionID is an unique identifier + // of the business connection + BusinessConnectionID string `json:"business_connection_id"` + // Chat is the information about a chat in the business account. + // The bot may not have access to the chat or the corresponding user. + Chat Chat `json:"chat"` + // MessageIDs is a JSON-serialized list of identifiers of deleted messages + // in the chat of the business account + MessageIDs []int `json:"message_ids"` +} + // ResponseParameters are various errors that can be returned in APIResponse. type ResponseParameters struct { // The group has been migrated to a supergroup with the specified identifier. @@ -3139,10 +3360,6 @@ type StickerSet struct { Title string `json:"title"` // StickerType of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” StickerType string `json:"sticker_type"` - // IsAnimated true, if the sticker set contains animated stickers - IsAnimated bool `json:"is_animated"` - // 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 @@ -3190,6 +3407,9 @@ type MaskPosition struct { type InputSticker struct { // The added sticker. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, upload a new one using multipart/form-data, or pass “attach://” to upload a new one using multipart/form-data under name. Animated and video stickers can't be uploaded via HTTP URL. Sticker RequestFile `json:"sticker"` + // Format of the added sticker, must be one of “static” for a + // .WEBP or .PNG image, “animated” for a .TGS animation, “video” for a WEBM video + Format string `json:"format"` // List of 1-20 emoji associated with the sticker EmojiList []string `json:"emoji_list"` // Position where the mask should be placed on faces. For “mask” stickers only. diff --git a/types_test.go b/types_test.go index 4fd9e44..ac1f3bc 100644 --- a/types_test.go +++ b/types_test.go @@ -308,6 +308,7 @@ var ( _ Chattable = FileConfig{} _ Chattable = ForwardConfig{} _ Chattable = GameConfig{} + _ Chattable = GetBusinessConnectionConfig{} _ Chattable = GetChatMemberConfig{} _ Chattable = GetChatMenuButtonConfig{} _ Chattable = GetGameHighScoresConfig{} @@ -324,6 +325,7 @@ var ( _ Chattable = PinChatMessageConfig{} _ Chattable = PreCheckoutConfig{} _ Chattable = PromoteChatMemberConfig{} + _ Chattable = ReplaceStickerInSetConfig{} _ Chattable = RestrictChatMemberConfig{} _ Chattable = RevokeChatInviteLinkConfig{} _ Chattable = SendPollConfig{}