1
0
Fork 0

👽 Updated code to Bot API v4.5

This commit is contained in:
Maxim Lebedev 2020-01-07 02:41:22 +05:00
parent 5f0d7efc61
commit 7659fbb9f5
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
3 changed files with 207 additions and 128 deletions

164
const.go
View File

@ -37,94 +37,98 @@ const (
// Entity represents available and supported entity types // Entity represents available and supported entity types
const ( const (
EntityBold string = "bold" EntityBold string = "bold"
EntityBotCommand string = "bot_command" EntityBotCommand string = "bot_command"
EntityCashtag string = "cashtag" EntityCashtag string = "cashtag"
EntityCode string = "code" EntityCode string = "code"
EntityEmail string = "email" EntityEmail string = "email"
EntityHashtag string = "hashtag" EntityHashtag string = "hashtag"
EntityItalic string = "italic" EntityItalic string = "italic"
EntityMention string = "mention" EntityMention string = "mention"
EntityPhoneNumber string = "phone_number" EntityPhoneNumber string = "phone_number"
EntityPre string = "pre" EntityPre string = "pre"
EntityTextLink string = "text_link" EntityStrikethrough string = "strikethrough"
EntityTextMention string = "text_mention" EntityTextLink string = "text_link"
EntityURL string = "url" EntityTextMention string = "text_mention"
EntityUnderline string = "underline"
EntityURL string = "url"
) )
// Method represents available and supported Telegram API methods // Method represents available and supported Telegram API methods
const ( const (
MethodAddStickerToSet string = "addStickerToSet" MethodAddStickerToSet string = "addStickerToSet"
MethodAnswerCallbackQuery string = "answerCallbackQuery" MethodAnswerCallbackQuery string = "answerCallbackQuery"
MethodAnswerInlineQuery string = "answerInlineQuery" MethodAnswerInlineQuery string = "answerInlineQuery"
MethodAnswerPreCheckoutQuery string = "answerPreCheckoutQuery" MethodAnswerPreCheckoutQuery string = "answerPreCheckoutQuery"
MethodAnswerShippingQuery string = "answerShippingQuery" MethodAnswerShippingQuery string = "answerShippingQuery"
MethodCreateNewStickerSet string = "createNewStickerSet" MethodCreateNewStickerSet string = "createNewStickerSet"
MethodDeleteChatPhoto string = "deleteChatPhoto" MethodDeleteChatPhoto string = "deleteChatPhoto"
MethodDeleteChatStickerSet string = "deleteChatStickerSet" MethodDeleteChatStickerSet string = "deleteChatStickerSet"
MethodDeleteMessage string = "deleteMessage" MethodDeleteMessage string = "deleteMessage"
MethodDeleteStickerFromSet string = "deleteStickerFromSet" MethodDeleteStickerFromSet string = "deleteStickerFromSet"
MethodDeleteWebhook string = "deleteWebhook" MethodDeleteWebhook string = "deleteWebhook"
MethodEditMessageCaption string = "editMessageCaption" MethodEditMessageCaption string = "editMessageCaption"
MethodEditMessageLiveLocation string = "editMessageLiveLocation" MethodEditMessageLiveLocation string = "editMessageLiveLocation"
MethodEditMessageMedia string = "editMessageMedia" MethodEditMessageMedia string = "editMessageMedia"
MethodEditMessageReplyMarkup string = "editMessageReplyMarkup" MethodEditMessageReplyMarkup string = "editMessageReplyMarkup"
MethodEditMessageText string = "editMessageText" MethodEditMessageText string = "editMessageText"
MethodExportChatInviteLink string = "exportChatInviteLink" MethodExportChatInviteLink string = "exportChatInviteLink"
MethodForwardMessage string = "forwardMessage" MethodForwardMessage string = "forwardMessage"
MethodGetChat string = "getChat" MethodGetChat string = "getChat"
MethodGetChatAdministrators string = "getChatAdministrators" MethodGetChatAdministrators string = "getChatAdministrators"
MethodGetChatMember string = "getChatMember" MethodGetChatMember string = "getChatMember"
MethodGetChatMembersCount string = "getChatMembersCount" MethodGetChatMembersCount string = "getChatMembersCount"
MethodGetFile string = "getFile" MethodGetFile string = "getFile"
MethodGetGameHighScores string = "getGameHighScores" MethodGetGameHighScores string = "getGameHighScores"
MethodGetMe string = "getMe" MethodGetMe string = "getMe"
MethodGetStickerSet string = "getStickerSet" MethodGetStickerSet string = "getStickerSet"
MethodGetUpdates string = "getUpdates" MethodGetUpdates string = "getUpdates"
MethodGetUserProfilePhotos string = "getUserProfilePhotos" MethodGetUserProfilePhotos string = "getUserProfilePhotos"
MethodGetWebhookInfo string = "getWebhookInfo" MethodGetWebhookInfo string = "getWebhookInfo"
MethodKickChatMember string = "kickChatMember" MethodKickChatMember string = "kickChatMember"
MethodLeaveChat string = "leaveChat" MethodLeaveChat string = "leaveChat"
MethodPinChatMessage string = "pinChatMessage" MethodPinChatMessage string = "pinChatMessage"
MethodPromoteChatMember string = "promoteChatMember" MethodPromoteChatMember string = "promoteChatMember"
MethodRestrictChatMember string = "restrictChatMember" MethodRestrictChatMember string = "restrictChatMember"
MethodSendAnimation string = "sendAnimation" MethodSendAnimation string = "sendAnimation"
MethodSendAudio string = "sendAudio" MethodSendAudio string = "sendAudio"
MethodSendChatAction string = "sendChatAction" MethodSendChatAction string = "sendChatAction"
MethodSendContact string = "sendContact" MethodSendContact string = "sendContact"
MethodSendDocument string = "sendDocument" MethodSendDocument string = "sendDocument"
MethodSendGame string = "sendGame" MethodSendGame string = "sendGame"
MethodSendInvoice string = "sendInvoice" MethodSendInvoice string = "sendInvoice"
MethodSendLocation string = "sendLocation" MethodSendLocation string = "sendLocation"
MethodSendMediaGroup string = "sendMediaGroup" MethodSendMediaGroup string = "sendMediaGroup"
MethodSendMessage string = "sendMessage" MethodSendMessage string = "sendMessage"
MethodSendPhoto string = "sendPhoto" MethodSendPhoto string = "sendPhoto"
MethodSendPoll string = "sendPoll" MethodSendPoll string = "sendPoll"
MethodSendSticker string = "sendSticker" MethodSendSticker string = "sendSticker"
MethodSendVenue string = "sendVenue" MethodSendVenue string = "sendVenue"
MethodSendVideo string = "sendVideo" MethodSendVideo string = "sendVideo"
MethodSendVideoNote string = "sendVideoNote" MethodSendVideoNote string = "sendVideoNote"
MethodSendVoice string = "sendVoice" MethodSendVoice string = "sendVoice"
MethodSetChatDescription string = "setChatDescription" MethodSetChatAdministratorCustomTitle string = "setChatAdministratorCustomTitle"
MethodSetChatPermissions string = "setChatPermissions" MethodSetChatDescription string = "setChatDescription"
MethodSetChatPhoto string = "setChatPhoto" MethodSetChatPermissions string = "setChatPermissions"
MethodSetChatStickerSet string = "setChatStickerSet" MethodSetChatPhoto string = "setChatPhoto"
MethodSetChatTitle string = "setChatTitle" MethodSetChatStickerSet string = "setChatStickerSet"
MethodSetGameScore string = "setGameScore" MethodSetChatTitle string = "setChatTitle"
MethodSetPassportDataErrors string = "setPassportDataErrors" MethodSetGameScore string = "setGameScore"
MethodSetStickerPositionInSet string = "setStickerPositionInSet" MethodSetPassportDataErrors string = "setPassportDataErrors"
MethodSetWebhook string = "setWebhook" MethodSetStickerPositionInSet string = "setStickerPositionInSet"
MethodStopMessageLiveLocation string = "stopMessageLiveLocation" MethodSetWebhook string = "setWebhook"
MethodStopPoll string = "stopPoll" MethodStopMessageLiveLocation string = "stopMessageLiveLocation"
MethodUnbanChatMember string = "unbanChatMember" MethodStopPoll string = "stopPoll"
MethodUnpinChatMessage string = "unpinChatMessage" MethodUnbanChatMember string = "unbanChatMember"
MethodUploadStickerFile string = "uploadStickerFile" MethodUnpinChatMessage string = "unpinChatMessage"
MethodUploadStickerFile string = "uploadStickerFile"
) )
// Mode represents available and supported parsing modes of messages // Mode represents available and supported parsing modes of messages
const ( const (
StyleHTML string = "html" ParseModeHTML string = "HTML"
StyleMarkdown string = "markdown" ParseModeMarkdown string = "Markdown"
ParseModeMarkdownV2 string = "MarkdownV2"
) )
// Mime represents available and supported MIME types of data // Mime represents available and supported MIME types of data

28
set.go
View File

@ -128,6 +128,17 @@ type (
// New default chat permissions // New default chat permissions
Permissions ChatPermissions `json:"permissions"` Permissions ChatPermissions `json:"permissions"`
} }
SetChatAdministratorCustomTitle struct {
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Unique identifier of the target user
UserID int `json:"user_id"`
// New custom title for the administrator; 0-16 characters, emoji are not allowed
CustomTitle string `json:"custom_title"`
}
) )
// NewWebhook creates new SetWebhookParameters only with required parameters. // NewWebhook creates new SetWebhookParameters only with required parameters.
@ -368,3 +379,20 @@ func (b *Bot) SetChatPermissions(params SetChatPermissionsParameters) (bool, err
err = parser.Unmarshal(resp.Result, &ok) err = parser.Unmarshal(resp.Result, &ok)
return ok, err return ok, err
} }
// SetChatAdministratorCustomTitle method to set a custom title for an administrator in a supergroup promoted by the bot. Returns True on success.
func (b *Bot) SetChatAdministratorCustomTitle(params SetChatAdministratorCustomTitle) (bool, error) {
dst, err := parser.Marshal(&params)
if err != nil {
return false, err
}
resp, err := b.request(dst, MethodSetChatAdministratorCustomTitle)
if err != nil {
return false, err
}
var ok bool
err = parser.Unmarshal(resp.Result, &ok)
return ok, err
}

143
types.go
View File

@ -10,7 +10,7 @@ type (
// especially handy if youre using Webhooks, since it allows you to // especially handy if youre using Webhooks, since it allows you to
// ignore repeated updates or to restore the correct update sequence, // ignore repeated updates or to restore the correct update sequence,
// should they get out of order. // should they get out of order.
ID int `json:"update_id"` UpdateID int `json:"update_id"`
// New incoming message of any kind — text, photo, sticker, etc. // New incoming message of any kind — text, photo, sticker, etc.
Message *Message `json:"message,omitempty"` Message *Message `json:"message,omitempty"`
@ -132,6 +132,9 @@ type (
// Default chat member permissions, for groups and supergroups. Returned only in getChat. // Default chat member permissions, for groups and supergroups. Returned only in getChat.
Permissions *ChatPermissions `json:"permissions,omitempty"` Permissions *ChatPermissions `json:"permissions,omitempty"`
// For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. Returned only in getChat.
SlowModeDelay int `json:"slow_mode_delay,omitempty"`
// For supergroups, name of Group sticker set. Returned only in getChat. // For supergroups, name of Group sticker set. Returned only in getChat.
StickerSetName string `json:"sticker_set_name,omitempty"` StickerSetName string `json:"sticker_set_name,omitempty"`
@ -336,9 +339,12 @@ type (
// PhotoSize represents one size of a photo or a file / sticker thumbnail. // PhotoSize represents one size of a photo or a file / sticker thumbnail.
PhotoSize struct { PhotoSize struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// Photo width // Photo width
Width int `json:"width"` Width int `json:"width"`
@ -352,9 +358,15 @@ type (
// Audio represents an audio file to be treated as music by the Telegram // Audio represents an audio file to be treated as music by the Telegram
// clients. // clients.
Audio struct { Audio struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// Duration of the audio in seconds as defined by sender
Duration int `json:"duration"`
// Performer of the audio as defined by sender or by audio tags // Performer of the audio as defined by sender or by audio tags
Performer string `json:"performer,omitempty"` Performer string `json:"performer,omitempty"`
@ -364,9 +376,6 @@ type (
// MIME type of the file as defined by sender // MIME type of the file as defined by sender
MimeType string `json:"mime_type,omitempty"` MimeType string `json:"mime_type,omitempty"`
// Duration of the audio in seconds as defined by sender
Duration int `json:"duration"`
// File size // File size
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
@ -377,29 +386,32 @@ type (
// Document represents a general file (as opposed to photos, voice messages // Document represents a general file (as opposed to photos, voice messages
// and audio files). // and audio files).
Document struct { Document struct {
// Unique file identifier // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// Document thumbnail as defined by sender
Thumb *PhotoSize `json:"thumb,omitempty"`
// Original filename as defined by sender // Original filename as defined by sender
FileName string `json:"file_name,omitempty"` FileName string `json:"file_name,omitempty"`
// MIME type of the file as defined by sender // MIME type of the file as defined by sender
MimeType string `json:"mime_type,omitempty"` MimeType string `json:"mime_type,omitempty"`
// Document thumbnail as defined by sender
Thumb *PhotoSize `json:"thumb,omitempty"`
// File size // File size
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
} }
// Video represents a video file. // Video represents a video file.
Video struct { Video struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Mime type of a file as defined by sender // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
MimeType string `json:"mime_type,omitempty"` FileUniqueID string `json:"file_unique_id"`
// Video width as defined by sender // Video width as defined by sender
Width int `json:"width"` Width int `json:"width"`
@ -410,24 +422,30 @@ type (
// Duration of the video in seconds as defined by sender // Duration of the video in seconds as defined by sender
Duration int `json:"duration"` Duration int `json:"duration"`
// File size
FileSize int `json:"file_size,omitempty"`
// Video thumbnail // Video thumbnail
Thumb *PhotoSize `json:"thumb,omitempty"` Thumb *PhotoSize `json:"thumb,omitempty"`
// Mime type of a file as defined by sender
MimeType string `json:"mime_type,omitempty"`
// File size
FileSize int `json:"file_size,omitempty"`
} }
// Voice represents a voice note. // Voice represents a voice note.
Voice struct { Voice struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// MIME type of the file as defined by sender // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
MimeType string `json:"mime_type,omitempty"` FileUniqueID string `json:"file_unique_id"`
// Duration of the audio in seconds as defined by sender // Duration of the audio in seconds as defined by sender
Duration int `json:"duration"` Duration int `json:"duration"`
// MIME type of the file as defined by sender
MimeType string `json:"mime_type,omitempty"`
// File size // File size
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
} }
@ -435,20 +453,23 @@ type (
// VideoNote represents a video message (available in Telegram apps as of // VideoNote represents a video message (available in Telegram apps as of
// v.4.0). // v.4.0).
VideoNote struct { VideoNote struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// Video width and height (diameter of the video message) as defined by sender // Video width and height (diameter of the video message) as defined by sender
Length int `json:"length"` Length int `json:"length"`
// Duration of the video in seconds as defined by sender // Duration of the video in seconds as defined by sender
Duration int `json:"duration"` Duration int `json:"duration"`
// File size
FileSize int `json:"file_size,omitempty"`
// Video thumbnail // Video thumbnail
Thumb *PhotoSize `json:"thumb,omitempty"` Thumb *PhotoSize `json:"thumb,omitempty"`
// File size
FileSize int `json:"file_size,omitempty"`
} }
// Contact represents a phone contact. // Contact represents a phone contact.
@ -538,15 +559,18 @@ type (
// //
// Maximum file size to download is 20 MB // Maximum file size to download is 20 MB
File struct { File struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// File size, if known
FileSize int `json:"file_size,omitempty"`
// File path. Use https://api.telegram.org/file/bot<token>/<file_path> to // File path. Use https://api.telegram.org/file/bot<token>/<file_path> to
// get the file. // get the file.
FilePath string `json:"file_path,omitempty"` FilePath string `json:"file_path,omitempty"`
// File size, if known
FileSize int `json:"file_size,omitempty"`
} }
// ReplyKeyboardMarkup represents a custom keyboard with reply options (see // ReplyKeyboardMarkup represents a custom keyboard with reply options (see
@ -761,15 +785,17 @@ type (
// ChatPhoto represents a chat photo. // ChatPhoto represents a chat photo.
ChatPhoto struct { ChatPhoto struct {
// Unique file identifier of small (160x160) chat photo. This file_id can // File identifier of small (160x160) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed.
// be used only for photo download. This file_id can be used only for photo download and only for as
// long as the photo is not changed.
SmallFileID string `json:"small_file_id"` SmallFileID string `json:"small_file_id"`
// Unique file identifier of big (640x640) chat photo. This file_id can // Unique file identifier of small (160x160) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
// be used only for photo download. This file_id can be used only for photo download and only for as SmallFileUniqueID string `json:"small_file_unique_id"`
// long as the photo is not changed.
// File identifier of big (640x640) chat photo. This file_id can be used only for photo download and only for as long as the photo is not changed.
BigFileID string `json:"big_file_id"` BigFileID string `json:"big_file_id"`
// Unique file identifier of big (640x640) chat photo, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
BigFileUniqueID string `json:"big_file_unique_id"`
} }
// ChatMember contains information about one member of a chat. // ChatMember contains information about one member of a chat.
@ -781,6 +807,9 @@ type (
// or "kicked" // or "kicked"
Status string `json:"status"` Status string `json:"status"`
// Owner and administrators only. Custom title for this user
CustomTitle string `json:"custom_title,omitempty"`
// Restictred and kicked only. Date when restrictions will be lifted for this user, unix time // Restictred and kicked only. Date when restrictions will be lifted for this user, unix time
UntilDate int64 `json:"until_date,omitempty"` UntilDate int64 `json:"until_date,omitempty"`
@ -1060,15 +1089,27 @@ type (
// Unique file identifier // Unique file identifier
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// Video width as defined by sender
Width int `json:"width"`
// Video height as defined by sender
Height int `json:"height"`
// Duration of the video in seconds as defined by sender
Duration int `json:"duration"`
// Animation thumbnail as defined by sender
Thumb *PhotoSize `json:"thumb,omitempty"`
// Original animation filename as defined by sender // Original animation filename as defined by sender
FileName string `json:"file_name,omitempty"` FileName string `json:"file_name,omitempty"`
// MIME type of the file as defined by sender // MIME type of the file as defined by sender
MimeType string `json:"mime_type,omitempty"` MimeType string `json:"mime_type,omitempty"`
// Animation thumbnail as defined by sender
Thumb *PhotoSize `json:"thumb,omitempty"`
// File size // File size
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
} }
@ -2191,14 +2232,17 @@ type (
// Telegram Passport files are in JPEG format when decrypted and don't exceed // Telegram Passport files are in JPEG format when decrypted and don't exceed
// 10MB. // 10MB.
PassportFile struct { PassportFile struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"`
// File size // File size
FileSize int `json:"file_size"` FileSize int `json:"file_size"`
// Unix time when the file was uploaded // Unix time when the file was uploaded
FileDate int64 `json:"file_date"` FileDate int `json:"file_date"`
} }
// Credentials is a JSON-serialized object. // Credentials is a JSON-serialized object.
@ -2698,14 +2742,11 @@ type (
// Sticker represents a sticker. // Sticker represents a sticker.
Sticker struct { Sticker struct {
// Unique identifier for this file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Emoji associated with the sticker // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
Emoji string `json:"emoji,omitempty"` FileUniqueID string `json:"file_unique_id"`
// Name of the sticker set to which the sticker belongs
SetName string `json:"set_name,omitempty"`
// Sticker width // Sticker width
Width int `json:"width"` Width int `json:"width"`
@ -2713,17 +2754,23 @@ type (
// Sticker height // Sticker height
Height int `json:"height"` Height int `json:"height"`
// File size // true, if the sticker is animated
FileSize int `json:"file_size,omitempty"` IsAnimated bool `json:"is_animated"`
// Sticker thumbnail in the .webp or .jpg format // Sticker thumbnail in the .webp or .jpg format
Thumb *PhotoSize `json:"thumb,omitempty"` Thumb *PhotoSize `json:"thumb,omitempty"`
// Emoji associated with the sticker
Emoji string `json:"emoji,omitempty"`
// Name of the sticker set to which the sticker belongs
SetName string `json:"set_name,omitempty"`
// For mask stickers, the position where the mask should be placed // For mask stickers, the position where the mask should be placed
MaskPosition *MaskPosition `json:"mask_position,omitempty"` MaskPosition *MaskPosition `json:"mask_position,omitempty"`
// true, if the sticker is animated // File size
IsAnimated bool `json:"is_animated"` FileSize int `json:"file_size,omitempty"`
} }
// StickerSet represents a sticker set. // StickerSet represents a sticker set.