Skip to content

Commit

Permalink
Merge branch 'v3.4' into BotAPI7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
demget authored Aug 9, 2024
2 parents 1cbaa0f + b85939e commit a49a37d
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 68 deletions.
106 changes: 106 additions & 0 deletions business.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package telebot

import (
"encoding/json"
"time"
)

type BusinessConnection struct {
// Unique identifier of the business connection
ID string `json:"id"`

// Business account user that created the business connection
Sender *User `json:"user"`

// Identifier of a private chat with the user who created the business connection. This
// number may have more than 32 significant bits and some programming languages may
// have difficulty/silent defects in interpreting it. But it has at most 52 significant bits,
// so a 64-bit integer or double-precision float type are safe for storing this identifier.
UserChatID int64 `json:"user_chat_id"`

// Unixtime, use BusinessConnection.Time() to get time.Time.
Unixtime int64 `json:"date"`

// 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"`

// True, if the connection is active
Enabled bool `json:"is_enabled"`
}

// Time returns the moment of business connection creation in local time.
func (b *BusinessConnection) Time() time.Time {
return time.Unix(b.Unixtime, 0)
}

type BusinessMessagesDeleted struct {
// Unique identifier of the business connection
BusinessConnectionID string `json:"business_connection_id"`

// 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"`

// The list of identifiers of deleted messages in the chat of the business account
MessageIDs []int `json:"message_ids"`
}

type BusinessIntro struct {
// (Optional)
// Title text of the business intro
Title string `json:"title"`

// Message text of the business intro
Message string `json:"message"`

// Sticker of the business intro
Sticker *Sticker `json:"sticker"`
}

type BusinessLocation struct {
// Address of the business
Address string `json:"address"`

// (Optional) Location of the business
Location *Location `json:"location"`
}

type BusinessOpeningHoursInterval struct {
// 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"`

// 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
ClosingMinute int `json:"closing_minute"`
}

type BusinessOpeningHours struct {
// Unique name of the time zone for which the opening hours are defined
Timezone string `json:"time_zone_name"`

// List of time intervals describing business opening hours
OpeningHours []BusinessOpeningHoursInterval `json:"opening_hours"`
}

// BusinessConnection returns the information about the connection of the bot with a business account.
func (b *Bot) BusinessConnection(id string) (*BusinessConnection, error) {
params := map[string]string{
"business_connection_id": id,
}

data, err := b.Raw("getBusinessConnection", params)
if err != nil {
return nil, err
}

var resp struct {
Result *BusinessConnection
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}
75 changes: 46 additions & 29 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ type User struct {
CustomEmojiStatus string `json:"emoji_status_custom_emoji_id"`

// Returns only in getMe
CanJoinGroups bool `json:"can_join_groups"`
CanReadMessages bool `json:"can_read_all_group_messages"`
SupportsInline bool `json:"supports_inline_queries"`
CanJoinGroups bool `json:"can_join_groups"`
CanReadMessages bool `json:"can_read_all_group_messages"`
SupportsInline bool `json:"supports_inline_queries"`
CanConnectToBusiness bool `json:"can_connect_to_business"`
}

// Recipient returns user ID (see Recipient interface).
Expand All @@ -47,33 +48,38 @@ type Chat struct {
Username string `json:"username"`

// Returns only in getChat
Bio string `json:"bio,omitempty"`
Photo *ChatPhoto `json:"photo,omitempty"`
Description string `json:"description,omitempty"`
InviteLink string `json:"invite_link,omitempty"`
PinnedMessage *Message `json:"pinned_message,omitempty"`
Permissions *Rights `json:"permissions,omitempty"`
Reactions []Reaction `json:"available_reactions"`
SlowMode int `json:"slow_mode_delay,omitempty"`
StickerSet string `json:"sticker_set_name,omitempty"`
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
CustomEmojiSetName string `json:"custom_emoji_sticker_set_name"`
LinkedChatID int64 `json:"linked_chat_id,omitempty"`
ChatLocation *ChatLocation `json:"location,omitempty"`
Private bool `json:"has_private_forwards,omitempty"`
Protected bool `json:"has_protected_content,omitempty"`
NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"`
HasHiddenMembers bool `json:"has_hidden_members,omitempty"`
AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"`
CustomEmojiID string `json:"emoji_status_custom_emoji_id"`
EmojiExpirationUnixtime int64 `json:"emoji_status_expiration_date"`
BackgroundEmojiID string `json:"background_custom_emoji_id"`
AccentColorID int `json:"accent_color_id"`
ProfileAccentColorID int `json:"profile_accent_color_id"`
ProfileBackgroundEmojiID string `json:"profile_background_custom_emoji_id"`
HasVisibleHistory bool `json:"has_visible_history"`
UnrestrictBoosts int `json:"unrestrict_boost_count"`
Bio string `json:"bio,omitempty"`
Photo *ChatPhoto `json:"photo,omitempty"`
Description string `json:"description,omitempty"`
InviteLink string `json:"invite_link,omitempty"`
PinnedMessage *Message `json:"pinned_message,omitempty"`
Permissions *Rights `json:"permissions,omitempty"`
Reactions []Reaction `json:"available_reactions"`
SlowMode int `json:"slow_mode_delay,omitempty"`
StickerSet string `json:"sticker_set_name,omitempty"`
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
CustomEmojiSetName string `json:"custom_emoji_sticker_set_name"`
LinkedChatID int64 `json:"linked_chat_id,omitempty"`
ChatLocation *ChatLocation `json:"location,omitempty"`
Private bool `json:"has_private_forwards,omitempty"`
Protected bool `json:"has_protected_content,omitempty"`
NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"`
HasHiddenMembers bool `json:"has_hidden_members,omitempty"`
AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"`
CustomEmojiID string `json:"emoji_status_custom_emoji_id"`
EmojiExpirationUnixtime int64 `json:"emoji_status_expiration_date"`
BackgroundEmojiID string `json:"background_custom_emoji_id"`
AccentColorID int `json:"accent_color_id"`
ProfileAccentColorID int `json:"profile_accent_color_id"`
ProfileBackgroundEmojiID string `json:"profile_background_custom_emoji_id"`
HasVisibleHistory bool `json:"has_visible_history"`
UnrestrictBoosts int `json:"unrestrict_boost_count"`
MaxReactionCount int `json:"max_reaction_count"`
Birthdate Birthdate `json:"birthdate,omitempty"`
PersonalChat *Chat `json:"personal_chat,omitempty"`
BusinessIntro BusinessIntro `json:"business_intro,omitempty"`
BusinessLocation BusinessLocation `json:"business_location,omitempty"`
BusinessOpeningHours BusinessOpeningHours `json:"business_opening_hours,omitempty"`
}

// Recipient returns chat ID (see Recipient interface).
Expand Down Expand Up @@ -321,6 +327,17 @@ type ChatBackground struct {
Type BackgroundType `json:"type"`
}

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"`

// (Optional) Year of the user's birth
Year int `json:"year"`
}

// ExpireDate returns the moment of the link expiration in local time.
func (c *ChatInviteLink) ExpireDate() time.Time {
return time.Unix(c.ExpireUnixtime, 0)
Expand Down
37 changes: 27 additions & 10 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,37 @@ type ReplyRecipient struct {
Premium *bool `json:"user_is_premium,omitempty"` // user only, optional
Quantity int `json:"max_quantity,omitempty"` // user only, optional

Channel bool `json:"chat_is_channel,omitempty"` // chat only, required
Forum *bool `json:"chat_is_forum,omitempty"` // chat only, optional
WithUsername *bool `json:"chat_has_username,omitempty"` // chat only, optional
Created *bool `json:"chat_is_created,omitempty"` // chat only, optional
UserRights *Rights `json:"user_administrator_rights,omitempty"` // chat only, optional
BotRights *Rights `json:"bot_administrator_rights,omitempty"` // chat only, optional
BotMember *bool `json:"bot_is_member,omitempty"` // chat only, optional
Channel bool `json:"chat_is_channel,omitempty"` // chat only, required
Forum *bool `json:"chat_is_forum,omitempty"` // chat only, optional
WithUsername *bool `json:"chat_has_username,omitempty"` // chat only, optional
Created *bool `json:"chat_is_created,omitempty"` // chat only, optional
UserRights *Rights `json:"user_administrator_rights,omitempty"` // chat only, optional
BotRights *Rights `json:"bot_administrator_rights,omitempty"` // chat only, optional
BotMember *bool `json:"bot_is_member,omitempty"` // chat only, optional
RequestTitle *bool `json:"request_title,omitempty"` // chat only, optional
RequestName *bool `json:"request_name,omitempty"` // user only, optional
RequestUsername *bool `json:"request_username,omitempty"` // user only, optional
RequestPhoto *bool `json:"request_photo,omitempty"` // user only, optional
}

// RecipientShared combines both UserShared and ChatShared objects.
type RecipientShared struct {
ID int32 `json:"request_id"`
UserID int64 `json:"user_id"`
ChatID int64 `json:"chat_id"`
ID int32 `json:"request_id"` // chat, users
Users []SharedUser `json:"users"` // users only
ChatID int64 `json:"chat_id"` // chat only
Title string `json:"title"` // chat only
Username string `json:"username"` // chat only
Photo *Photo `json:"photo"` // chat only
}

// SharedUser contains information about a user that was shared
// with the bot using a KeyboardButtonRequestUsers button.
type SharedUser struct {
UserID int64 `json:"user_id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
Photo []photoSize `json:"photo"`
}

// InlineButton represents a button displayed in the message.
Expand Down
14 changes: 14 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type Message struct {
// (Optional) Message can't be forwarded.
Protected bool `json:"has_protected_content,omitempty"`

// (Optional) 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
FromOffline bool `json:"is_from_offline,omitempty"`

// AlbumID is the unique identifier of a media message group
// this message belongs to.
AlbumID string `json:"media_group_id"`
Expand Down Expand Up @@ -169,6 +173,16 @@ type Message struct {
// (Optional) Service message: a giveaway without public winners was completed.
GiveawayCompleted *GiveawayCompleted `json:"giveaway_completed"`

// (Optional) 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.
BusinessConnectionID string `json:"business_connection_id"`

// (Optional) 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.
BusinessBot *User `json:"sender_business_bot"`

// For a service message, represents a user,
// that just got added to chat, this message came from.
//
Expand Down
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type SendOptions struct {

// ReplyParams Describes the message to reply to
ReplyParams *ReplyParams

// Unique identifier of the business connection
BusinessConnectionID string
}

func (og *SendOptions) copy() *SendOptions {
Expand Down
39 changes: 32 additions & 7 deletions sticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ type StickerSet struct {
Format StickerSetFormat `json:"sticker_format"`
Name string `json:"name"`
Title string `json:"title"`
Animated bool `json:"is_animated"`
Video bool `json:"is_video"`
Stickers []Sticker `json:"stickers"`
Thumbnail *Photo `json:"thumbnail"`
Emojis string `json:"emojis"`
Expand All @@ -55,6 +53,7 @@ type StickerSet struct {
type InputSticker struct {
File
Sticker string `json:"sticker"`
Format string `json:"format"`
MaskPosition *MaskPosition `json:"mask_position"`
Emojis []string `json:"emoji_list"`
Keywords []string `json:"keywords"`
Expand Down Expand Up @@ -120,11 +119,10 @@ func (b *Bot) CreateStickerSet(of Recipient, set *StickerSet) error {
data, _ := json.Marshal(set.Input)

params := map[string]string{
"user_id": of.Recipient(),
"name": set.Name,
"title": set.Title,
"sticker_format": set.Format,
"stickers": string(data),
"user_id": of.Recipient(),
"name": set.Name,
"title": set.Title,
"stickers": string(data),
}
if set.Type != "" {
params["sticker_type"] = set.Type
Expand Down Expand Up @@ -198,6 +196,7 @@ func (b *Bot) SetStickerSetThumb(of Recipient, set *StickerSet) error {
params := map[string]string{
"user_id": of.Recipient(),
"name": set.Name,
"format": set.Format,
"thumbnail": repr,
}

Expand Down Expand Up @@ -304,3 +303,29 @@ func (b *Bot) SetCustomEmojiStickerSetThumb(name, id string) error {
_, err := b.Raw("setCustomEmojiStickerSetThumbnail", params)
return err
}

// ReplaceStickerInSet returns True on success, if existing sticker was replaced with a new one.
func (b *Bot) ReplaceStickerInSet(of Recipient, stickerSet, oldSticker string, sticker InputSticker) (bool, error) {
files := make(map[string]File)

repr := sticker.File.process("0", files)
if repr == "" {
return false, errors.New("telebot: sticker does not exist")
}
sticker.Sticker = repr

data, err := json.Marshal(sticker)
if err != nil {
return false, err
}

params := map[string]string{
"user_id": of.Recipient(),
"name": stickerSet,
"old_sticker": oldSticker,
"sticker": string(data),
}

_, err = b.sendFiles("replaceStickerInSet", files, params)
return true, err
}
5 changes: 5 additions & 0 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ const (

OnBoost = "\aboost_updated"
OnBoostRemoved = "\aboost_removed"

OnBusinessConnection = "\abusiness_connection"
OnBusinessMessage = "\abusiness_message"
OnEditedBusinessMessage = "\aedited_business_message"
OnDeletedBusinessMessages = "\adeleted_business_messages"
)

// ChatAction is a client-side status indicating bot activity.
Expand Down
Loading

0 comments on commit a49a37d

Please sign in to comment.