api: update to 6.4 (#606)

Co-authored-by: Demian <optigan@protonmail.com>
pull/625/head^2
Nikita 6 months ago committed by GitHub
parent 03dcac73d8
commit fb8ce2a4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
}
@ -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
}

@ -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).

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

@ -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

@ -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,

@ -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 {
@ -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) {

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

@ -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.
@ -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{}
@ -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
}

@ -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))

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

Loading…
Cancel
Save