Skip to content

Commit

Permalink
api: implement 6.6, 6.7 features (#655)
Browse files Browse the repository at this point in the history
* api: implement 6.6-6.7 features
  • Loading branch information
Nash-Well authored Feb 27, 2024
1 parent 9c4cc77 commit 32b47a4
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 91 deletions.
76 changes: 76 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,3 +1161,79 @@ func (b *Bot) Close() (bool, error) {

return resp.Result, nil
}

// BotInfo represents a single object of BotName, BotDescription, BotShortDescription instances.
type BotInfo struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ShortDescription string `json:"short_description,omitempty"`
}

// SetMyName change's the bot name.
func (b *Bot) SetMyName(name, language string) error {
params := map[string]string{
"name": name,
"language_code": language,
}

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

// MyName returns the current bot name for the given user language.
func (b *Bot) MyName(language string) (*BotInfo, error) {
return b.botInfo(language, "getMyName")
}

// SetMyDescription change's the bot description, which is shown in the chat
// with the bot if the chat is empty.
func (b *Bot) SetMyDescription(desc, language string) error {
params := map[string]string{
"description": desc,
"language_code": language,
}

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

// MyDescription the current bot description for the given user language.
func (b *Bot) MyDescription(language string) (*BotInfo, error) {
return b.botInfo(language, "getMyDescription")
}

// SetMyShortDescription change's the bot short description, which is shown on
// the bot's profile page and is sent together with the link when users share the bot.
func (b *Bot) SetMyShortDescription(desc, language string) error {
params := map[string]string{
"short_description": desc,
"language_code": language,
}

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

// MyShortDescription the current bot short description for the given user language.
func (b *Bot) MyShortDescription(language string) (*BotInfo, error) {
return b.botInfo(language, "getMyShortDescription")
}

func (b *Bot) botInfo(language, key string) (*BotInfo, error) {
params := map[string]string{
"language_code": language,
}

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

var resp struct {
Result *BotInfo
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
}
3 changes: 3 additions & 0 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ type ChatMemberUpdate struct {
// (Optional) InviteLink which was used by the user to
// join the chat; for joining by invite link events only.
InviteLink *ChatInviteLink `json:"invite_link"`

// (Optional) True, if the user joined the chat via a chat folder invite link.
ViaFolderLink bool `json:"via_chat_folder_invite_link"`
}

// Time returns the moment of the change in local time.
Expand Down
40 changes: 40 additions & 0 deletions inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,46 @@ type QueryResponse struct {
// (Optional) Parameter for the start message sent to the bot when user
// presses the switch button.
SwitchPMParameter string `json:"switch_pm_parameter,omitempty"`

// (Optional) A JSON-serialized object describing a button to be shown
// above inline query results.
Button *QueryResponseButton `json:"button,omitempty"`
}

// QueryResponseButton represents a button to be shown above inline query results.
// You must use exactly one of the optional fields.
type QueryResponseButton struct {
// Label text on the button
Text string `json:"text"`

// (Optional) Description of the Web App that will be launched when the
// user presses the button. The Web App will be able to switch back to the
// inline mode using the method switchInlineQuery inside the Web App.
WebApp *WebApp `json:"web_app"`

// (Optional) Deep-linking parameter for the /start message sent to the bot
// when a user presses the button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
Start string `json:"start_parameter"`
}

// SwitchInlineQuery represents an inline button that switches the current
// user to inline mode in a chosen chat, with an optional default inline query.
type SwitchInlineQuery struct {
// (Optional) The default inline query to be inserted in the input field.
// If left empty, only the bot's username will be inserted.
Query string `json:"query"`

// (Optional) True, if private chats with users can be chosen.
AllowUserChats bool `json:"allow_user_chats"`

// (Optional) True, if private chats with bots can be chosen.
AllowBotChats bool `json:"allow_bot_chats"`

// (Optional) True, if group and supergroup chats can be chosen.
AllowGroupChats bool `json:"allow_group_chats"`

// (Optional) True, if channel chats can be chosen.
AllowChannelChats bool `json:"allow_channel_chats"`
}

// InlineResult represents a result of an inline query that was chosen
Expand Down
38 changes: 19 additions & 19 deletions inline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ type ArticleResult struct {
Description string `json:"description,omitempty"`

// Optional. URL of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`
}

// AudioResult represents a link to an mp3 audio file.
Expand Down Expand Up @@ -140,13 +140,13 @@ type ContactResult struct {
LastName string `json:"last_name,omitempty"`

// Optional. URL of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`
}

// DocumentResult represents a link to a file.
Expand All @@ -170,13 +170,13 @@ type DocumentResult struct {
Description string `json:"description,omitempty"`

// Optional. URL of the thumbnail (jpeg only) for the file.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`

// If Cache != "", it'll be used instead
Cache string `json:"document_file_id,omitempty"`
Expand All @@ -199,11 +199,11 @@ type GifResult struct {
Duration int `json:"gif_duration,omitempty"`

// URL of the static thumbnail for the result (jpeg or gif).
ThumbURL string `json:"thumb_url"`
ThumbURL string `json:"thumbnail_url"`

// Optional. MIME type of the thumbnail, must be one of
// “image/jpeg”, “image/gif”, or “video/mp4”.
ThumbMIME string `json:"thumb_mime_type,omitempty"`
ThumbMIME string `json:"thumbnail_mime_type,omitempty"`

// Optional. Title for the result.
Title string `json:"title,omitempty"`
Expand All @@ -225,7 +225,7 @@ type LocationResult struct {
Title string `json:"title"`

// Optional. Url of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`
}

// Mpeg4GifResult represents a link to a video animation
Expand All @@ -246,11 +246,11 @@ type Mpeg4GifResult struct {
Duration int `json:"mpeg4_duration,omitempty"`

// URL of the static thumbnail (jpeg or gif) for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. MIME type of the thumbnail, must be one of
// “image/jpeg”, “image/gif”, or “video/mp4”.
ThumbMIME string `json:"thumb_mime_type,omitempty"`
ThumbMIME string `json:"thumbnail_mime_type,omitempty"`

// Optional. Title for the result.
Title string `json:"title,omitempty"`
Expand Down Expand Up @@ -286,7 +286,7 @@ type PhotoResult struct {
Caption string `json:"caption,omitempty"`

// URL of the thumbnail for the photo.
ThumbURL string `json:"thumb_url"`
ThumbURL string `json:"thumbnail_url"`

// If Cache != "", it'll be used instead
Cache string `json:"photo_file_id,omitempty"`
Expand All @@ -308,13 +308,13 @@ type VenueResult struct {
FoursquareID string `json:"foursquare_id,omitempty"`

// Optional. URL of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`
}

// VideoResult represents a link to a page containing an embedded
Expand All @@ -329,7 +329,7 @@ type VideoResult struct {
MIME string `json:"mime_type"`

// URL of the thumbnail (jpeg only) for the video.
ThumbURL string `json:"thumb_url"`
ThumbURL string `json:"thumbnail_url"`

// Title for the result.
Title string `json:"title"`
Expand Down
2 changes: 1 addition & 1 deletion layout/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ results:
id: '{{ .ID }}'
title: '{{ .Title }}'
description: '{{ .Description }}'
thumb_url: '{{ .PreviewURL }}'
thumbnail_url: '{{ .PreviewURL }}'
message_text: '{{ text `article_message` }}'
15 changes: 8 additions & 7 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,14 @@ type InlineButton struct {
// It will be used as a callback endpoint.
Unique string `json:"unique,omitempty"`

Text string `json:"text"`
URL string `json:"url,omitempty"`
Data string `json:"callback_data,omitempty"`
InlineQuery string `json:"switch_inline_query,omitempty"`
InlineQueryChat string `json:"switch_inline_query_current_chat"`
Login *Login `json:"login_url,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
Text string `json:"text"`
URL string `json:"url,omitempty"`
Data string `json:"callback_data,omitempty"`
InlineQuery string `json:"switch_inline_query,omitempty"`
InlineQueryChat string `json:"switch_inline_query_current_chat"`
InlineQueryChosenChat *SwitchInlineQuery `json:"switch_inline_query_chosen_chat,omitempty"`
Login *Login `json:"login_url,omitempty"`
WebApp *WebApp `json:"web_app,omitempty"`
}

// MarshalJSON implements json.Marshaler interface.
Expand Down
23 changes: 16 additions & 7 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type InputMedia struct {
Type string `json:"type"`
Media string `json:"media"`
Caption string `json:"caption"`
Thumbnail string `json:"thumb,omitempty"`
Thumbnail string `json:"thumbnail,omitempty"`
ParseMode string `json:"parse_mode,omitempty"`
Entities Entities `json:"caption_entities,omitempty"`
Width int `json:"width,omitempty"`
Expand Down Expand Up @@ -113,7 +113,7 @@ type Audio struct {

// (Optional)
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Thumbnail *Photo `json:"thumbnail,omitempty"`
Title string `json:"title,omitempty"`
Performer string `json:"performer,omitempty"`
MIME string `json:"mime_type,omitempty"`
Expand Down Expand Up @@ -145,7 +145,7 @@ type Document struct {
File

// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
Thumbnail *Photo `json:"thumbnail,omitempty"`
Caption string `json:"caption,omitempty"`
MIME string `json:"mime_type"`
FileName string `json:"file_name,omitempty"`
Expand Down Expand Up @@ -179,7 +179,7 @@ type Video struct {

// (Optional)
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Thumbnail *Photo `json:"thumbnail,omitempty"`
Streaming bool `json:"supports_streaming,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
Expand Down Expand Up @@ -215,7 +215,7 @@ type Animation struct {

// (Optional)
Caption string `json:"caption,omitempty"`
Thumbnail *Photo `json:"thumb,omitempty"`
Thumbnail *Photo `json:"thumbnail,omitempty"`
MIME string `json:"mime_type,omitempty"`
FileName string `json:"file_name,omitempty"`
}
Expand Down Expand Up @@ -265,7 +265,7 @@ type VideoNote struct {
Duration int `json:"duration"`

// (Optional)
Thumbnail *Photo `json:"thumb,omitempty"`
Thumbnail *Photo `json:"thumbnail,omitempty"`
Length int `json:"length,omitempty"`
}

Expand All @@ -284,13 +284,16 @@ type Sticker struct {
Height int `json:"height"`
Animated bool `json:"is_animated"`
Video bool `json:"is_video"`
Thumbnail *Photo `json:"thumb"`
Thumbnail *Photo `json:"thumbnail"`
Emoji string `json:"emoji"`
SetName string `json:"set_name"`
MaskPosition *MaskPosition `json:"mask_position"`
PremiumAnimation *File `json:"premium_animation"`
Type StickerSetType `json:"type"`
CustomEmoji string `json:"custom_emoji_id"`
Repaint bool `json:"needs_repainting"`
Emojis []string `json:"emoji_list"`
Keywords []string `json:"keywords"`
}

func (s *Sticker) MediaType() string {
Expand All @@ -301,6 +304,12 @@ func (s *Sticker) MediaFile() *File {
return &s.File
}

func (s *Sticker) InputMedia() InputMedia {
return InputMedia{
Type: s.MediaType(),
}
}

// Contact object represents a contact to Telegram user.
type Contact struct {
PhoneNumber string `json:"phone_number"`
Expand Down
3 changes: 2 additions & 1 deletion sendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (d *Document) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error
func (s *Sticker) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {
params := map[string]string{
"chat_id": to.Recipient(),
"emoji": s.Emoji,
}
b.embedSendOptions(params, opt)

Expand Down Expand Up @@ -401,7 +402,7 @@ func (g *Game) Send(b *Bot, to Recipient, opt *SendOptions) (*Message, error) {

func thumbnailToFilemap(thumb *Photo) map[string]File {
if thumb != nil {
return map[string]File{"thumb": thumb.File}
return map[string]File{"thumbnail": thumb.File}
}
return nil
}
Loading

0 comments on commit 32b47a4

Please sign in to comment.