Skip to content

Commit

Permalink
api: update to 6.4 (tucnak#606)
Browse files Browse the repository at this point in the history
Co-authored-by: Demian <[email protected]>
  • Loading branch information
setval and demget authored Nov 19, 2023
1 parent 03dcac7 commit fb8ce2a
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 47 deletions.
6 changes: 5 additions & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (b *Bot) Delete(msg Editable) error {
//
// Currently, Telegram supports only a narrow range of possible
// actions, these are aligned as constants of this package.
func (b *Bot) Notify(to Recipient, action ChatAction) error {
func (b *Bot) Notify(to Recipient, action ChatAction, threadID ...int) error {
if to == nil {
return ErrBadRecipient
}
Expand All @@ -689,6 +689,10 @@ func (b *Bot) Notify(to Recipient, action ChatAction) error {
"action": string(action),
}

if len(threadID) > 0 {
params["message_thread_id"] = strconv.Itoa(threadID[0])
}

_, err := b.Raw("sendChatAction", params)
return err
}
Expand Down
30 changes: 16 additions & 14 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ 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"`
SlowMode int `json:"slow_mode_delay,omitempty"`
StickerSet string `json:"sticker_set_name,omitempty"`
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
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"`
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"`
SlowMode int `json:"slow_mode_delay,omitempty"`
StickerSet string `json:"sticker_set_name,omitempty"`
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
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"`
HiddenMembers bool `json:"has_hidden_members,omitempty"`
AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"`
}

// Recipient returns chat ID (see Recipient interface).
Expand Down
5 changes: 3 additions & 2 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type ReplyMarkup struct {

// Placeholder will be shown in the input field when the reply is active.
Placeholder string `json:"input_field_placeholder,omitempty"`

// IsPersistent allows to control when the keyboard is shown.
IsPersistent bool `json:"is_persistent,omitempty"`
}

func (r *ReplyMarkup) copy() *ReplyMarkup {
Expand Down Expand Up @@ -106,7 +109,6 @@ func (r *ReplyMarkup) Row(many ...Btn) Row {
//
// `Split(3, []Btn{six buttons...}) -> [[1, 2, 3], [4, 5, 6]]`
// `Split(2, []Btn{six buttons...}) -> [[1, 2],[3, 4],[5, 6]]`
//
func (r *ReplyMarkup) Split(max int, btns []Btn) []Row {
rows := make([]Row, (max-1+len(btns))/max)
for i, b := range btns {
Expand Down Expand Up @@ -202,7 +204,6 @@ func (r *ReplyMarkup) WebApp(text string, app *WebApp) Btn {
//
// Set either Contact or Location to true in order to request
// sensitive info, such as user's phone number or current location.
//
type ReplyButton struct {
Text string `json:"text"`

Expand Down
1 change: 1 addition & 0 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type InputMedia struct {
Performer string `json:"performer,omitempty"`
Streaming bool `json:"supports_streaming,omitempty"`
DisableTypeDetection bool `json:"disable_content_type_detection,omitempty"`
HasSpoiler bool `json:"is_spoiler,omitempty"`
}

// Inputtable is a generic type for all kinds of media you
Expand Down
15 changes: 15 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ type Message struct {

// Service message: forum topic reopened
TopicReopened *TopicReopened `json:"forum_topic_reopened,omitempty"`

// Service message: forum topic deleted
TopicEdited *TopicEdited `json:"forum_topic_edited,omitempty"`

// Service message: general forum topic hidden
GeneralTopicHidden *GeneralTopicHidden `json:"general_topic_hidden,omitempty"`

// Service message: general forum topic unhidden
GeneralTopicUnhidden *GeneralTopicUnhidden `json:"general_topic_unhidden,omitempty"`

// Service message: represents spoiler information about the message.
HasMediaSpoiler bool `json:"has_media_spoiler,omitempty"`

// Service message: the user allowed the bot added to the attachment menu to write messages
WriteAccessAllowed *WriteAccessAllowed `json:"write_access_allowed,omitempty"`
}

// MessageEntity object represents "special" parts of text messages,
Expand Down
8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type SendOptions struct {

// ThreadID supports sending messages to a thread.
ThreadID int

// HasSpoiler marks the message as containing a spoiler.
HasSpoiler bool

}

func (og *SendOptions) copy() *SendOptions {
Expand Down Expand Up @@ -194,6 +198,10 @@ func (b *Bot) embedSendOptions(params map[string]string, opt *SendOptions) {
if opt.ThreadID != 0 {
params["message_thread_id"] = strconv.Itoa(opt.ThreadID)
}

if opt.HasSpoiler {
params["spoiler"] = "true"
}
}

func processButtons(keys [][]InlineButton) {
Expand Down
54 changes: 29 additions & 25 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,35 @@ const DefaultApiURL = "https://api.telegram.org"
// an "alert" character \a.
const (
// Basic message handlers.
OnText = "\atext"
OnEdited = "\aedited"
OnPhoto = "\aphoto"
OnAudio = "\aaudio"
OnAnimation = "\aanimation"
OnDocument = "\adocument"
OnSticker = "\asticker"
OnVideo = "\avideo"
OnVoice = "\avoice"
OnVideoNote = "\avideo_note"
OnContact = "\acontact"
OnLocation = "\alocation"
OnVenue = "\avenue"
OnDice = "\adice"
OnInvoice = "\ainvoice"
OnPayment = "\apayment"
OnGame = "\agame"
OnPoll = "\apoll"
OnPollAnswer = "\apoll_answer"
OnPinned = "\apinned"
OnChannelPost = "\achannel_post"
OnEditedChannelPost = "\aedited_channel_post"
OnTopicCreated = "\atopic_created"
OnTopicReopened = "\atopic_reopened"
OnTopicClosed = "\atopic_closed"
OnText = "\atext"
OnEdited = "\aedited"
OnPhoto = "\aphoto"
OnAudio = "\aaudio"
OnAnimation = "\aanimation"
OnDocument = "\adocument"
OnSticker = "\asticker"
OnVideo = "\avideo"
OnVoice = "\avoice"
OnVideoNote = "\avideo_note"
OnContact = "\acontact"
OnLocation = "\alocation"
OnVenue = "\avenue"
OnDice = "\adice"
OnInvoice = "\ainvoice"
OnPayment = "\apayment"
OnGame = "\agame"
OnPoll = "\apoll"
OnPollAnswer = "\apoll_answer"
OnPinned = "\apinned"
OnChannelPost = "\achannel_post"
OnEditedChannelPost = "\aedited_channel_post"
OnTopicCreated = "\atopic_created"
OnTopicReopened = "\atopic_reopened"
OnTopicClosed = "\atopic_closed"
OnTopicEdited = "\atopic_edited"
OnGeneralTopicHidden = "\ageneral_topic_hidden"
OnGeneralTopicUnhidden = "\ageneral_topic_unhidden"
OnWriteAccessAllowed = "\awrite_access_allowed"

OnAddedToGroup = "\aadded_to_group"
OnUserJoined = "\auser_joined"
Expand Down
64 changes: 59 additions & 5 deletions topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ type Topic struct {
}

type (
TopicCreated struct{ Topic }
TopicClosed struct{}
TopicDeleted struct{ Topic }
TopicReopened struct{ Topic }
TopicCreated struct{ Topic }
TopicClosed struct{}
TopicDeleted struct{ Topic }
TopicReopened struct{ Topic }
TopicEdited struct{ Topic }
GeneralTopicHidden struct{}
GeneralTopicUnhidden struct{}
)

// CreateTopic creates a topic in a forum supergroup chat.
Expand Down Expand Up @@ -99,7 +102,7 @@ func (b *Bot) UnpinAllTopicMessages(chat *Chat, forum *Topic) error {
return err
}

// TopicIconStickers gets custom emoji stickers, which can be used as a forum topic icon by any user
// TopicIconStickers gets custom emoji stickers, which can be used as a forum topic icon by any user.
func (b *Bot) TopicIconStickers() ([]Sticker, error) {
params := map[string]string{}

Expand All @@ -116,3 +119,54 @@ func (b *Bot) TopicIconStickers() ([]Sticker, error) {
}
return resp.Result, nil
}

// EditGeneralTopic edits name of the 'General' topic in a forum supergroup chat.
func (b *Bot) EditGeneralTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
"name": forum.Name,
}

_, err := b.Raw("editGeneralForumTopic", params)
return err
}

// CloseGeneralTopic closes an open 'General' topic in a forum supergroup chat.
func (b *Bot) CloseGeneralTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}

_, err := b.Raw("closeGeneralForumTopic", params)
return err
}

// ReopenGeneralTopic reopens a closed 'General' topic in a forum supergroup chat.
func (b *Bot) ReopenGeneralTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}

_, err := b.Raw("reopenGeneralForumTopic", params)
return err
}

// HideGeneralTopic hides the 'General' topic in a forum supergroup chat.
func (b *Bot) HideGeneralTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}

_, err := b.Raw("hideGeneralForumTopic", params)
return err
}

// UnhideGeneralTopic unhides the 'General' topic in a forum supergroup chat.
func (b *Bot) UnhideGeneralTopic(chat *Chat, forum *Topic) error {
params := map[string]interface{}{
"chat_id": chat.Recipient(),
}

_, err := b.Raw("unhideGeneralForumTopic", params)
return err
}
16 changes: 16 additions & 0 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ func (b *Bot) ProcessUpdate(u Update) {
b.handle(OnTopicClosed, c)
return
}
if m.TopicEdited != nil {
b.handle(OnTopicEdited, c)
return
}
if m.GeneralTopicHidden != nil {
b.handle(OnGeneralTopicHidden, c)
return
}
if m.GeneralTopicUnhidden != nil {
b.handle(OnGeneralTopicUnhidden, c)
return
}
if m.WriteAccessAllowed != nil {
b.handle(OnWriteAccessAllowed, c)
return
}

wasAdded := (m.UserJoined != nil && m.UserJoined.ID == b.Me.ID) ||
(m.UsersJoined != nil && isUserInList(b.Me, m.UsersJoined))
Expand Down
6 changes: 6 additions & 0 deletions web_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ type WebAppData struct {
Data string `json:"data"`
Text string `json:"button_text"`
}

// WebAppAccessAllowed represents a service message about a user allowing
// a bot to write messages after adding the bot to the attachment menu or launching a Web App from a link.
type WriteAccessAllowed struct {
WebAppName string `json:"web_app_name,omitempty"`
}

0 comments on commit fb8ce2a

Please sign in to comment.