From 61aa4b5a64134bbb32986aa42d39a07e2e169e92 Mon Sep 17 00:00:00 2001 From: ramin Date: Tue, 24 Sep 2024 18:04:05 +0330 Subject: [PATCH] Initial commit --- .gitignore | 3 + README.md | 260 + SECURITY.md | 21 + client/Client.go | 69 + config/config.go | 158 + examples/basic/simpleBot.go | 22 + examples/basic/simpleBotWithClient.go | 30 + examples/basic/simpleBotWithDebug.go | 35 + examples/basic/simpleHandleGetUpdates.go | 31 + examples/basic/simpleHandleHttpWebhook.go | 32 + examples/basic/simpleHandleHttpsWebhook.go | 32 + examples/methods/addStickerToSet.go | 34 + examples/methods/answerCallbackQuery.go | 22 + examples/methods/answerInlineQuery.go | 44 + examples/methods/answerPreCheckoutQuery.go | 24 + examples/methods/answerShippingQuery.go | 24 + examples/methods/answerWebAppQuery.go | 28 + examples/methods/approveChatJoinRequest.go | 23 + examples/methods/banChatMember.go | 23 + examples/methods/banChatSenderChat.go | 23 + examples/methods/closeForumTopic.go | 23 + examples/methods/closeGeneralForumTopic.go | 22 + examples/methods/copyMessage.go | 24 + examples/methods/copyMessages.go | 24 + examples/methods/createChatInviteLink.go | 22 + examples/methods/createForumTopic.go | 23 + examples/methods/createInvoiceLink.go | 29 + examples/methods/createNewStickerSet.go | 35 + examples/methods/declineChatJoinRequest.go | 23 + examples/methods/deleteChatPhoto.go | 22 + examples/methods/deleteChatStickerSet.go | 22 + examples/methods/deleteForumTopic.go | 23 + examples/methods/deleteMessage.go | 23 + examples/methods/deleteMessages.go | 23 + examples/methods/deleteMyCommands.go | 21 + examples/methods/deleteMyCommandsWithScope.go | 21 + .../deleteMyCommandsWithScopeAndLanguage.go | 21 + examples/methods/deleteStickerFromSet.go | 22 + examples/methods/deleteStickerSet.go | 22 + examples/methods/editCaption.go | 24 + examples/methods/editChatInviteLink.go | 23 + examples/methods/editForumTopic.go | 23 + examples/methods/editGeneralForumTopic.go | 23 + examples/methods/editMessage.go | 24 + examples/methods/editMessageLiveLocation.go | 31 + examples/methods/editMessageMedia.go | 27 + examples/methods/editMessageReplyMarkup.go | 39 + examples/methods/exportChatInviteLink.go | 22 + examples/methods/forwardMessage.go | 24 + examples/methods/forwardMessages.go | 24 + examples/methods/getBusinessConnection.go | 22 + examples/methods/getChat.go | 22 + examples/methods/getChatAdministrators.go | 22 + examples/methods/getChatMember.go | 23 + examples/methods/getChatMemberCount.go | 22 + examples/methods/getChatMenuButton.go | 21 + examples/methods/getCustomEmojiStickers.go | 23 + examples/methods/getFile.go | 22 + examples/methods/getForumTopicIconStickers.go | 20 + examples/methods/getGameHighScores.go | 23 + examples/methods/getMyCommandsWithScope.go | 21 + .../getMyCommandsWithScopeAndLanguage.go | 21 + .../getMyDefaultAdministratorRights.go | 21 + examples/methods/getMyDescription.go | 21 + examples/methods/getMyShortDescription.go | 21 + examples/methods/getStarTransactions.go | 21 + examples/methods/getStickerSet.go | 22 + examples/methods/getUserChatBoosts.go | 23 + examples/methods/getUserProfilePhotos.go | 22 + examples/methods/hideGeneralForumTopic.go | 22 + examples/methods/leaveChat.go | 22 + examples/methods/pinChatMessage.go | 23 + examples/methods/promoteChatMember.go | 26 + examples/methods/refundStarPayment.go | 23 + examples/methods/reopenForumTopic.go | 23 + examples/methods/reopenGeneralForumTopic.go | 22 + examples/methods/replaceStickerInSet.go | 35 + examples/methods/restrictChatMember.go | 29 + examples/methods/revokeChatInviteLink.go | 23 + examples/methods/sendAnimation.go | 23 + examples/methods/sendAudio.go | 23 + examples/methods/sendChatAction.go | 23 + examples/methods/sendContact.go | 24 + examples/methods/sendDice.go | 23 + examples/methods/sendDocument.go | 23 + examples/methods/sendGame.go | 23 + examples/methods/sendInvoice.go | 30 + examples/methods/sendLocation.go | 24 + examples/methods/sendMediaGroup.go | 34 + examples/methods/sendMessage.go | 24 + examples/methods/sendMessageEscapeText.go | 24 + examples/methods/sendMessageRemoveKeyboard.go | 27 + .../methods/sendMessageWithInlineKeyboard.go | 34 + examples/methods/sendMessageWithKeyboard.go | 39 + examples/methods/sendPaidMedia.go | 35 + examples/methods/sendPhoto.go | 23 + examples/methods/sendPoll.go | 34 + examples/methods/sendSticker.go | 23 + examples/methods/sendVenue.go | 26 + examples/methods/sendVideo.go | 23 + examples/methods/sendVideoNote.go | 23 + examples/methods/sendVoice.go | 23 + .../setChatAdministratorCustomTitle.go | 24 + examples/methods/setChatDescription.go | 23 + examples/methods/setChatMenuButton.go | 22 + examples/methods/setChatPermissions.go | 28 + examples/methods/setChatPhoto.go | 23 + examples/methods/setChatStickerSet.go | 23 + examples/methods/setChatTitle.go | 23 + .../setCustomEmojiStickerSetThumbnail.go | 22 + examples/methods/setGameScore.go | 24 + examples/methods/setMessageReaction.go | 36 + examples/methods/setMyCommands.go | 25 + examples/methods/setMyCommandsWithScope.go | 25 + .../setMyCommandsWithScopeAndLanguage.go | 25 + .../setMyDefaultAdministratorRights.go | 21 + examples/methods/setMyDescription.go | 22 + examples/methods/setMyShortDescription.go | 22 + examples/methods/setPassportDataErrors.go | 32 + examples/methods/setStickerEmojiList.go | 23 + examples/methods/setStickerKeywords.go | 23 + examples/methods/setStickerMaskPosition.go | 22 + examples/methods/setStickerPositionInSet.go | 23 + examples/methods/setStickerSetThumbnail.go | 24 + examples/methods/setStickerSetTitle.go | 23 + examples/methods/stopMessageLiveLocation.go | 28 + examples/methods/stopPoll.go | 23 + examples/methods/unHideGeneralForumTopic.go | 22 + examples/methods/unbanChatMember.go | 23 + examples/methods/unbanChatSenderChat.go | 23 + examples/methods/unpinAllChatMessages.go | 22 + .../methods/unpinAllForumTopicMessages.go | 23 + examples/methods/unpinChatMessage.go | 23 + examples/methods/uploadStickerFile.go | 24 + examples/webhook/info.go | 28 + examples/webhook/set.go | 42 + examples/webhook/unset.go | 31 + go.mod | 3 + telegram/helpers.go | 312 ++ telegram/methods.go | 2848 +++++++++++ telegram/telegram.go | 121 + telegram/utils.go | 1364 ++++++ types/Bot.go | 19 + types/helpers.go | 363 ++ types/methods.go | 4308 +++++++++++++++++ types/types.go | 2262 +++++++++ types/utils.go | 74 + 147 files changed, 15480 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 SECURITY.md create mode 100644 client/Client.go create mode 100644 config/config.go create mode 100644 examples/basic/simpleBot.go create mode 100644 examples/basic/simpleBotWithClient.go create mode 100644 examples/basic/simpleBotWithDebug.go create mode 100644 examples/basic/simpleHandleGetUpdates.go create mode 100644 examples/basic/simpleHandleHttpWebhook.go create mode 100644 examples/basic/simpleHandleHttpsWebhook.go create mode 100644 examples/methods/addStickerToSet.go create mode 100644 examples/methods/answerCallbackQuery.go create mode 100644 examples/methods/answerInlineQuery.go create mode 100644 examples/methods/answerPreCheckoutQuery.go create mode 100644 examples/methods/answerShippingQuery.go create mode 100644 examples/methods/answerWebAppQuery.go create mode 100644 examples/methods/approveChatJoinRequest.go create mode 100644 examples/methods/banChatMember.go create mode 100644 examples/methods/banChatSenderChat.go create mode 100644 examples/methods/closeForumTopic.go create mode 100644 examples/methods/closeGeneralForumTopic.go create mode 100644 examples/methods/copyMessage.go create mode 100644 examples/methods/copyMessages.go create mode 100644 examples/methods/createChatInviteLink.go create mode 100644 examples/methods/createForumTopic.go create mode 100644 examples/methods/createInvoiceLink.go create mode 100644 examples/methods/createNewStickerSet.go create mode 100644 examples/methods/declineChatJoinRequest.go create mode 100644 examples/methods/deleteChatPhoto.go create mode 100644 examples/methods/deleteChatStickerSet.go create mode 100644 examples/methods/deleteForumTopic.go create mode 100644 examples/methods/deleteMessage.go create mode 100644 examples/methods/deleteMessages.go create mode 100644 examples/methods/deleteMyCommands.go create mode 100644 examples/methods/deleteMyCommandsWithScope.go create mode 100644 examples/methods/deleteMyCommandsWithScopeAndLanguage.go create mode 100644 examples/methods/deleteStickerFromSet.go create mode 100644 examples/methods/deleteStickerSet.go create mode 100644 examples/methods/editCaption.go create mode 100644 examples/methods/editChatInviteLink.go create mode 100644 examples/methods/editForumTopic.go create mode 100644 examples/methods/editGeneralForumTopic.go create mode 100644 examples/methods/editMessage.go create mode 100644 examples/methods/editMessageLiveLocation.go create mode 100644 examples/methods/editMessageMedia.go create mode 100644 examples/methods/editMessageReplyMarkup.go create mode 100644 examples/methods/exportChatInviteLink.go create mode 100644 examples/methods/forwardMessage.go create mode 100644 examples/methods/forwardMessages.go create mode 100644 examples/methods/getBusinessConnection.go create mode 100644 examples/methods/getChat.go create mode 100644 examples/methods/getChatAdministrators.go create mode 100644 examples/methods/getChatMember.go create mode 100644 examples/methods/getChatMemberCount.go create mode 100644 examples/methods/getChatMenuButton.go create mode 100644 examples/methods/getCustomEmojiStickers.go create mode 100644 examples/methods/getFile.go create mode 100644 examples/methods/getForumTopicIconStickers.go create mode 100644 examples/methods/getGameHighScores.go create mode 100644 examples/methods/getMyCommandsWithScope.go create mode 100644 examples/methods/getMyCommandsWithScopeAndLanguage.go create mode 100644 examples/methods/getMyDefaultAdministratorRights.go create mode 100644 examples/methods/getMyDescription.go create mode 100644 examples/methods/getMyShortDescription.go create mode 100644 examples/methods/getStarTransactions.go create mode 100644 examples/methods/getStickerSet.go create mode 100644 examples/methods/getUserChatBoosts.go create mode 100644 examples/methods/getUserProfilePhotos.go create mode 100644 examples/methods/hideGeneralForumTopic.go create mode 100644 examples/methods/leaveChat.go create mode 100644 examples/methods/pinChatMessage.go create mode 100644 examples/methods/promoteChatMember.go create mode 100644 examples/methods/refundStarPayment.go create mode 100644 examples/methods/reopenForumTopic.go create mode 100644 examples/methods/reopenGeneralForumTopic.go create mode 100644 examples/methods/replaceStickerInSet.go create mode 100644 examples/methods/restrictChatMember.go create mode 100644 examples/methods/revokeChatInviteLink.go create mode 100644 examples/methods/sendAnimation.go create mode 100644 examples/methods/sendAudio.go create mode 100644 examples/methods/sendChatAction.go create mode 100644 examples/methods/sendContact.go create mode 100644 examples/methods/sendDice.go create mode 100644 examples/methods/sendDocument.go create mode 100644 examples/methods/sendGame.go create mode 100644 examples/methods/sendInvoice.go create mode 100644 examples/methods/sendLocation.go create mode 100644 examples/methods/sendMediaGroup.go create mode 100644 examples/methods/sendMessage.go create mode 100644 examples/methods/sendMessageEscapeText.go create mode 100644 examples/methods/sendMessageRemoveKeyboard.go create mode 100644 examples/methods/sendMessageWithInlineKeyboard.go create mode 100644 examples/methods/sendMessageWithKeyboard.go create mode 100644 examples/methods/sendPaidMedia.go create mode 100644 examples/methods/sendPhoto.go create mode 100644 examples/methods/sendPoll.go create mode 100644 examples/methods/sendSticker.go create mode 100644 examples/methods/sendVenue.go create mode 100644 examples/methods/sendVideo.go create mode 100644 examples/methods/sendVideoNote.go create mode 100644 examples/methods/sendVoice.go create mode 100644 examples/methods/setChatAdministratorCustomTitle.go create mode 100644 examples/methods/setChatDescription.go create mode 100644 examples/methods/setChatMenuButton.go create mode 100644 examples/methods/setChatPermissions.go create mode 100644 examples/methods/setChatPhoto.go create mode 100644 examples/methods/setChatStickerSet.go create mode 100644 examples/methods/setChatTitle.go create mode 100644 examples/methods/setCustomEmojiStickerSetThumbnail.go create mode 100644 examples/methods/setGameScore.go create mode 100644 examples/methods/setMessageReaction.go create mode 100644 examples/methods/setMyCommands.go create mode 100644 examples/methods/setMyCommandsWithScope.go create mode 100644 examples/methods/setMyCommandsWithScopeAndLanguage.go create mode 100644 examples/methods/setMyDefaultAdministratorRights.go create mode 100644 examples/methods/setMyDescription.go create mode 100644 examples/methods/setMyShortDescription.go create mode 100644 examples/methods/setPassportDataErrors.go create mode 100644 examples/methods/setStickerEmojiList.go create mode 100644 examples/methods/setStickerKeywords.go create mode 100644 examples/methods/setStickerMaskPosition.go create mode 100644 examples/methods/setStickerPositionInSet.go create mode 100644 examples/methods/setStickerSetThumbnail.go create mode 100644 examples/methods/setStickerSetTitle.go create mode 100644 examples/methods/stopMessageLiveLocation.go create mode 100644 examples/methods/stopPoll.go create mode 100644 examples/methods/unHideGeneralForumTopic.go create mode 100644 examples/methods/unbanChatMember.go create mode 100644 examples/methods/unbanChatSenderChat.go create mode 100644 examples/methods/unpinAllChatMessages.go create mode 100644 examples/methods/unpinAllForumTopicMessages.go create mode 100644 examples/methods/unpinChatMessage.go create mode 100644 examples/methods/uploadStickerFile.go create mode 100644 examples/webhook/info.go create mode 100644 examples/webhook/set.go create mode 100644 examples/webhook/unset.go create mode 100644 go.mod create mode 100644 telegram/helpers.go create mode 100644 telegram/methods.go create mode 100644 telegram/telegram.go create mode 100644 telegram/utils.go create mode 100644 types/Bot.go create mode 100644 types/helpers.go create mode 100644 types/methods.go create mode 100644 types/types.go create mode 100644 types/utils.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c40110 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.xml +*.iml +.idea \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c15808 --- /dev/null +++ b/README.md @@ -0,0 +1,260 @@ +# Telegram Bot API + +The Telegram Bot API provides an HTTP API for creating Telegram Bots. + +If you've got any questions about bots or would like to report an issue with your bot, kindly contact us at @BotSupport in Telegram. + +Please note that only global Bot API issues that affect all bots are suitable for this repository. + +To learn how to use it, please see our [examples](https://github.com/raminsa/telegram-bot-api/tree/main/examples). + +Bot API 7.7 recent changes [July 7, 2024](https://core.telegram.org/bots/api#july-7-2024). + +## Table of Contents +- [Installation](#installation) +- [Documentation](#documentation) +- [Example](#example) +- [Custom Client](#custom-client) +- [Debug](#debug) + + +## Installation +`go get github.com/raminsa/telegram-bot-api`. + + +## Documentation +See [Bots: An introduction for developers](https://core.telegram.org/bots) for a brief description of Telegram Bots and their features. + +See the [Telegram Bot API documentation](https://core.telegram.org/bots/api) for a description of the Bot API interface and a complete list of available classes, methods and updates. + +See the [Telegram Bot API server build instruction generator](https://tdlib.github.io/telegram-bot-api/build.html) for detailed instructions on how to build the Telegram Bot API server. + +Subscribe to [@BotNews](https://t.me/botnews) to be the first to know about the latest updates and join the discussion in [@BotTalk](https://t.me/bottalk). + + + +## Example + +use get update method (simple): +```go +package main + +import ( + "fmt" + "log" + + "github.com/raminsa/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getUpdates := tg.NewGetUpdates() + getUpdates.Offset = 1 + getUpdates.Timeout = 60 + getUpdates.Limit = 100 + updates := tg.GetUpdatesChan(getUpdates) + for update := range updates { + fmt.Println(update.UpdateID, getUpdates.Offset) + if update.UpdateID >= getUpdates.Offset { + getUpdates.Offset = update.UpdateID + 1 + } + if update.Message != nil { + fmt.Println(update.Message.Text) + } + } +} +``` + +use webhook method (http): +```go +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/raminsa/telegram-bot-api/telegram" +) + +func main() { + fmt.Println("start at port:", "BotPortNumber") + err := http.ListenAndServe("BotPortNumber", http.HandlerFunc(handleWebhook)) + if err != nil { + log.Fatal(err) + } +} + +func handleWebhook(w http.ResponseWriter, r *http.Request) { + update, err := telegram.HandleUpdate(r) + if err != nil { + err = telegram.HandleUpdateError(w, err) + if err != nil { + //handle err + } + return + } + + if update.Message != nil { + fmt.Println(update.Message.Text) + } +} +``` + +use webhook method (https): +```go +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/raminsa/telegram-bot-api/telegram" +) + +func main() { + fmt.Println("start at port:", "BotPortNumber") + err := http.ListenAndServeTLS("BotPortNumber", "BotCertFile", "BotKeyFile", http.HandlerFunc(handleWebhook)) + if err != nil { + log.Fatal(err) + } +} + +func handleWebhook(w http.ResponseWriter, r *http.Request) { + update, err := telegram.HandleUpdate(r) + if err != nil { + err := telegram.HandleUpdateError(w, err) + if err != nil { + //handle err + } + return + } + + if update.Message != nil { + fmt.Println(update.Message.Text) + } +} +``` + +to generate your cert file use this. See [self-signed](https://core.telegram.org/bots/self-signed) guide for details.: + + openssl req -newkey rsa:2048 -sha256 -nodes -keyout -x509 -days 36500 -out -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=" + + +use a channel to handle all requests (Avoid ReadTimeoutExpired error), http.ListenAndServe() supports concurrency: +```go +package main + +import ( + "fmt" + "net/http" + + "github.com/raminsa/telegram-bot-api/telegram" + "github.com/raminsa/telegram-bot-api/types" +) + +func main() { + fmt.Println("start at port:", "BotPortNumber") + updates := listenForWebhook(100) + go http.ListenAndServeTLS("BotPortNumber", "BotCertFile", "BotKeyFile", nil) + for update := range updates { + if update.Message != nil { + fmt.Println(update.Message.Text) + } + } +} + +func listenForWebhook(maxWebhookConnections int) types.UpdatesChannel { + ch := make(chan types.Update, maxWebhookConnections) + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if update, err := telegram.HandleUpdate(r); err != nil { + return + } else { + ch <- *update + } + }) + + return ch +} +``` + + +## Custom Client +use client with custom options: +```go +package main + +import ( + "fmt" + "log" + + "github.com/raminsa/telegram-bot-api/telegram" +) + +func main() { + client := telegram.Client() + client.BaseUrl = "baseUrl" + client.Proxy = "proxy" + client.ForceV4 = true + client.DisableSSLVerify = true + client.ForceAttemptHTTP2 = true + tg, err := telegram.NewWithCustomClient("BotToken", client) + if err != nil { + log.Fatal(err) + } + + me, err := tg.GetMe() + if err != nil { + log.Fatal(err) + } + + fmt.Println("botID:", me.ID, "botUsername:", me.UserName) +} +``` + + +## Debug + +use debug option and write to local file: +```go +package main + +import ( + "fmt" + "log" + + "github.com/raminsa/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.NewWithBaseUrl("BotToken", "baseUrl") + if err != nil { + log.Fatal(err) + } + + //active debug mode + tg.Bot.Debug = true + + me, err := tg.GetMe() + if err != nil { + log.Fatal(err) + } + + fmt.Println("botID:", me.ID, "botUsername:", me.UserName) + + //access debug log + //method 1: write to console + fmt.Println(tg.GetLoggerFile()) + + //method 2: write to file + err = tg.WriteLoggerFile("fileName") + if err != nil { + log.Fatal(err) + } +} +``` diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..d5b3b33 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +|---------|--------------------| +| 5.1.x | :white_check_mark: | +| 5.0.x | :x: | +| 4.0.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. diff --git a/client/Client.go b/client/Client.go new file mode 100644 index 0000000..081aa76 --- /dev/null +++ b/client/Client.go @@ -0,0 +1,69 @@ +package client + +import ( + "context" + "crypto/tls" + "net" + "net/http" + "net/url" +) + +type Config struct { + HttpC *http.Client + Proxy string + ForceV4 bool + DisableSSLVerify bool + ForceAttemptHTTP2 bool + BaseUrl string +} + +// Setup setup a new client to use telegram api +func (c *Config) Setup() error { + var proxy func(*http.Request) (*url.URL, error) + var myDC func(ctx context.Context, network, addr string) (net.Conn, error) + var TLSClientConfig *tls.Config + var forceAttemptHTTP2 bool + + if c.Proxy != "" { + proxyUrl, err := url.Parse(c.Proxy) + if err != nil { + return err + } + if proxyUrl != nil { + proxy = http.ProxyURL(proxyUrl) + } else { + proxy = nil + } + } else { + proxy = nil + } + + if c.ForceV4 { + myDC = func(ctx context.Context, network string, addr string) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "tcp4", addr) + } + } else { + myDC = nil + } + + if c.DisableSSLVerify { + TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } else { + TLSClientConfig = &tls.Config{InsecureSkipVerify: false} + } + + if c.ForceAttemptHTTP2 { + forceAttemptHTTP2 = true + } + + c.HttpC = &http.Client{ + Transport: &http.Transport{ + Proxy: proxy, + ForceAttemptHTTP2: forceAttemptHTTP2, + DialContext: myDC, + TLSClientConfig: TLSClientConfig, + }, + } + + return nil +} diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..601476d --- /dev/null +++ b/config/config.go @@ -0,0 +1,158 @@ +package config + +// Telegram constants +const ( + DefaultBaseUrl = "https://api.telegram.org" + APIEndpoint = "/bot%s/%s" + APIFileEndpoint = DefaultBaseUrl + "/file/bot%s/%s" +) + +// Constant values for Endpoints +const ( + EndpointGetUpdates = "getUpdates" + EndpointSetWebhook = "setWebhook" + EndpointDeleteWebhook = "deleteWebhook" + EndpointGetWebhook = "getWebhookInfo" + EndpointGetMe = "getMe" + EndpointLogOut = "logOut" + EndpointClose = "close" + EndpointSendMessage = "sendMessage" + EndpointForwardMessage = "forwardMessage" + EndpointForwardMessages = "forwardMessages" + EndpointCopyMessage = "copyMessage" + EndpointCopyMessages = "copyMessages" + EndpointSendPhoto = "sendPhoto" + EndpointSendAudio = "sendAudio" + EndpointSendDocument = "sendDocument" + EndpointSendVideo = "sendVideo" + EndpointSendAnimation = "sendAnimation" + EndpointSendVoice = "sendVoice" + EndpointSendVideoNote = "sendVideoNote" + EndpointSendPaidMedia = "sendPaidMedia" + EndpointSendMediaGroup = "sendMediaGroup" + EndpointSendLocation = "sendLocation" + EndpointEditMessageLiveLocation = "editMessageLiveLocation" + EndpointStopMessageLiveLocation = "stopMessageLiveLocation" + EndpointSendVenue = "sendVenue" + EndpointSendContact = "sendContact" + EndpointSendPoll = "sendPoll" + EndpointSendDice = "sendDice" + EndpointSendChatAction = "sendChatAction" + EndpointSetMessageReaction = "setMessageReaction" + EndpointGetUserProfilePhotos = "getUserProfilePhotos" + EndpointGetFile = "getFile" + EndpointBanChatMember = "banChatMember" + EndpointUnbanChatMember = "unbanChatMember" + EndpointRestrictChatMember = "restrictChatMember" + EndpointPromoteChatMember = "promoteChatMember" + EndpointSetChatAdministratorCustomTitle = "setChatAdministratorCustomTitle" + EndpointBanChatSenderChat = "banChatSenderChat" + EndpointUnbanChatSenderChat = "unbanChatSenderChat" + EndpointSetChatPermissions = "setChatPermissions" + EndpointExportChatInviteLink = "exportChatInviteLink" + EndpointCreateChatInviteLink = "createChatInviteLink" + EndpointEditChatInviteLink = "editChatInviteLink" + EndpointRevokeChatInviteLink = "revokeChatInviteLink" + EndpointApproveChatJoinRequest = "approveChatJoinRequest" + EndpointDeclineChatJoinRequest = "declineChatJoinRequest" + EndpointSetChatPhoto = "setChatPhoto" + EndpointDeleteChatPhoto = "deleteChatPhoto" + EndpointSetChatTitle = "setChatTitle" + EndpointSetChatDescription = "setChatDescription" + EndpointPinChatMessage = "pinChatMessage" + EndpointUnpinChatMessage = "unpinChatMessage" + EndpointUnpinAllChatMessages = "unpinAllChatMessages" + EndpointLeaveChat = "leaveChat" + EndpointGetChat = "getChat" + EndpointGetChatAdministrators = "getChatAdministrators" + EndpointGetChatMemberCount = "getChatMemberCount" + EndpointGetChatMember = "getChatMember" + EndpointSetChatStickerSet = "setChatStickerSet" + EndpointDeleteChatStickerSet = "deleteChatStickerSet" + EndpointCreateForumTopic = "createForumTopic" + EndpointEditForumTopic = "editForumTopic" + EndpointCloseForumTopic = "closeForumTopic" + EndpointReopenForumTopic = "reopenForumTopic" + EndpointDeleteForumTopic = "deleteForumTopic" + EndpointUnpinAllForumTopicMessages = "unpinAllForumTopicMessages" + EndpointEditGeneralForumTopic = "editGeneralForumTopic" + EndpointCloseGeneralForumTopic = "closeGeneralForumTopic" + EndpointReopenGeneralForumTopic = "reopenGeneralForumTopic" + EndpointHideGeneralForumTopic = "hideGeneralForumTopic" + EndpointUnHideGeneralForumTopic = "unhideGeneralForumTopic" + EndpointUnpinAllGeneralForumTopicMessages = "unpinAllGeneralForumTopicMessages" + EndpointGetForumTopicIconStickers = "getForumTopicIconStickers" + EndpointAnswerCallbackQuery = "answerCallbackQuery" + EndpointGetUserChatBoosts = "getUserChatBoosts" + EndpointGetBusinessConnection = "getBusinessConnection" + EndpointSetMyCommands = "setMyCommands" + EndpointDeleteMyCommands = "deleteMyCommands" + EndpointGetMyCommands = "getMyCommands" + EndpointSetMyName = "setMyName" + EndpointGetMyName = "getMyName" + EndpointSetMyDescription = "setMyDescription" + EndpointGetMyDescription = "getMyDescription" + EndpointSetMyShortDescription = "setMyShortDescription" + EndpointGetMyShortDescription = "getMyShortDescription" + EndpointSetChatMenuButton = "setChatMenuButton" + EndpointGetChatMenuButton = "getChatMenuButton" + EndpointSetMyDefaultAdministratorRights = "setMyDefaultAdministratorRights" + EndpointGetMyDefaultAdministratorRights = "getMyDefaultAdministratorRights" + EndpointEditMessageText = "editMessageText" + EndpointEditMessageCaption = "editMessageCaption" + EndpointEditMessageMedia = "editMessageMedia" + EndpointEditMessageReplyMarkup = "editMessageReplyMarkup" + EndpointStopPoll = "stopPoll" + EndpointDeleteMessage = "deleteMessage" + EndpointDeleteMessages = "deleteMessages" + EndpointSendSticker = "sendSticker" + EndpointGetStickerSet = "getStickerSet" + EndpointGetCustomEmojiStickers = "getCustomEmojiStickers" + EndpointUploadStickerFile = "uploadStickerFile" + EndpointCreateNewStickerSet = "createNewStickerSet" + EndpointAddStickerToSet = "addStickerToSet" + EndpointSetStickerPositionInSet = "setStickerPositionInSet" + EndpointDeleteStickerFromSet = "deleteStickerFromSet" + EndpointReplaceStickerInSet = "replaceStickerInSet" + EndpointSetStickerEmojiList = "setStickerEmojiList" + EndpointSetStickerKeywords = "setStickerKeywords" + EndpointSetStickerMaskPosition = "setStickerMaskPosition" + EndpointSetStickerSetTitle = "setStickerSetTitle" + EndpointSetStickerSetThumbnail = "setStickerSetThumbnail" + EndpointSetCustomEmojiStickerSetThumbnail = "setCustomEmojiStickerSetThumbnail" + EndpointDeleteStickerSet = "deleteStickerSet" + EndpointAnswerInlineQuery = "answerInlineQuery" + EndpointAnswerWebAppQuery = "answerWebAppQuery" + EndpointSendInvoice = "sendInvoice" + EndpointCreateInvoiceLink = "createInvoiceLink" + EndpointAnswerShippingQuery = "answerShippingQuery" + EndpointAnswerPreCheckoutQuery = "answerPreCheckoutQuery" + EndpointGetStarTransactions = "getStarTransactions" + EndpointRefundStarPayment = "refundStarPayment" + EndpointSetPassportDataErrors = "setPassportDataErrors" + EndpointSendGame = "sendGame" + EndpointSetGameScore = "setGameScore" + EndpointGetGameHighScores = "getGameHighScores" +) + +// Constant values for ChatActions +const ( + ChatTyping = "typing" + ChatUploadPhoto = "upload_photo" + ChatRecordVideo = "record_video" + ChatUploadVideo = "upload_video" + ChatRecordVoice = "record_voice" + ChatUploadVoice = "upload_voice" + ChatUploadDocument = "upload_document" + ChatChooseSticker = "choose_sticker" + ChatFindLocation = "find_location" + ChatRecordVideoNote = "record_video_note" + ChatUploadVideoNote = "upload_video_note" +) + +// Constant values for ParseMode in MessageConfig +const ( + ModeMarkdown = "Markdown" + ModeMarkdownV2 = "MarkdownV2" + ModeHTML = "HTML" +) diff --git a/examples/basic/simpleBot.go b/examples/basic/simpleBot.go new file mode 100644 index 0000000..a8dbbc4 --- /dev/null +++ b/examples/basic/simpleBot.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + me, err := tg.GetMe() + if err != nil { + log.Fatal(err) + } + + fmt.Println("botID:", me.ID, "botUsername:", me.UserName) +} diff --git a/examples/basic/simpleBotWithClient.go b/examples/basic/simpleBotWithClient.go new file mode 100644 index 0000000..80bb832 --- /dev/null +++ b/examples/basic/simpleBotWithClient.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + client := telegram.Client() + + client.BaseUrl = "baseUrl" + client.Proxy = "proxy" + client.ForceV4 = true + client.DisableSSLVerify = true + client.ForceAttemptHTTP2 = true + + tg, err := telegram.NewWithCustomClient("BotToken", client) + if err != nil { + log.Fatal(err) + } + + me, err := tg.GetMe() + if err != nil { + log.Fatal(err) + } + + fmt.Println("botID:", me.ID, "botUsername:", me.UserName) +} diff --git a/examples/basic/simpleBotWithDebug.go b/examples/basic/simpleBotWithDebug.go new file mode 100644 index 0000000..4b76c65 --- /dev/null +++ b/examples/basic/simpleBotWithDebug.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.NewWithBaseUrl("BotToken", "baseUrl") + if err != nil { + log.Fatal(err) + } + + //active debug mode + tg.Bot.Debug = true + + me, err := tg.GetMe() + if err != nil { + log.Fatal(err) + } + + fmt.Println("botID:", me.ID, "botUsername:", me.UserName) + + //access debug log + //method 1: write to console + fmt.Println(tg.GetLoggerFile()) + + //method 2: write to file + err = tg.WriteLoggerFile("fileName") + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/basic/simpleHandleGetUpdates.go b/examples/basic/simpleHandleGetUpdates.go new file mode 100644 index 0000000..7349c04 --- /dev/null +++ b/examples/basic/simpleHandleGetUpdates.go @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getUpdates := tg.NewGetUpdates() + getUpdates.Offset = 1 + getUpdates.Timeout = 60 + getUpdates.Limit = 100 + + updates := tg.GetUpdatesChan(getUpdates) + for update := range updates { + fmt.Println(update.UpdateID, getUpdates.Offset) + if update.UpdateID >= getUpdates.Offset { + getUpdates.Offset = update.UpdateID + 1 + } + if update.Message != nil { + fmt.Println(update.Message.Text) + } + } +} diff --git a/examples/basic/simpleHandleHttpWebhook.go b/examples/basic/simpleHandleHttpWebhook.go new file mode 100644 index 0000000..65d2bf9 --- /dev/null +++ b/examples/basic/simpleHandleHttpWebhook.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + fmt.Println("start at port:", "BotPortNumber") + + err := http.ListenAndServe("BotPortNumber", http.HandlerFunc(handleWebhook)) + if err != nil { + log.Fatal(err) + } +} + +func handleWebhook(w http.ResponseWriter, r *http.Request) { + update, err := telegram.HandleUpdate(r) + if err != nil { + err = telegram.HandleUpdateError(w, err) + if err != nil { + log.Fatal(err) + } + return + } + if update.Message != nil { + fmt.Println(update.Message.Text) + } +} diff --git a/examples/basic/simpleHandleHttpsWebhook.go b/examples/basic/simpleHandleHttpsWebhook.go new file mode 100644 index 0000000..daff9c1 --- /dev/null +++ b/examples/basic/simpleHandleHttpsWebhook.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + fmt.Println("start at port:", "BotPortNumber") + + err := http.ListenAndServeTLS("BotPortNumber", "BotCertFile", "BotKeyFile", http.HandlerFunc(handleWebhookTLS)) + if err != nil { + log.Fatal(err) + } +} + +func handleWebhookTLS(w http.ResponseWriter, r *http.Request) { + update, err := telegram.HandleUpdate(r) + if err != nil { + err = telegram.HandleUpdateError(w, err) + if err != nil { + log.Fatal(err) + } + return + } + if update.Message != nil { + fmt.Println(update.Message.Text) + } +} diff --git a/examples/methods/addStickerToSet.go b/examples/methods/addStickerToSet.go new file mode 100644 index 0000000..cc43615 --- /dev/null +++ b/examples/methods/addStickerToSet.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewAddStickerToSet() + message.UserID = 1234 + message.Name = "myName_by_" + + stickers := tg.NewInputSticker() + stickers.EmojiList = []string{"🏀"} + + maskPosition := tg.NewMaskPosition() + + stickers.MaskPosition = maskPosition + stickers.Keywords = []string{"ball"} + stickers.Sticker = tg.FileURL("url") + + message.Sticker = stickers + + _, err = tg.AddStickerToSet(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/answerCallbackQuery.go b/examples/methods/answerCallbackQuery.go new file mode 100644 index 0000000..31794ae --- /dev/null +++ b/examples/methods/answerCallbackQuery.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewAnswerCallbackQuery() + msg.CallbackQueryID = "id" + + _, err = tg.AnswerCallbackQuery(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/answerInlineQuery.go b/examples/methods/answerInlineQuery.go new file mode 100644 index 0000000..7dc4ba1 --- /dev/null +++ b/examples/methods/answerInlineQuery.go @@ -0,0 +1,44 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewAnswerInlineQuery() + message.InlineQueryID = "id" + + var ResultArticle []any + + article := tg.NewInlineQueryResultArticle("1234", "title") + article.Description = "description" + + inputTextMessageContent := tg.NewInputTextMessageContent() + inputTextMessageContent.Text = "text" + + article.InputMessageContent = inputTextMessageContent + ResultArticle = append(ResultArticle, article) + + article = tg.NewInlineQueryResultArticle("1235", "title2") + article.Description = "description" + + inputTextMessageContent = tg.NewInputTextMessageContent() + inputTextMessageContent.Text = "text2" + + article.InputMessageContent = inputTextMessageContent + ResultArticle = append(ResultArticle, article) + + message.Results = ResultArticle + + _, err = tg.AnswerInlineQuery(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/answerPreCheckoutQuery.go b/examples/methods/answerPreCheckoutQuery.go new file mode 100644 index 0000000..47f30bf --- /dev/null +++ b/examples/methods/answerPreCheckoutQuery.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewAnswerPreCheckoutQuery() + message.PreCheckoutQueryID = "id" + message.OK = false + message.ErrorMessage = "err" + + _, err = tg.AnswerPreCheckoutQuery(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/answerShippingQuery.go b/examples/methods/answerShippingQuery.go new file mode 100644 index 0000000..b1d3411 --- /dev/null +++ b/examples/methods/answerShippingQuery.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewAnswerShippingQuery() + message.ShippingQueryID = "id" + message.OK = false + message.ErrorMessage = "err" + + _, err = tg.AnswerShippingQuery(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/answerWebAppQuery.go b/examples/methods/answerWebAppQuery.go new file mode 100644 index 0000000..de4d628 --- /dev/null +++ b/examples/methods/answerWebAppQuery.go @@ -0,0 +1,28 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewAnswerWebAppQuery() + message.WebAppQueryID = "id" + + article := tg.NewInlineQueryResultArticle("1234", "title") + article.Description = "description" + article.InputMessageContent = tg.NewInputTextMessageContent() + + message.Result = article + + _, err = tg.AnswerWebAppQuery(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/approveChatJoinRequest.go b/examples/methods/approveChatJoinRequest.go new file mode 100644 index 0000000..76a500b --- /dev/null +++ b/examples/methods/approveChatJoinRequest.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewApproveChatJoinRequest() + msg.Username = "username" + msg.UserID = 1234 + + _, err = tg.ApproveChatJoinRequest(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/banChatMember.go b/examples/methods/banChatMember.go new file mode 100644 index 0000000..394d0bd --- /dev/null +++ b/examples/methods/banChatMember.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewBanChatMember() + msg.Username = "username" + msg.UserID = 1234 + + _, err = tg.BanChatMember(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/banChatSenderChat.go b/examples/methods/banChatSenderChat.go new file mode 100644 index 0000000..70bf3c6 --- /dev/null +++ b/examples/methods/banChatSenderChat.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewBanChatSenderChat() + msg.Username = "username" + msg.SenderChatID = 1234 + + _, err = tg.BanChatSenderChat(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/closeForumTopic.go b/examples/methods/closeForumTopic.go new file mode 100644 index 0000000..b8460e6 --- /dev/null +++ b/examples/methods/closeForumTopic.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCloseForumTopic() + msg.Username = "username" + msg.MessageThreadID = 1234 + + _, err = tg.CloseForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/closeGeneralForumTopic.go b/examples/methods/closeGeneralForumTopic.go new file mode 100644 index 0000000..842e4a1 --- /dev/null +++ b/examples/methods/closeGeneralForumTopic.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCloseGeneralForumTopic() + msg.Username = "username" + + _, err = tg.CloseGeneralForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/copyMessage.go b/examples/methods/copyMessage.go new file mode 100644 index 0000000..4ad9eef --- /dev/null +++ b/examples/methods/copyMessage.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCopyMessage() + msg.ChatID = 1234 + msg.FromChatID = 1234 + msg.MessageID = 1234 + + _, err = tg.CopyMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/copyMessages.go b/examples/methods/copyMessages.go new file mode 100644 index 0000000..4d8864e --- /dev/null +++ b/examples/methods/copyMessages.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCopyMessages() + msg.ChatID = 1234 + msg.FromChatID = 1234 + msg.MessageIds = []int{1234, 1235} + + _, err = tg.CopyMessages(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/createChatInviteLink.go b/examples/methods/createChatInviteLink.go new file mode 100644 index 0000000..7c14758 --- /dev/null +++ b/examples/methods/createChatInviteLink.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCreateChatInviteLink() + msg.Username = "username" + + _, err = tg.CreateChatInviteLink(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/createForumTopic.go b/examples/methods/createForumTopic.go new file mode 100644 index 0000000..3c44c35 --- /dev/null +++ b/examples/methods/createForumTopic.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCreateForumTopic() + msg.Username = "username" + msg.Name = "name" + + _, err = tg.CreateForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/createInvoiceLink.go b/examples/methods/createInvoiceLink.go new file mode 100644 index 0000000..25c0ed3 --- /dev/null +++ b/examples/methods/createInvoiceLink.go @@ -0,0 +1,29 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewCreateInvoiceLink() + message.Title = "title" + message.Description = "description" + message.Payload = "payload" + message.Currency = "currency" + message.Prices = tg.NewLabeledPrices( + tg.NewLabeledPrice("title1", 1234), + tg.NewLabeledPrice("title2", 1234), + ) + + _, err = tg.CreateInvoiceLink(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/createNewStickerSet.go b/examples/methods/createNewStickerSet.go new file mode 100644 index 0000000..6297538 --- /dev/null +++ b/examples/methods/createNewStickerSet.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewCreateNewStickerSet() + msg.UserID = 1234 + msg.Name = "name" + msg.Title = "title" + + stickers1 := tg.NewInputSticker() + stickers1.EmojiList = []string{"🏀"} + maskPosition := tg.NewMaskPosition() + stickers1.MaskPosition = maskPosition + stickers1.Keywords = []string{"ball"} + stickers1.Sticker = tg.FileURL("url") + + stickers2 := tg.NewInputSticker() + + msg.Stickers = []any{stickers1, stickers2} + + _, err = tg.CreateNewStickerSet(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/declineChatJoinRequest.go b/examples/methods/declineChatJoinRequest.go new file mode 100644 index 0000000..22e96df --- /dev/null +++ b/examples/methods/declineChatJoinRequest.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewDeclineChatJoinRequest() + msg.Username = "username" + msg.UserID = 1234 + + _, err = tg.DeclineChatJoinRequest(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteChatPhoto.go b/examples/methods/deleteChatPhoto.go new file mode 100644 index 0000000..ce28cd2 --- /dev/null +++ b/examples/methods/deleteChatPhoto.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewDeleteChatPhoto() + msg.Username = "username" + + _, err = tg.DeleteChatPhoto(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteChatStickerSet.go b/examples/methods/deleteChatStickerSet.go new file mode 100644 index 0000000..2eeb487 --- /dev/null +++ b/examples/methods/deleteChatStickerSet.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewDeleteChatStickerSet() + msg.Username = "username" + + _, err = tg.DeleteChatStickerSet(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteForumTopic.go b/examples/methods/deleteForumTopic.go new file mode 100644 index 0000000..cc20d4f --- /dev/null +++ b/examples/methods/deleteForumTopic.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewDeleteForumTopic() + msg.Username = "username" + msg.MessageThreadID = 1234 + + _, err = tg.DeleteForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteMessage.go b/examples/methods/deleteMessage.go new file mode 100644 index 0000000..3ab676a --- /dev/null +++ b/examples/methods/deleteMessage.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewDeleteMessage() + message.ChatID = 1234 + message.MessageID = 1234 + + _, err = tg.DeleteMessage(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteMessages.go b/examples/methods/deleteMessages.go new file mode 100644 index 0000000..e6b33cd --- /dev/null +++ b/examples/methods/deleteMessages.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewDeleteMessages() + message.ChatID = 1234 + message.MessageIds = []int{1234, 1235} + + _, err = tg.DeleteMessages(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteMyCommands.go b/examples/methods/deleteMyCommands.go new file mode 100644 index 0000000..0b2d540 --- /dev/null +++ b/examples/methods/deleteMyCommands.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + deleteCommands := tg.NewDeleteMyCommands() + + _, err = tg.DeleteMyCommands(deleteCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteMyCommandsWithScope.go b/examples/methods/deleteMyCommandsWithScope.go new file mode 100644 index 0000000..9b8daa4 --- /dev/null +++ b/examples/methods/deleteMyCommandsWithScope.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + deleteCommands := tg.NewDeleteMyCommandsWithScope(tg.NewBotCommandScopeDefault()) + + _, err = tg.DeleteMyCommands(deleteCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteMyCommandsWithScopeAndLanguage.go b/examples/methods/deleteMyCommandsWithScopeAndLanguage.go new file mode 100644 index 0000000..e643646 --- /dev/null +++ b/examples/methods/deleteMyCommandsWithScopeAndLanguage.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + deleteCommands := tg.NewDeleteMyCommandsWithScopeAndLanguage(tg.NewBotCommandScopeDefault(), "en") + + _, err = tg.DeleteMyCommands(deleteCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteStickerFromSet.go b/examples/methods/deleteStickerFromSet.go new file mode 100644 index 0000000..f104719 --- /dev/null +++ b/examples/methods/deleteStickerFromSet.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewDeleteStickerFromSet() + message.Sticker = "sticker" + + _, err = tg.DeleteStickerFromSet(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/deleteStickerSet.go b/examples/methods/deleteStickerSet.go new file mode 100644 index 0000000..ce0579a --- /dev/null +++ b/examples/methods/deleteStickerSet.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewDeleteStickerSet() + msg.Name = "name" + + _, err = tg.DeleteStickerSet(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editCaption.go b/examples/methods/editCaption.go new file mode 100644 index 0000000..0346faf --- /dev/null +++ b/examples/methods/editCaption.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewEditMessageCaption() + message.ChatID = 1234 + message.MessageID = 1742 + message.Caption = "text" + + _, err = tg.EditMessageCaption(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editChatInviteLink.go b/examples/methods/editChatInviteLink.go new file mode 100644 index 0000000..c616aae --- /dev/null +++ b/examples/methods/editChatInviteLink.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewEditChatInviteLink() + msg.Username = "username" + msg.InviteLink = "url" + + _, err = tg.EditChatInviteLink(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editForumTopic.go b/examples/methods/editForumTopic.go new file mode 100644 index 0000000..c4f4439 --- /dev/null +++ b/examples/methods/editForumTopic.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewEditForumTopic() + msg.Username = "username" + msg.MessageThreadID = 1234 + + _, err = tg.EditForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editGeneralForumTopic.go b/examples/methods/editGeneralForumTopic.go new file mode 100644 index 0000000..eb28306 --- /dev/null +++ b/examples/methods/editGeneralForumTopic.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewEditGeneralForumTopic() + msg.Username = "username" + msg.Name = "name" + + _, err = tg.EditGeneralForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editMessage.go b/examples/methods/editMessage.go new file mode 100644 index 0000000..a56ffbc --- /dev/null +++ b/examples/methods/editMessage.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewEditMessageText() + message.ChatID = 1234 + message.MessageID = 1234 + message.Text = "text" + + _, err = tg.EditMessageText(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editMessageLiveLocation.go b/examples/methods/editMessageLiveLocation.go new file mode 100644 index 0000000..b5daa06 --- /dev/null +++ b/examples/methods/editMessageLiveLocation.go @@ -0,0 +1,31 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewEditMessageLiveLocation() + + // use InlineMessageID + msg.InlineMessageID = "inline id" + + // or use ChatID & MessageID + msg.ChatID = 1234 + msg.MessageID = 1234 + + msg.Latitude = 1234 + msg.Longitude = 1234 + + _, err = tg.EditMessageLiveLocation(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editMessageMedia.go b/examples/methods/editMessageMedia.go new file mode 100644 index 0000000..54ae4dc --- /dev/null +++ b/examples/methods/editMessageMedia.go @@ -0,0 +1,27 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewEditMessageMedia() + message.ChatID = 1234 + message.MessageID = 1234 + + media := tg.NewInputMediaPhoto() + media.Media = tg.FileURL("url") + message.Media = media + + _, err = tg.EditMessageMedia(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/editMessageReplyMarkup.go b/examples/methods/editMessageReplyMarkup.go new file mode 100644 index 0000000..e30dce9 --- /dev/null +++ b/examples/methods/editMessageReplyMarkup.go @@ -0,0 +1,39 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewEditMessageReplyMarkup() + message.ChatID = 1234 + message.MessageID = 1234 + + keyboard := tg.NewReplyKeyboardMarkup( + tg.NewKeyboardButtonRow( + tg.NewKeyboardButton("btn1"), + ), + tg.NewKeyboardButtonRow( + tg.NewKeyboardButton("btn2"), + tg.NewKeyboardButton("btn3"), + ), + ) + keyboard.ResizeKeyboard = true + keyboard.OneTimeKeyboard = true + keyboard.Selective = true + keyboard.InputFieldPlaceholder = "some text" + + message.ReplyMarkup = keyboard + + _, err = tg.EditMessageReplyMarkup(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/exportChatInviteLink.go b/examples/methods/exportChatInviteLink.go new file mode 100644 index 0000000..0e63dca --- /dev/null +++ b/examples/methods/exportChatInviteLink.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewExportChatInviteLink() + msg.Username = "username" + + _, err = tg.ExportChatInviteLink(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/forwardMessage.go b/examples/methods/forwardMessage.go new file mode 100644 index 0000000..2d8bdd9 --- /dev/null +++ b/examples/methods/forwardMessage.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewForwardMessage() + msg.ChatID = 1234 + msg.FromChatID = 1234 + msg.MessageID = 1234 + + _, err = tg.ForwardMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/forwardMessages.go b/examples/methods/forwardMessages.go new file mode 100644 index 0000000..dc9efbc --- /dev/null +++ b/examples/methods/forwardMessages.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewForwardMessages() + msg.ChatID = 1234 + msg.FromChatID = 1234 + msg.MessageIds = []int{1234, 1235} + + _, err = tg.ForwardMessages(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getBusinessConnection.go b/examples/methods/getBusinessConnection.go new file mode 100644 index 0000000..4f7bd46 --- /dev/null +++ b/examples/methods/getBusinessConnection.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetBusinessConnection() + msg.BusinessConnectionId = "1234" + + _, err = tg.GetBusinessConnection(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getChat.go b/examples/methods/getChat.go new file mode 100644 index 0000000..1309d1e --- /dev/null +++ b/examples/methods/getChat.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetChat() + msg.Username = "username" + + _, err = tg.GetChat(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getChatAdministrators.go b/examples/methods/getChatAdministrators.go new file mode 100644 index 0000000..ea4b004 --- /dev/null +++ b/examples/methods/getChatAdministrators.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetChatAdministrators() + msg.Username = "username" + + _, err = tg.GetChatAdministrators(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getChatMember.go b/examples/methods/getChatMember.go new file mode 100644 index 0000000..2316014 --- /dev/null +++ b/examples/methods/getChatMember.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetChatMember() + msg.Username = "username" + msg.UserID = 1234 + + _, err = tg.GetChatMember(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getChatMemberCount.go b/examples/methods/getChatMemberCount.go new file mode 100644 index 0000000..eb274f5 --- /dev/null +++ b/examples/methods/getChatMemberCount.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetChatMemberCount() + msg.Username = "username" + + _, err = tg.GetChatMemberCount(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getChatMenuButton.go b/examples/methods/getChatMenuButton.go new file mode 100644 index 0000000..9a79011 --- /dev/null +++ b/examples/methods/getChatMenuButton.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewGetChatMenuButton() + + _, err = tg.GetChatMenuButton(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getCustomEmojiStickers.go b/examples/methods/getCustomEmojiStickers.go new file mode 100644 index 0000000..d4a9beb --- /dev/null +++ b/examples/methods/getCustomEmojiStickers.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewGetCustomEmojiStickers() + + message.CustomEmojiIds = []string{"1", "2", "3", "4"} + + _, err = tg.GetCustomEmojiStickers(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getFile.go b/examples/methods/getFile.go new file mode 100644 index 0000000..60897ce --- /dev/null +++ b/examples/methods/getFile.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetFile() + msg.FileID = "file id" + + _, err = tg.GetFile(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getForumTopicIconStickers.go b/examples/methods/getForumTopicIconStickers.go new file mode 100644 index 0000000..c079ed2 --- /dev/null +++ b/examples/methods/getForumTopicIconStickers.go @@ -0,0 +1,20 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetForumTopicIconStickers() + _, err = tg.GetForumTopicIconStickers(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getGameHighScores.go b/examples/methods/getGameHighScores.go new file mode 100644 index 0000000..f3fc922 --- /dev/null +++ b/examples/methods/getGameHighScores.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewGetGameHighScores() + message.UserID = 1234 + message.InlineMessageID = "id" + + _, err = tg.GetGameHighScores(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getMyCommandsWithScope.go b/examples/methods/getMyCommandsWithScope.go new file mode 100644 index 0000000..01039f5 --- /dev/null +++ b/examples/methods/getMyCommandsWithScope.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getCommands := tg.NewGetMyCommandsWithScope(tg.NewBotCommandScopeDefault()) + + _, err = tg.GetMyCommands(getCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getMyCommandsWithScopeAndLanguage.go b/examples/methods/getMyCommandsWithScopeAndLanguage.go new file mode 100644 index 0000000..1cfb986 --- /dev/null +++ b/examples/methods/getMyCommandsWithScopeAndLanguage.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getCommands := tg.NewGetMyCommandsWithScopeAndLanguage(tg.NewBotCommandScopeAllPrivateChats(), "en") + + _, err = tg.GetMyCommands(getCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getMyDefaultAdministratorRights.go b/examples/methods/getMyDefaultAdministratorRights.go new file mode 100644 index 0000000..2cdd03d --- /dev/null +++ b/examples/methods/getMyDefaultAdministratorRights.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getDefaultAdministratorRights := tg.NewGetMyDefaultAdministratorRights() + + _, err = tg.GetMyDefaultAdministratorRights(getDefaultAdministratorRights) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getMyDescription.go b/examples/methods/getMyDescription.go new file mode 100644 index 0000000..822483d --- /dev/null +++ b/examples/methods/getMyDescription.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getDescription := tg.NewGetMyDescription() + + _, err = tg.GetMyDescription(getDescription) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getMyShortDescription.go b/examples/methods/getMyShortDescription.go new file mode 100644 index 0000000..4cf2c19 --- /dev/null +++ b/examples/methods/getMyShortDescription.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + getDescription := tg.NewGetMyShortDescription() + + _, err = tg.GetMyShortDescription(getDescription) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getStarTransactions.go b/examples/methods/getStarTransactions.go new file mode 100644 index 0000000..affff36 --- /dev/null +++ b/examples/methods/getStarTransactions.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewGetStarTransactions() + + _, err = tg.GetStarTransactions(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getStickerSet.go b/examples/methods/getStickerSet.go new file mode 100644 index 0000000..f2de0c1 --- /dev/null +++ b/examples/methods/getStickerSet.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewGetStickerSet() + message.Name = "mySticker" + + _, err = tg.GetStickerSet(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getUserChatBoosts.go b/examples/methods/getUserChatBoosts.go new file mode 100644 index 0000000..97bfbf4 --- /dev/null +++ b/examples/methods/getUserChatBoosts.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetUserChatBoosts() + msg.ChatID = 1234 + msg.UserID = 1235 + + _, err = tg.GetUserChatBoosts(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/getUserProfilePhotos.go b/examples/methods/getUserProfilePhotos.go new file mode 100644 index 0000000..5adf7d9 --- /dev/null +++ b/examples/methods/getUserProfilePhotos.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewGetUserProfilePhotos() + msg.UserID = 1234 + + _, err = tg.GetUserProfilePhotos(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/hideGeneralForumTopic.go b/examples/methods/hideGeneralForumTopic.go new file mode 100644 index 0000000..fa9abb7 --- /dev/null +++ b/examples/methods/hideGeneralForumTopic.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewHideGeneralForumTopic() + msg.Username = "username" + + _, err = tg.HideGeneralForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/leaveChat.go b/examples/methods/leaveChat.go new file mode 100644 index 0000000..3b93bf0 --- /dev/null +++ b/examples/methods/leaveChat.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewLeaveChat() + msg.Username = "username" + + _, err = tg.LeaveChat(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/pinChatMessage.go b/examples/methods/pinChatMessage.go new file mode 100644 index 0000000..9d662b0 --- /dev/null +++ b/examples/methods/pinChatMessage.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewPinChatMessage() + msg.Username = "username" + msg.MessageID = 1234 + + _, err = tg.PinChatMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/promoteChatMember.go b/examples/methods/promoteChatMember.go new file mode 100644 index 0000000..0c0788b --- /dev/null +++ b/examples/methods/promoteChatMember.go @@ -0,0 +1,26 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewPromoteChatMember() + msg.Username = "username" + msg.UserID = 1234 + + msg.CanEditMessages = false + msg.CanInviteUsers = true + + _, err = tg.PromoteChatMember(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/refundStarPayment.go b/examples/methods/refundStarPayment.go new file mode 100644 index 0000000..1956e22 --- /dev/null +++ b/examples/methods/refundStarPayment.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewRefundStarPayment() + message.UserId = "user_id" + message.TelegramPaymentChargeId = "id" + + _, err = tg.RefundStarPayment(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/reopenForumTopic.go b/examples/methods/reopenForumTopic.go new file mode 100644 index 0000000..7cd1e15 --- /dev/null +++ b/examples/methods/reopenForumTopic.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewReopenForumTopic() + msg.Username = "username" + msg.MessageThreadID = 1234 + + _, err = tg.ReopenForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/reopenGeneralForumTopic.go b/examples/methods/reopenGeneralForumTopic.go new file mode 100644 index 0000000..bb025fc --- /dev/null +++ b/examples/methods/reopenGeneralForumTopic.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewReopenGeneralForumTopic() + msg.Username = "username" + + _, err = tg.ReopenGeneralForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/replaceStickerInSet.go b/examples/methods/replaceStickerInSet.go new file mode 100644 index 0000000..c98c32a --- /dev/null +++ b/examples/methods/replaceStickerInSet.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewReplaceStickerInSet() + message.UserID = 1234 + message.Name = "myName_by_" + message.OldSticker = "1234" + + stickers := tg.NewInputSticker() + stickers.EmojiList = []string{"🏀"} + + maskPosition := tg.NewMaskPosition() + + stickers.MaskPosition = maskPosition + stickers.Keywords = []string{"ball"} + stickers.Sticker = tg.FileURL("url") + + message.Sticker = stickers + + _, err = tg.ReplaceStickerInSet(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/restrictChatMember.go b/examples/methods/restrictChatMember.go new file mode 100644 index 0000000..f9a1407 --- /dev/null +++ b/examples/methods/restrictChatMember.go @@ -0,0 +1,29 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewRestrictChatMember() + msg.Username = "username" + msg.UserID = 1234 + + permissions := tg.NewChatPermissions() + permissions.CanChangeInfo = false + permissions.CanSendMessages = true + + msg.Permissions = permissions + + _, err = tg.RestrictChatMember(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/revokeChatInviteLink.go b/examples/methods/revokeChatInviteLink.go new file mode 100644 index 0000000..a08e0db --- /dev/null +++ b/examples/methods/revokeChatInviteLink.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewRevokeChatInviteLink() + msg.Username = "username" + msg.InviteLink = "url" + + _, err = tg.RevokeChatInviteLink(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendAnimation.go b/examples/methods/sendAnimation.go new file mode 100644 index 0000000..8aaca87 --- /dev/null +++ b/examples/methods/sendAnimation.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendAnimation() + msg.ChatID = 1234 + msg.Animation = tg.FileURL("url") + + _, err = tg.SendAnimation(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendAudio.go b/examples/methods/sendAudio.go new file mode 100644 index 0000000..50374e0 --- /dev/null +++ b/examples/methods/sendAudio.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendAudio() + msg.ChatID = 1234 + msg.Audio = tg.FileURL("url") + + _, err = tg.SendAudio(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendChatAction.go b/examples/methods/sendChatAction.go new file mode 100644 index 0000000..19b6a32 --- /dev/null +++ b/examples/methods/sendChatAction.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendChatAction() + msg.ChatID = 1234 + msg.Action = tg.TypingChatAction() + + _, err = tg.SendChatAction(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendContact.go b/examples/methods/sendContact.go new file mode 100644 index 0000000..1d05212 --- /dev/null +++ b/examples/methods/sendContact.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendContact() + msg.ChatID = 1234 + msg.PhoneNumber = "phone number" + msg.FirstName = "first name" + + _, err = tg.SendContact(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendDice.go b/examples/methods/sendDice.go new file mode 100644 index 0000000..9955a12 --- /dev/null +++ b/examples/methods/sendDice.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendDice() + msg.ChatID = 1234 + msg.Emoji = "⚽" + + _, err = tg.SendDice(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendDocument.go b/examples/methods/sendDocument.go new file mode 100644 index 0000000..8f56dfc --- /dev/null +++ b/examples/methods/sendDocument.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendDocument() + msg.ChatID = 1234 + msg.Document = tg.FilePath("filePath") + + _, err = tg.SendDocument(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendGame.go b/examples/methods/sendGame.go new file mode 100644 index 0000000..c046770 --- /dev/null +++ b/examples/methods/sendGame.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSendGame() + message.ChatID = 1234 + message.GameShortName = "name" + + _, err = tg.SendGame(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendInvoice.go b/examples/methods/sendInvoice.go new file mode 100644 index 0000000..29f9c1a --- /dev/null +++ b/examples/methods/sendInvoice.go @@ -0,0 +1,30 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSendInvoice() + message.ChatIDStr = "chatId" + message.Title = "title" + message.Description = "description" + message.Payload = "payload" + message.Currency = "currency" + message.Prices = tg.NewLabeledPrices( + tg.NewLabeledPrice("title1", 1234), + tg.NewLabeledPrice("title2", 1234), + ) + + _, err = tg.SendInvoice(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendLocation.go b/examples/methods/sendLocation.go new file mode 100644 index 0000000..a830e82 --- /dev/null +++ b/examples/methods/sendLocation.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendLocation() + msg.ChatID = 1234 + msg.Latitude = 1234 + msg.Longitude = 1234 + + _, err = tg.SendLocation(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendMediaGroup.go b/examples/methods/sendMediaGroup.go new file mode 100644 index 0000000..55e7bbe --- /dev/null +++ b/examples/methods/sendMediaGroup.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendMediaGroup() + msg.ChatID = 1234 + + var medias []any + + media := tg.NewInputMediaPhoto() + + media.Media = tg.FileURL("url1") + medias = append(medias, media) + + media.Media = tg.FileURL("url2") + medias = append(medias, media) + + msg.Media = medias + + _, err = tg.SendMediaGroup(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendMessage.go b/examples/methods/sendMessage.go new file mode 100644 index 0000000..154f2b0 --- /dev/null +++ b/examples/methods/sendMessage.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendMessage() + msg.ChatID = 1234 + msg.ParseMode = tg.ModeMarkdown() + msg.Text = "some text" + + _, err = tg.SendMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendMessageEscapeText.go b/examples/methods/sendMessageEscapeText.go new file mode 100644 index 0000000..b1681f5 --- /dev/null +++ b/examples/methods/sendMessageEscapeText.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendMessage() + msg.ChatID = 1234 + msg.ParseMode = tg.ModeMarkdown() + msg.Text = tg.EscapeText(msg.ParseMode, "some text") + + _, err = tg.SendMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendMessageRemoveKeyboard.go b/examples/methods/sendMessageRemoveKeyboard.go new file mode 100644 index 0000000..7ac6fdc --- /dev/null +++ b/examples/methods/sendMessageRemoveKeyboard.go @@ -0,0 +1,27 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendMessage() + msg.ChatID = 1234 + + keyboard := tg.NewReplyKeyboardRemove(true) + keyboard.Selective = true + + msg.ReplyMarkup = keyboard + + _, err = tg.SendMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendMessageWithInlineKeyboard.go b/examples/methods/sendMessageWithInlineKeyboard.go new file mode 100644 index 0000000..4fb5346 --- /dev/null +++ b/examples/methods/sendMessageWithInlineKeyboard.go @@ -0,0 +1,34 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendMessage() + msg.ChatID = 1234 + msg.Text = "text" + keyboard := tg.NewInlineKeyboardMarkup( + tg.NewInlineKeyboardRow( + tg.NewInlineKeyboardCallbackData("btn1", "data1"), + ), + tg.NewInlineKeyboardRow( + tg.NewInlineKeyboardCallbackData("btn2", "data2"), + tg.NewInlineKeyboardCallbackData("btn3", "data3"), + ), + ) + + msg.ReplyMarkup = keyboard + + _, err = tg.SendMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendMessageWithKeyboard.go b/examples/methods/sendMessageWithKeyboard.go new file mode 100644 index 0000000..8c30e58 --- /dev/null +++ b/examples/methods/sendMessageWithKeyboard.go @@ -0,0 +1,39 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendMessage() + msg.ChatID = 1234 + msg.Text = "text" + + keyboard := tg.NewReplyKeyboardMarkup( + tg.NewKeyboardButtonRow( + tg.NewKeyboardButton("btn1"), + ), + tg.NewKeyboardButtonRow( + tg.NewKeyboardButton("btn2"), + tg.NewKeyboardButton("btn3"), + ), + ) + keyboard.ResizeKeyboard = true + keyboard.OneTimeKeyboard = true + keyboard.Selective = true + keyboard.InputFieldPlaceholder = "some text" + + msg.ReplyMarkup = keyboard + + _, err = tg.SendMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendPaidMedia.go b/examples/methods/sendPaidMedia.go new file mode 100644 index 0000000..ff7160e --- /dev/null +++ b/examples/methods/sendPaidMedia.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendPaidMedia() + msg.ChatID = 1234 + msg.StarCount = 2 + + var medias []any + + media := tg.NewInputPaidMediaPhoto() + + media.Media = tg.FileURL("url1") + medias = append(medias, media) + + media.Media = tg.FileURL("url2") + medias = append(medias, media) + + msg.Media = medias + + _, err = tg.SendPaidMedia(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendPhoto.go b/examples/methods/sendPhoto.go new file mode 100644 index 0000000..f17809e --- /dev/null +++ b/examples/methods/sendPhoto.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendPhoto() + msg.ChatID = 1234 + msg.Photo = tg.FileURL("url") + + _, err = tg.SendPhoto(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendPoll.go b/examples/methods/sendPoll.go new file mode 100644 index 0000000..331a6a9 --- /dev/null +++ b/examples/methods/sendPoll.go @@ -0,0 +1,34 @@ +package main + +import ( + "github.com/alisapro/telegram-bot-api/types" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendPoll() + msg.ChatID = 1234 + msg.Question = "question" + + var inputPollOptions []types.InputPollOption + inputPollOptions = append(inputPollOptions, types.InputPollOption{ + Text: "text1", + }) + inputPollOptions = append(inputPollOptions, types.InputPollOption{ + Text: "text2", + }) + + msg.Options = inputPollOptions + + _, err = tg.SendPoll(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendSticker.go b/examples/methods/sendSticker.go new file mode 100644 index 0000000..39de9db --- /dev/null +++ b/examples/methods/sendSticker.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSendSticker() + message.ChatID = 1234 + message.Sticker = tg.FileURL("url") + + _, err = tg.SendSticker(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendVenue.go b/examples/methods/sendVenue.go new file mode 100644 index 0000000..6d5ca6a --- /dev/null +++ b/examples/methods/sendVenue.go @@ -0,0 +1,26 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendVenue() + msg.ChatID = 1234 + msg.Latitude = 1234 + msg.Longitude = 1234 + msg.Title = "title" + msg.Address = "address" + + _, err = tg.SendVenue(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendVideo.go b/examples/methods/sendVideo.go new file mode 100644 index 0000000..92447cf --- /dev/null +++ b/examples/methods/sendVideo.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendVideo() + msg.ChatID = 1234 + msg.Video = tg.FileURL("url") + + _, err = tg.SendVideo(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendVideoNote.go b/examples/methods/sendVideoNote.go new file mode 100644 index 0000000..87fc7e8 --- /dev/null +++ b/examples/methods/sendVideoNote.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendVideoNote() + msg.ChatID = 1234 + msg.VideoNote = tg.FileURL("url") + + _, err = tg.SendVideoNote(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/sendVoice.go b/examples/methods/sendVoice.go new file mode 100644 index 0000000..50374e0 --- /dev/null +++ b/examples/methods/sendVoice.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSendAudio() + msg.ChatID = 1234 + msg.Audio = tg.FileURL("url") + + _, err = tg.SendAudio(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatAdministratorCustomTitle.go b/examples/methods/setChatAdministratorCustomTitle.go new file mode 100644 index 0000000..40abfc3 --- /dev/null +++ b/examples/methods/setChatAdministratorCustomTitle.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetChatAdministratorCustomTitle() + msg.Username = "username" + msg.UserID = 1234 + msg.CustomTitle = "title" + + _, err = tg.SetChatAdministratorCustomTitle(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatDescription.go b/examples/methods/setChatDescription.go new file mode 100644 index 0000000..29c0812 --- /dev/null +++ b/examples/methods/setChatDescription.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetChatDescription() + msg.Username = "username" + msg.Description = "description" + + _, err = tg.SetChatDescription(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatMenuButton.go b/examples/methods/setChatMenuButton.go new file mode 100644 index 0000000..995fa95 --- /dev/null +++ b/examples/methods/setChatMenuButton.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + chatMenu := tg.NewSetChatMenuButton() + chatMenu.MenuButton = tg.NewMenuButtonDefault() + + _, err = tg.SetChatMenuButton(chatMenu) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatPermissions.go b/examples/methods/setChatPermissions.go new file mode 100644 index 0000000..afd8b39 --- /dev/null +++ b/examples/methods/setChatPermissions.go @@ -0,0 +1,28 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetChatPermissions() + msg.Username = "username" + + permissions := tg.NewChatPermissions() + permissions.CanChangeInfo = false + permissions.CanSendMessages = true + + msg.Permissions = permissions + + _, err = tg.SetChatPermissions(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatPhoto.go b/examples/methods/setChatPhoto.go new file mode 100644 index 0000000..46da3c0 --- /dev/null +++ b/examples/methods/setChatPhoto.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetChatPhoto() + msg.Username = "username" + msg.Photo = tg.FilePath("path") + + _, err = tg.SetChatPhoto(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatStickerSet.go b/examples/methods/setChatStickerSet.go new file mode 100644 index 0000000..2c8d875 --- /dev/null +++ b/examples/methods/setChatStickerSet.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetChatStickerSet() + msg.Username = "username" + msg.StickerSetName = "name" + + _, err = tg.SetChatStickerSet(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setChatTitle.go b/examples/methods/setChatTitle.go new file mode 100644 index 0000000..a36d66a --- /dev/null +++ b/examples/methods/setChatTitle.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetChatTitle() + msg.Username = "username" + msg.Title = "title" + + _, err = tg.SetChatTitle(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setCustomEmojiStickerSetThumbnail.go b/examples/methods/setCustomEmojiStickerSetThumbnail.go new file mode 100644 index 0000000..0be248e --- /dev/null +++ b/examples/methods/setCustomEmojiStickerSetThumbnail.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetCustomEmojiStickerSetThumbnail() + msg.Name = "name" + + _, err = tg.SetCustomEmojiStickerSetThumbnail(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setGameScore.go b/examples/methods/setGameScore.go new file mode 100644 index 0000000..e0d2d38 --- /dev/null +++ b/examples/methods/setGameScore.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSetGameScore() + message.UserID = 1234 + message.Score = 1 + message.InlineMessageID = "id" + + _, err = tg.SetGameScore(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMessageReaction.go b/examples/methods/setMessageReaction.go new file mode 100644 index 0000000..397e8d0 --- /dev/null +++ b/examples/methods/setMessageReaction.go @@ -0,0 +1,36 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" + "github.com/alisapro/telegram-bot-api/types" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetMessageReaction() + msg.ChatID = 1234 + msg.MessageID = 1235 + + reaction := types.ReactionType{ + ReactionTypeEmoji: types.ReactionTypeEmoji{ + Type: "emoji", + Emoji: "❤", + }, + ReactionTypeCustomEmoji: types.ReactionTypeCustomEmoji{ + Type: "custom_emoji", + CustomEmoji: "😀", + }, + } + msg.Reaction = append(msg.Reaction, reaction) + + _, err = tg.SetMessageReaction(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMyCommands.go b/examples/methods/setMyCommands.go new file mode 100644 index 0000000..2bdced4 --- /dev/null +++ b/examples/methods/setMyCommands.go @@ -0,0 +1,25 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + setCommands := tg.NewSetMyCommands( + tg.NewBotCommand("/command1", "description 1"), + tg.NewBotCommand("/command2", "description 2"), + tg.NewBotCommand("/command3", "description 3"), + ) + + _, err = tg.SetMyCommands(setCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMyCommandsWithScope.go b/examples/methods/setMyCommandsWithScope.go new file mode 100644 index 0000000..c741e59 --- /dev/null +++ b/examples/methods/setMyCommandsWithScope.go @@ -0,0 +1,25 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + setCommands := tg.NewSetMyCommandsWithScope(tg.NewBotCommandScopeAllPrivateChats(), + tg.NewBotCommand("/command1", "description 1"), + tg.NewBotCommand("/command2", "description 2"), + tg.NewBotCommand("/command3", "description 3"), + ) + + _, err = tg.SetMyCommands(setCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMyCommandsWithScopeAndLanguage.go b/examples/methods/setMyCommandsWithScopeAndLanguage.go new file mode 100644 index 0000000..3ccaad2 --- /dev/null +++ b/examples/methods/setMyCommandsWithScopeAndLanguage.go @@ -0,0 +1,25 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + setCommands := tg.NewSetMyCommandsWithScopeAndLanguage(tg.NewBotCommandScopeAllPrivateChats(), "en", + tg.NewBotCommand("/command1", "description 1"), + tg.NewBotCommand("/command2", "description 2"), + tg.NewBotCommand("/command3", "description 3"), + ) + + _, err = tg.SetMyCommands(setCommands) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMyDefaultAdministratorRights.go b/examples/methods/setMyDefaultAdministratorRights.go new file mode 100644 index 0000000..7e1bff9 --- /dev/null +++ b/examples/methods/setMyDefaultAdministratorRights.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSetMyDefaultAdministratorRights() + + _, err = tg.SetMyDefaultAdministratorRights(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMyDescription.go b/examples/methods/setMyDescription.go new file mode 100644 index 0000000..0ea8f63 --- /dev/null +++ b/examples/methods/setMyDescription.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + setDescription := tg.NewSetMyDescription() + setDescription.Description = "description" + + _, err = tg.SetMyDescription(setDescription) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setMyShortDescription.go b/examples/methods/setMyShortDescription.go new file mode 100644 index 0000000..af0cfb9 --- /dev/null +++ b/examples/methods/setMyShortDescription.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + setDescription := tg.NewSetMyShortDescription() + setDescription.ShortDescription = "short description" + + _, err = tg.SetMyShortDescription(setDescription) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setPassportDataErrors.go b/examples/methods/setPassportDataErrors.go new file mode 100644 index 0000000..5fb1fa8 --- /dev/null +++ b/examples/methods/setPassportDataErrors.go @@ -0,0 +1,32 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSetPassportDataErrors() + message.UserID = 1234 + + var Errors []any + + passportElementErrorDataField := tg.PassportElementErrorDataField() + passportElementErrorDataField.Source = "source" + passportElementErrorDataField.Type = "type" + passportElementErrorDataField.Message = "message" + Errors = append(Errors, passportElementErrorDataField) + + message.Errors = Errors + + _, err = tg.SetPassportDataErrors(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setStickerEmojiList.go b/examples/methods/setStickerEmojiList.go new file mode 100644 index 0000000..6d8214a --- /dev/null +++ b/examples/methods/setStickerEmojiList.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetStickerEmojiList() + msg.Sticker = "1234" + msg.EmojiList = []string{"🏀"} + + _, err = tg.SetStickerEmojiList(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setStickerKeywords.go b/examples/methods/setStickerKeywords.go new file mode 100644 index 0000000..c73eb26 --- /dev/null +++ b/examples/methods/setStickerKeywords.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetStickerKeywords() + msg.Sticker = "1234" + msg.Keywords = []string{"ball"} + + _, err = tg.SetStickerKeywords(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setStickerMaskPosition.go b/examples/methods/setStickerMaskPosition.go new file mode 100644 index 0000000..b6563a7 --- /dev/null +++ b/examples/methods/setStickerMaskPosition.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetStickerMaskPosition() + msg.Sticker = "1234" + + _, err = tg.SetStickerMaskPosition(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setStickerPositionInSet.go b/examples/methods/setStickerPositionInSet.go new file mode 100644 index 0000000..be60a95 --- /dev/null +++ b/examples/methods/setStickerPositionInSet.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSetStickerPositionInSet() + message.Sticker = "🎯" + message.Position = 0 + + _, err = tg.SetStickerPositionInSet(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setStickerSetThumbnail.go b/examples/methods/setStickerSetThumbnail.go new file mode 100644 index 0000000..46795dc --- /dev/null +++ b/examples/methods/setStickerSetThumbnail.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewSetStickerSetThumbnail() + message.UserID = 1234 + message.Name = "name" + message.Format = "static" // “static”, “animated”, “video” + + _, err = tg.SetStickerSetThumbnail(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/setStickerSetTitle.go b/examples/methods/setStickerSetTitle.go new file mode 100644 index 0000000..4102f97 --- /dev/null +++ b/examples/methods/setStickerSetTitle.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewSetStickerSetTitle() + msg.Name = "name" + msg.Title = "title" + + _, err = tg.SetStickerSetTitle(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/stopMessageLiveLocation.go b/examples/methods/stopMessageLiveLocation.go new file mode 100644 index 0000000..5d09d2b --- /dev/null +++ b/examples/methods/stopMessageLiveLocation.go @@ -0,0 +1,28 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewStopMessageLiveLocation() + + // use InlineMessageID + msg.InlineMessageID = "id" + + // or use ChatID & MessageID + msg.ChatID = 1234 + msg.MessageID = 1234 + + _, err = tg.StopMessageLiveLocation(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/stopPoll.go b/examples/methods/stopPoll.go new file mode 100644 index 0000000..262ba65 --- /dev/null +++ b/examples/methods/stopPoll.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewStopPoll() + message.ChatID = 1234 + message.MessageID = 1234 + + _, err = tg.StopPoll(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/unHideGeneralForumTopic.go b/examples/methods/unHideGeneralForumTopic.go new file mode 100644 index 0000000..51fe5a4 --- /dev/null +++ b/examples/methods/unHideGeneralForumTopic.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewUnHideGeneralForumTopic() + msg.Username = "username" + + _, err = tg.UnHideGeneralForumTopic(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/unbanChatMember.go b/examples/methods/unbanChatMember.go new file mode 100644 index 0000000..a1e23e0 --- /dev/null +++ b/examples/methods/unbanChatMember.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewUnbanChatMember() + msg.Username = "username" + msg.UserID = 1234 + + _, err = tg.UnbanChatMember(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/unbanChatSenderChat.go b/examples/methods/unbanChatSenderChat.go new file mode 100644 index 0000000..afcc387 --- /dev/null +++ b/examples/methods/unbanChatSenderChat.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewUnbanChatSenderChat() + msg.Username = "username" + msg.SenderChatID = 1234 + + _, err = tg.UnbanChatSenderChat(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/unpinAllChatMessages.go b/examples/methods/unpinAllChatMessages.go new file mode 100644 index 0000000..d0a8371 --- /dev/null +++ b/examples/methods/unpinAllChatMessages.go @@ -0,0 +1,22 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewUnpinAllChatMessages() + msg.Username = "username" + + _, err = tg.UnpinAllChatMessages(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/unpinAllForumTopicMessages.go b/examples/methods/unpinAllForumTopicMessages.go new file mode 100644 index 0000000..d00fed6 --- /dev/null +++ b/examples/methods/unpinAllForumTopicMessages.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewUnpinAllForumTopicMessages() + msg.Username = "username" + msg.MessageThreadID = 1234 + + _, err = tg.UnpinAllForumTopicMessages(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/unpinChatMessage.go b/examples/methods/unpinChatMessage.go new file mode 100644 index 0000000..3dd46ac --- /dev/null +++ b/examples/methods/unpinChatMessage.go @@ -0,0 +1,23 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + msg := tg.NewUnpinChatMessage() + msg.Username = "username" + msg.MessageID = 1234 + + _, err = tg.UnpinChatMessage(msg) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/methods/uploadStickerFile.go b/examples/methods/uploadStickerFile.go new file mode 100644 index 0000000..076c2e7 --- /dev/null +++ b/examples/methods/uploadStickerFile.go @@ -0,0 +1,24 @@ +package main + +import ( + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + message := tg.NewUploadStickerFile() + message.UserID = 1234 + message.Sticker = tg.FilePath("path") + message.StickerFormat = "static" // “static”, “animated”, “video” + + _, err = tg.UploadStickerFile(message) + if err != nil { + log.Fatal(err) + } +} diff --git a/examples/webhook/info.go b/examples/webhook/info.go new file mode 100644 index 0000000..07dde91 --- /dev/null +++ b/examples/webhook/info.go @@ -0,0 +1,28 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + webhook, err := tg.GetWebhook() + if err != nil { + log.Fatal(err) + } + + out, err := json.MarshalIndent(webhook, "", " ") + if err != nil { + log.Fatal(err) + } + + fmt.Printf("webhook info: \n%s\n", string(out)) +} diff --git a/examples/webhook/set.go b/examples/webhook/set.go new file mode 100644 index 0000000..8aeaaaa --- /dev/null +++ b/examples/webhook/set.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "net/url" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + tg.SetSecretToken("BotSecretToken") // optional + + hook := tg.NewSetWebhook() + + u, err := url.Parse("BotHookUrl") + if err != nil { + log.Fatal(err) + } + hook.URL = u + hook.Certificate = tg.FilePath("CertFile") + hook.MaxConnections = 100 + // hook.AllowedUpdates = []string{"message", "edited_channel_post", "callback_query"} + + webhook, err := tg.SetWebhook(hook) + if err != nil { + log.Fatal(err) + } + + out, err := json.MarshalIndent(webhook, "", " ") + if err != nil { + log.Fatal(err) + } + + fmt.Printf("status: \n%s\n", string(out)) +} diff --git a/examples/webhook/unset.go b/examples/webhook/unset.go new file mode 100644 index 0000000..3a2b828 --- /dev/null +++ b/examples/webhook/unset.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/alisapro/telegram-bot-api/telegram" +) + +func main() { + tg, err := telegram.New("BotToken") + if err != nil { + log.Fatal(err) + } + + hook := tg.NewDeleteWebhook() + hook.DropPendingUpdates = true + + webhook, err := tg.DeleteWebhook(hook) + if err != nil { + log.Fatal(err) + } + + out, err := json.MarshalIndent(webhook, "", " ") + if err != nil { + log.Fatal(err) + } + + fmt.Printf("status: \n%s\n", string(out)) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d763412 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/alisapro/telegram-bot-api + +go 1.18 diff --git a/telegram/helpers.go b/telegram/helpers.go new file mode 100644 index 0000000..237ecd6 --- /dev/null +++ b/telegram/helpers.go @@ -0,0 +1,312 @@ +package telegram + +import ( + "context" + "encoding/json" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/url" + "os" + "strings" + "time" + + "github.com/alisapro/telegram-bot-api/config" + "github.com/alisapro/telegram-bot-api/types" +) + +// SetSecretToken parse secret token for very webhook request +func (t *Api) SetSecretToken(secretToken string) { + Core.Bot.SecretToken = secretToken +} + +// WriteDebugLog write debug log to bot log interface +func (t *Api) WriteDebugLog(msg string) { + logger := log.New(&t.Bot.Log, "Debug: ", log.LstdFlags|log.Llongfile) + Info := func(info string) { + _ = logger.Output(2, info) + } + Info(msg) +} + +// GetLoggerFile get debug log +func (t *Api) GetLoggerFile() string { + return t.Bot.Log.String() +} + +// WriteLoggerFile write debug to file +func (t *Api) WriteLoggerFile(fileName string) error { + return os.WriteFile(fileName, t.Bot.Log.Bytes(), 0666) +} + +// MakeRequest makes a request to a specific endpoint with our token. +func (t *Api) MakeRequest(endpoint string, params types.Params) (*types.APIResponse, error) { + if t.Bot.Debug { + t.WriteDebugLog(fmt.Sprintf("Endpoint: %s, params: %v\n", endpoint, params)) + } + + URL := fmt.Sprintf(t.Bot.BaseUrl+config.APIEndpoint, t.Bot.Token, endpoint) + + values := buildParams(params) + + var timeout time.Duration + if t.Bot.RequestTimeout == 0 { + timeout = 90 * time.Second + } else { + timeout = t.Bot.RequestTimeout + } + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + req, err := http.NewRequestWithContext(ctx, http.MethodPost, URL, strings.NewReader(values.Encode())) + if err != nil { + return nil, err + } + + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + if t.Bot.SecretToken != "" { + req.Header.Set("X-Telegram-Bot-Api-Secret-Token", t.Bot.SecretToken) + } + + var resp *http.Response + resp, err = t.Bot.Client.Do(req) + if err != nil { + return nil, err + } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) + + var apiResp types.APIResponse + var bytes []byte + bytes, err = t.decodeAPIResponse(resp.Body, &apiResp) + if err != nil { + return &apiResp, err + } + + if t.Bot.Debug { + t.WriteDebugLog(fmt.Sprintf("Endpoint: %s, response: %s\n", endpoint, string(bytes))) + } + + if !apiResp.Ok { + var parameters types.ResponseParameters + if apiResp.Parameters != nil { + parameters = *apiResp.Parameters + } + return &apiResp, &types.Error{ + Code: apiResp.ErrorCode, + Message: apiResp.Description, + ResponseParameters: parameters, + } + } + + return &apiResp, nil +} + +// UploadFiles makes a request to the API with files. +func (t *Api) UploadFiles(endpoint string, params types.Params, files []types.RequestFile) (*types.APIResponse, error) { + r, w := io.Pipe() + m := multipart.NewWriter(w) + + go func() { + defer func(w *io.PipeWriter) { + _ = w.Close() + }(w) + defer func(m *multipart.Writer) { + _ = m.Close() + }(m) + + for field, value := range params { + if err := m.WriteField(field, value); err != nil { + _ = w.CloseWithError(err) + return + } + } + + for _, file := range files { + if file.Data.NeedsUpload() { + name, reader, err := file.Data.UploadData() + if err != nil { + _ = w.CloseWithError(err) + return + } + if file.FileName != "" { + name = file.FileName + } + + part, err := m.CreateFormFile(file.Name, name) + if err != nil { + _ = w.CloseWithError(err) + return + } + + if _, err = io.Copy(part, reader); err != nil { + _ = w.CloseWithError(err) + return + } + + if closer, ok := reader.(io.ReadCloser); ok { + if err = closer.Close(); err != nil { + _ = w.CloseWithError(err) + return + } + } + } else { + value := file.Data.SendData() + + if err := m.WriteField(file.Name, value); err != nil { + _ = w.CloseWithError(err) + return + } + } + } + }() + + if t.Bot.Debug { + t.WriteDebugLog(fmt.Sprintf("Endpoint: %s, params: %v, with %d files\n", endpoint, params, len(files))) + } + + URL := fmt.Sprintf(t.Bot.BaseUrl+config.APIEndpoint, t.Bot.Token, endpoint) + + var timeout time.Duration + if t.Bot.RequestTimeout == 0 { + timeout = 2 * time.Minute + } else { + timeout = t.Bot.RequestTimeout + } + + ctx, cancel := context.WithTimeout(context.Background(), timeout) + defer cancel() + req, err := http.NewRequestWithContext(ctx, http.MethodPost, URL, r) + if err != nil { + return nil, err + } + + req.Header.Set("Content-Type", m.FormDataContentType()) + if t.Bot.SecretToken != "" { + req.Header.Set("X-Telegram-Bot-Api-Secret-Token", t.Bot.SecretToken) + } + + var resp *http.Response + resp, err = t.Bot.Client.Do(req) + if err != nil { + return nil, err + } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) + + var apiResp types.APIResponse + var bytes []byte + bytes, err = t.decodeAPIResponse(resp.Body, &apiResp) + if err != nil { + return &apiResp, err + } + + if t.Bot.Debug { + t.WriteDebugLog(fmt.Sprintf("Endpoint: %s, response: %s\n", endpoint, string(bytes))) + } + + if !apiResp.Ok { + var parameters types.ResponseParameters + if apiResp.Parameters != nil { + parameters = *apiResp.Parameters + } + return &apiResp, &types.Error{ + Code: apiResp.ErrorCode, + Message: apiResp.Description, + ResponseParameters: parameters, + } + } + + return &apiResp, nil +} + +// Request sends a Chattable to Telegram, and returns the APIResponse. +func (t *Api) Request(c types.Chattable) (*types.APIResponse, error) { + params, err := c.Params() + if err != nil { + return nil, err + } + + if f, ok := c.(types.Fileable); ok { + files := f.Files() + + // If we have files that need to be uploaded, we should delegate the + // request to UploadFile. + if hasFilesNeedingUpload(files) { + return t.UploadFiles(f.EndPoint(), params, files) + } + + // However, if there are no files to be uploaded, there are likely things + // that need to be turned into params instead. + for _, file := range files { + params[file.Name] = file.Data.SendData() + } + } + + return t.MakeRequest(c.EndPoint(), params) +} + +// Send will send a Chattable item to Telegram and provides the returned Message. +func (t *Api) Send(c types.Chattable) (*types.Message, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var message types.Message + err = json.Unmarshal(resp.Result, &message) + if err != nil { + return nil, err + } + + return &message, err +} + +// decodeAPIResponse decode response and return slice of bytes if debug enabled. +func (t *Api) decodeAPIResponse(responseBody io.Reader, resp *types.APIResponse) ([]byte, error) { + if !t.Bot.Debug { + dec := json.NewDecoder(responseBody) + err := dec.Decode(resp) + return nil, err + } + + data, err := io.ReadAll(responseBody) + if err != nil { + return nil, err + } + + err = json.Unmarshal(data, resp) + if err != nil { + return nil, err + } + + return data, nil +} + +func buildParams(in types.Params) url.Values { + if in == nil { + return url.Values{} + } + + out := url.Values{} + + for key, value := range in { + out.Set(key, value) + } + + return out +} + +func hasFilesNeedingUpload(files []types.RequestFile) bool { + for _, file := range files { + if file.Data.NeedsUpload() { + return true + } + } + + return false +} diff --git a/telegram/methods.go b/telegram/methods.go new file mode 100644 index 0000000..14f0710 --- /dev/null +++ b/telegram/methods.go @@ -0,0 +1,2848 @@ +package telegram + +import ( + "encoding/json" + "errors" + "fmt" + "log" + "time" + + "github.com/alisapro/telegram-bot-api/config" + "github.com/alisapro/telegram-bot-api/types" +) + +// GetUpdates Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. +// Notes: +// 1. This method will not work if an outgoing webhook is set up. +// 2. In order to avoid getting duplicate updates, recalculate offset after each server response. +func (t *Api) GetUpdates(c *types.GetUpdates) ([]types.Update, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var updates []types.Update + err = json.Unmarshal(resp.Result, &updates) + + return updates, err +} + +// GetUpdatesChan starts and returns a channel for getting updates. +func (t *Api) GetUpdatesChan(c *types.GetUpdates) types.UpdatesChannel { + t.Bot.GetUpdateChannel = make(chan any) + + if c.Limit < 1 || c.Limit > 100 { + c.Limit = 100 + } + ch := make(chan types.Update, c.Limit) + + go func() { + for { + select { + case <-t.Bot.GetUpdateChannel: + close(ch) + return + default: + } + + updates, err := t.GetUpdates(c) + if err != nil { + if t.Bot.Debug { + t.WriteDebugLog(fmt.Sprintf("Failed to get updates, retrying in 3 seconds... Error:%s", err.Error())) + } + log.Println(err) + log.Println("Failed to get updates, retrying in 3 seconds...") + time.Sleep(time.Second * 3) + + continue + } + + for _, update := range updates { + if update.UpdateID >= c.Offset { + c.Offset = update.UpdateID + 1 + ch <- update + } + } + } + }() + + return ch +} + +// StopReceivingUpdates stops the go routine which receives updates +func (t *Api) StopReceivingUpdates() { + close(t.Bot.GetUpdateChannel) +} + +// SetWebhook Use this method to specify a URL and receive incoming updates via an outgoing webhook. +// Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, +// containing a JSON-serialized Update. +// In case of an unsuccessful request, we will give up after a reasonable number of attempts. +// Returns True to success. +// If you'd like to make sure that you set the webhook, +// you can specify secret data in the parameter secret_token. +// If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content. +func (t *Api) SetWebhook(c *types.SetWebhook) (*json.RawMessage, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + return &resp.Result, err +} + +// DeleteWebhook Use this method to remove webhook integration if you decide to switch back to getUpdates. +// Returns True to success. +func (t *Api) DeleteWebhook(c *types.DeleteWebhook) (*json.RawMessage, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + return &resp.Result, err +} + +// GetWebhook Use this method to get current webhook status. +// Requires no parameters. +// On success, returns a WebhookInfo object. +// If the bot is using getUpdates, will return an object with the url field empty. +func (t *Api) GetWebhook() (*types.WebhookInfo, error) { + resp, err := t.MakeRequest(config.EndpointGetWebhook, nil) + if err != nil { + return nil, err + } + + var webhookInfo types.WebhookInfo + err = json.Unmarshal(resp.Result, &webhookInfo) + + return &webhookInfo, err +} + +// GetMe A simple method for testing your bot authentication token. +// Requires no parameters. +// Returns basic information about the bot in the form of a User object. +func (t *Api) GetMe() (*types.User, error) { + resp, err := t.MakeRequest(config.EndpointGetMe, nil) + if err != nil { + return nil, err + } + + var user types.User + err = json.Unmarshal(resp.Result, &user) + + if err == nil { + user.IDString = fmt.Sprintf("%d", user.ID) + } + + return &user, err +} + +// LogOut Use this method to log out from the cloud Bot API server before launching the bot locally. +// You must log out the bot before running it locally, +// otherwise there is no guarantee that the bot will receive updates. +// After a successful call, you can immediately log in on a local server, +// but will not be able to log in back to the cloud Bot API server for 10 minutes. +// Returns True to success. +// Requires no parameters. +func (t *Api) LogOut() (bool, error) { + resp, err := t.MakeRequest(config.EndpointLogOut, nil) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// Close Use this method to close the bot instance before moving it from one local server to another. +// You need to delete the webhook before calling this method to ensure that the +// bot isn't launched again after the server restarts. +// The method will return +// error 429 in the first 10 minutes after the bot is launched. +// Returns True to +// success. +// Requires no parameters. +func (t *Api) Close() (bool, error) { + resp, err := t.MakeRequest(config.EndpointClose, nil) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SendMessage Use this method to send text messages. On success, the sent Message is returned. +func (t *Api) SendMessage(c *types.SendMessage) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Text == "" { + return nil, errors.New("text Required") + } + + return t.Send(c) +} + +// ForwardMessage Use this method to forward messages of any kind. +// Service messages can't be forwarded. +// On success, the sent Message is returned. +func (t *Api) ForwardMessage(c *types.ForwardMessage) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.FromChatID == 0 && c.FromChatIDStr == "" && c.FromUsername == "" { + return nil, errors.New("FromChatID or FromUsername Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + + return t.Send(c) +} + +// ForwardMessages Use this method to forward multiple messages of any kind. +// If some of the specified messages can't be found or forwarded, they are skipped. +// Service messages and messages with protected content can't be forwarded. +// Album grouping is kept for forwarded messages. +// On success, an array of MessageId of the sent messages is returned. +func (t *Api) ForwardMessages(c *types.ForwardMessages) ([]types.MessageID, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.FromChatID == 0 && c.FromChatIDStr == "" && c.FromUsername == "" { + return nil, errors.New("FromChatID or FromUsername Required") + } + if c.MessageIds == nil { + return nil, errors.New("MessageIds Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var messages []types.MessageID + err = json.Unmarshal(resp.Result, &messages) + + return messages, err +} + +// CopyMessage Use this method to copy messages of any kind. +// Service messages and invoice messages can't be copied. +// The method is analogous to the method forwardMessage, +// but the copied message doesn't have a link to the original message. +// Returns the MessageId of the sent message on success. +func (t *Api) CopyMessage(c *types.CopyMessage) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.FromChatID == 0 && c.FromChatIDStr == "" && c.FromUsername == "" { + return nil, errors.New("FromChatID or FromUsername Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + + return t.Send(c) +} + +// CopyMessages Use this method to copy messages of any kind. +// If some of the specified messages can't be found or copied, they are skipped. +// Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. +// A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. +// The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. +// Album grouping is kept for copied messages. +// On success, an array of MessageId of the sent messages is returned. +func (t *Api) CopyMessages(c *types.CopyMessages) ([]types.MessageID, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.FromChatID == 0 && c.FromChatIDStr == "" && c.FromUsername == "" { + return nil, errors.New("FromChatID or FromUsername Required") + } + if c.MessageIds == nil { + return nil, errors.New("MessageIds Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var messages []types.MessageID + err = json.Unmarshal(resp.Result, &messages) + + return messages, err +} + +// SendPhoto Use this method to send photos. On success, the sent Message is returned. +func (t *Api) SendPhoto(c *types.SendPhoto) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Photo == nil { + return nil, errors.New("photo Required") + } + + return t.Send(c) +} + +// SendAudio Use this method to send audio files if you want Telegram clients to display them in the music player. +// Your audio must be in the .MP3 or .M4A format. +// On success, the sent Message is returned. +// Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. +// For sending voice messages, use the sendVoice method instead. +func (t *Api) SendAudio(c *types.SendAudio) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Audio == nil { + return nil, errors.New("audio Required") + } + + return t.Send(c) +} + +// SendDocument Use this method to send general files. +// On success, the sent Message is returned. +// Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. +func (t *Api) SendDocument(c *types.SendDocument) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Document == nil { + return nil, errors.New("document Required") + } + + return t.Send(c) +} + +// SendVideo Use this method to send video files, +// Telegram clients support MPEG4 videos (other formats may be sent as Document). +// On success, the sent Message is returned. +// Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. +func (t *Api) SendVideo(c *types.SendVideo) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Video == nil { + return nil, errors.New("video Required") + } + + return t.Send(c) +} + +// SendAnimation Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without a sound). +// On success, the sent Message is returned. +// Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. +func (t *Api) SendAnimation(c *types.SendAnimation) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Animation == nil { + return nil, errors.New("animation Required") + } + + return t.Send(c) +} + +// SendVoice Use this method +// to send audio files if you want Telegram clients to display the file as a playable voice message. +// For this to work, your audio must be in an .OGG file encoded with OPUS +// (other formats may be sent as Audio or Document). +// On success, the sent Message is returned. +// Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. +func (t *Api) SendVoice(c *types.SendVoice) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Voice == nil { + return nil, errors.New("voice Required") + } + + return t.Send(c) +} + +// SendVideoNote As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. +// Use this method to send video messages. +// On success, the sent Message is returned. +func (t *Api) SendVideoNote(c *types.SendVideoNote) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.VideoNote == nil { + return nil, errors.New("VideoNote Required") + } + + return t.Send(c) +} + +// SendPaidMedia send paid media to channel chats. +// On success, the sent Message is returned. +func (t *Api) SendPaidMedia(c *types.SendPaidMedia) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.StarCount < 1 { + return nil, errors.New("StarCount Required") + } + if c.Media == nil { + return nil, errors.New("media Required") + } + + return t.Send(c) +} + +// SendMediaGroup Use this method to send a group of photos, videos, documents or audios as an album. +// Documents and audio files can be only grouped on an album with messages of the same type. +// On success, an array of Messages that were sent is returned. +func (t *Api) SendMediaGroup(c *types.SendMediaGroup) ([]types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Media == nil { + return nil, errors.New("media Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var messages []types.Message + err = json.Unmarshal(resp.Result, &messages) + + return messages, err +} + +// SendLocation Use this method to send point on the map. On success, the sent Message is returned. +func (t *Api) SendLocation(c *types.SendLocation) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Latitude == 0 { + return nil, errors.New("latitude Required") + } + if c.Longitude == 0 { + return nil, errors.New("longitude Required") + } + + return t.Send(c) +} + +// EditMessageLiveLocation Use this method to edit live location messages. +// A location can be edited +// until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +func (t *Api) EditMessageLiveLocation(c *types.EditMessageLiveLocation) (*types.Message, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + if c.Latitude == 0 { + return nil, errors.New("latitude Required") + } + if c.Longitude == 0 { + return nil, errors.New("longitude Required") + } + + return t.Send(c) +} + +// StopMessageLiveLocation Use this method to stop updating a live location message before live_period expires. +// On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. +func (t *Api) StopMessageLiveLocation(c *types.StopMessageLiveLocation) (*types.Message, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + + return t.Send(c) +} + +// SendVenue Use this method to send information about a venue. On success, the sent Message is returned. +func (t *Api) SendVenue(c *types.SendVenue) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Latitude == 0 { + return nil, errors.New("latitude Required") + } + if c.Longitude == 0 { + return nil, errors.New("longitude Required") + } + if c.Title == "" { + return nil, errors.New("title Required") + } + if c.Address == "" { + return nil, errors.New("address Required") + } + + return t.Send(c) +} + +// SendContact Use this method to send phone contacts. On success, the sent Message is returned. +func (t *Api) SendContact(c *types.SendContact) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.PhoneNumber == "" { + return nil, errors.New("PhoneNumber Required") + } + if c.FirstName == "" { + return nil, errors.New("FirstName Required") + } + + return t.Send(c) +} + +// SendPoll Use this method to send a native poll. On success, the sent Message is returned. +func (t *Api) SendPoll(c *types.SendPoll) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Question == "" { + return nil, errors.New("question Required") + } + if len(c.Options) == 0 { + return nil, errors.New("options Required") + } + + return t.Send(c) +} + +// SendDice Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned. +func (t *Api) SendDice(c *types.SendDice) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + + return t.Send(c) +} + +// SendChatAction Use this method when you need to tell the user that something is happening on the bot side. +// The status is set for 5 seconds or less +// (when a message arrives from your bot, Telegram clients clear its typing status). +// Returns True on success. +// Example: The ImageBot needs some time to process a request and upload the image. +// Instead of sending a text message along the lines of “Retrieving image, +// please wait…”, the bot may use sendChatAction with action = upload_photo. +// The user will see a “sending photo” status for the bot. +// We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. +func (t *Api) SendChatAction(c *types.SendChatAction) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.Action == "" { + return false, errors.New("action Required") + } + + _, err := t.Request(c) + if err != nil { + return false, err + } + + return true, nil +} + +// SetMessageReaction Use this method to change the chosen reactions on a message. Service messages can't be reacted to. +// Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. +// In albums, bots must react to the first message. +// Returns True on success. +func (t *Api) SetMessageReaction(c *types.SetMessageReaction) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + + _, err := t.Request(c) + if err != nil { + return false, err + } + + return true, nil +} + +// GetUserProfilePhotos Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. +func (t *Api) GetUserProfilePhotos(c *types.GetUserProfilePhotos) (*types.UserProfilePhotos, error) { + if c.UserID == 0 { + return nil, errors.New("UserID Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var profilePhotos types.UserProfilePhotos + err = json.Unmarshal(resp.Result, &profilePhotos) + + return &profilePhotos, err +} + +// GetFile Use this method to get basic information about a file and prepare it for downloading. +// For the moment, bots can download files of up to 20MB in size. +// On success, a File object is returned. +// The file can then be downloaded via the link https://api.telegram.org/file/bot/, +// where is taken from the response. +// It is guaranteed that the link will be valid for at least 1 hour. +// When the link expires, a new one can be requested by calling getFile again. +// Note: This function may not preserve the original file name and MIME type. +// You should save the file's MIME type and name (if available) when the File object is received. +func (t *Api) GetFile(c *types.GetFile) (*types.File, error) { + if c.FileID == "" { + return nil, errors.New("FileID Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var file types.File + err = json.Unmarshal(resp.Result, &file) + + return &file, err +} + +// BanChatMember Use this method to ban a user in a group, a supergroup or a channel. +// In the case of supergroups and channels, +// the user will not be able to return to the chat on their own using invite links, etc., +// unless unbanned first. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) BanChatMember(c *types.BanChatMember) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("UserID Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnbanChatMember Use this method to unban a previously banned user in a supergroup or channel. +// The user will not return to the group or channel automatically, +// but will be able to join via a link, etc. The bot must be an administrator for this to work. +// By default, this method guarantees that after the call the user is not a member of the chat, +// but will be able to join it. +// So if the user is a member of the chat, they will also be removed from the chat. +// If you don't want this, use the parameter only_if_banned. +// Returns True to success. +func (t *Api) UnbanChatMember(c *types.UnbanChatMember) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("user_id Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// RestrictChatMember Use this method to restrict a user in a supergroup. +// The bot must be an administrator in the supergroup for this to work +// and must have the appropriate administrator rights. +// Pass True for all permissions to lift restrictions from a user. +// Returns True to success. +func (t *Api) RestrictChatMember(c *types.RestrictChatMember) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("user_id Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// PromoteChatMember Use this method to promote or demote a user in a supergroup or a channel. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Pass False for all boolean parameters to demote a user. +// Returns True to success. +func (t *Api) PromoteChatMember(c *types.PromoteChatMember) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("user_id Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetChatAdministratorCustomTitle Use this method +// to set a custom title for an administrator in a supergroup promoted by the bot. +// Returns True to success. +func (t *Api) SetChatAdministratorCustomTitle(c *types.SetChatAdministratorCustomTitle) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("user_id Required") + } + if c.CustomTitle == "" { + return false, errors.New("custom_title Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// BanChatSenderChat Use this method to ban a channel chat in a supergroup or a channel. +// Until the chat is unbanned, +// the owner of the banned chat won't be able to send messages on behalf of any of their channels. +// The bot must be an administrator in the supergroup or channel for this to work +// and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) BanChatSenderChat(c *types.BanChatSenderChat) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.SenderChatID == 0 { + return false, errors.New("sender_chatID Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnbanChatSenderChat Use this method to unban a previously banned channel chat in a supergroup or channel. +// The bot must be an administrator for this to work and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) UnbanChatSenderChat(c *types.UnbanChatSenderChat) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.SenderChatID == 0 { + return false, errors.New("sender_chatID Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetChatPermissions Use this method to set default chat permissions for all members. +// The bot must be an administrator in the group or a supergroup +// for this to work and must have the can_restrict_members administrator rights. +// Returns True to success. +func (t *Api) SetChatPermissions(c *types.SetChatPermissions) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// ExportChatInviteLink Use this method to generate a new primary invite link for a chat; +// any previously generated primary link is revoked. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns the new invite link as String on success. +func (t *Api) ExportChatInviteLink(c *types.ExportChatInviteLink) (string, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return "", errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return "", err + } + + var inviteLink string + err = json.Unmarshal(resp.Result, &inviteLink) + + return inviteLink, err +} + +// CreateChatInviteLink Use this method to create an additional invite link for a chat. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// The link can be revoked using the method revokeChatInviteLink. +// Returns the new invite link as ChatInviteLink object. +func (t *Api) CreateChatInviteLink(c *types.CreateChatInviteLink) (*types.ChatInviteLink, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var chatInviteLink types.ChatInviteLink + err = json.Unmarshal(resp.Result, &chatInviteLink) + + return &chatInviteLink, err +} + +// EditChatInviteLink Use this method to edit a non-primary invite link created by the bot. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns the edited invite link as a ChatInviteLink object. +func (t *Api) EditChatInviteLink(c *types.EditChatInviteLink) (*types.ChatInviteLink, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.InviteLink == "" { + return nil, errors.New("invite_link Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var chatInviteLink types.ChatInviteLink + err = json.Unmarshal(resp.Result, &chatInviteLink) + + return &chatInviteLink, err +} + +// RevokeChatInviteLink Use this method to revoke an invitation link created by the bot. +// If the primary link is revoked, a new link is automatically generated. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns the revoked invite link as ChatInviteLink object. +func (t *Api) RevokeChatInviteLink(c *types.RevokeChatInviteLink) (*types.ChatInviteLink, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.InviteLink == "" { + return nil, errors.New("invite_link Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var chatInviteLink types.ChatInviteLink + err = json.Unmarshal(resp.Result, &chatInviteLink) + + return &chatInviteLink, err +} + +// ApproveChatJoinRequest Use this method to approve a chat join request. +// The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. +// Returns True to success. +func (t *Api) ApproveChatJoinRequest(c *types.ApproveChatJoinRequest) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("user_id Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeclineChatJoinRequest Use this method to decline a chat join request. +// The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. +// Returns True to success. +func (t *Api) DeclineChatJoinRequest(c *types.DeclineChatJoinRequest) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return false, errors.New("user_id Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetChatPhoto Use this method to set a new profile photo for the chat. +// Photos can't be changed for private chats. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) SetChatPhoto(c *types.SetChatPhoto) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.Photo == nil { + return false, errors.New("photo Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteChatPhoto Use this method to delete a chat photo. +// Photos can't be changed for private chats. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) DeleteChatPhoto(c *types.DeleteChatPhoto) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetChatTitle Use this method to change the title of a chat. +// Titles can't be changed for private chats. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) SetChatTitle(c *types.SetChatTitle) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.Title == "" { + return false, errors.New("title Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetChatDescription Use this method to change the description of a group, a supergroup or a channel. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +func (t *Api) SetChatDescription(c *types.SetChatDescription) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// PinChatMessage Use this method to add a message to the list of pinned messages in a chat. +// If the chat is not a private chat, +// the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' +// administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. +// Returns True to success. +func (t *Api) PinChatMessage(c *types.PinChatMessage) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnpinChatMessage Use this method to remove a message from the list of pinned messages in a chat. +// If the chat is not a private chat, +// the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' +// administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. +// Returns True to success. +func (t *Api) UnpinChatMessage(c *types.UnpinChatMessage) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnpinAllChatMessages Use this method to clear the list of pinned messages in a chat. +// If the chat is not a private chat, +// the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' +// administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. +// Returns True to success. +func (t *Api) UnpinAllChatMessages(c *types.UnpinAllChatMessages) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// LeaveChat Use this method for your bot to leave a group, supergroup or channel. Returns True to success. +func (t *Api) LeaveChat(c *types.LeaveChat) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetChat Use this method to get up-to-date information about the chat +// (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). +// Returns a Chat object on success. +func (t *Api) GetChat(c *types.GetChat) (*types.ChatFullInfo, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var chat types.ChatFullInfo + err = json.Unmarshal(resp.Result, &chat) + + if err == nil { + chat.IDString = fmt.Sprintf("%d", chat.ID) + } + + return &chat, err +} + +// GetChatAdministrators Use this method to get a list of administrators in a chat. +// On success, +// returns an Array of ChatMember objects that contains information about all chat administrators except other bots. +// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. +func (t *Api) GetChatAdministrators(c *types.GetChatAdministrators) ([]types.ChatMember, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var members []types.ChatMember + err = json.Unmarshal(resp.Result, &members) + + return members, err +} + +// GetChatMemberCount Use this method to get the number of members in a chat. Returns Int to success. +func (t *Api) GetChatMemberCount(c *types.GetChatMemberCount) (int64, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return 0, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return 0, err + } + + var count int64 + err = json.Unmarshal(resp.Result, &count) + + return count, err +} + +// GetChatMember Use this method to get information about a member of a chat. Returns a ChatMember object on success. +func (t *Api) GetChatMember(c *types.GetChatMember) (*types.ChatMember, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return nil, errors.New("UserID Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var member types.ChatMember + err = json.Unmarshal(resp.Result, &member) + + return &member, err +} + +// SetChatStickerSet Use this method to set a new group sticker set for a supergroup. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. +// Returns True to success. +func (t *Api) SetChatStickerSet(c *types.SetChatStickerSet) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.StickerSetName == "" { + return false, errors.New("StickerSetName Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteChatStickerSet Use this method to delete a group sticker set from a supergroup. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. +// Returns True to success. +func (t *Api) DeleteChatStickerSet(c *types.DeleteChatStickerSet) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetForumTopicIconStickers Use this method to get custom emoji stickers, +// which can be used as a forum topic icon by any user. +// Requires no parameters. +// Returns an Array of Sticker objects. +func (t *Api) GetForumTopicIconStickers(c *types.GetForumTopicIconStickers) ([]types.Sticker, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var result []types.Sticker + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return nil, err + } + + return result, err +} + +// CreateForumTopic Use this method to create a topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// Returns information about the created topic as a ForumTopic object. +func (t *Api) CreateForumTopic(c *types.CreateForumTopic) (*types.ForumTopic, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + + if c.Name == "" { + return nil, errors.New("name is Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var result types.ForumTopic + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return nil, err + } + + return &result, err +} + +// EditForumTopic Use this method to edit the name and icon of a topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, +// unless it is the creator of the topic. +// Returns True to success. +func (t *Api) EditForumTopic(c *types.EditForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + if c.MessageThreadID == 0 { + return false, errors.New("message_thread_id is Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// CloseForumTopic Use this method to close an open topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights, +// unless it is the creator of the topic. +// Returns True to success. +func (t *Api) CloseForumTopic(c *types.CloseForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + if c.MessageThreadID == 0 { + return false, errors.New("message_thread_id is Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// ReopenForumTopic Use this method to reopen a closed topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights, +// unless it is the creator of the topic. +// Returns True to success. +func (t *Api) ReopenForumTopic(c *types.ReopenForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + if c.MessageThreadID == 0 { + return false, errors.New("message_thread_id is Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteForumTopic Use this method to delete a forum topic along with all its messages in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_delete_messages administrator rights. +// Returns True to success. +func (t *Api) DeleteForumTopic(c *types.DeleteForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + if c.MessageThreadID == 0 { + return false, errors.New("message_thread_id is Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnpinAllForumTopicMessages Use this method to clear the list of pinned messages in a forum topic. +// The bot must be an administrator in the chat for this to work and must have +// the can_pin_messages administrator right in the supergroup. +// Returns True to +// success. +func (t *Api) UnpinAllForumTopicMessages(c *types.UnpinAllForumTopicMessages) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + if c.MessageThreadID == 0 { + return false, errors.New("message_thread_id is Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// EditGeneralForumTopic Use this method to edit the name of the 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. +// Returns True to success. +func (t *Api) EditGeneralForumTopic(c *types.EditGeneralForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + if c.Name == "" { + return false, errors.New("name is Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// CloseGeneralForumTopic Use this method to close an open 'General' topic in a +// forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// Returns True to success. +func (t *Api) CloseGeneralForumTopic(c *types.CloseGeneralForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// ReopenGeneralForumTopic Use this method to reopen a closed 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// The topic will be automatically unhidden if it was hidden. +// Returns True to success. +func (t *Api) ReopenGeneralForumTopic(c *types.ReopenGeneralForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// HideGeneralForumTopic Use this method to hide the 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// The topic will be automatically closed if it is open. +// Returns True to success. +func (t *Api) HideGeneralForumTopic(c *types.HideGeneralForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnHideGeneralForumTopic Use this method to unhide the 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// Returns True to success. +func (t *Api) UnHideGeneralForumTopic(c *types.UnHideGeneralForumTopic) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// UnpinAllGeneralForumTopicMessages Use this method to clear the list of pinned messages in a General forum topic. +// The bot must be an administrator in the chat for this to work +// and must have the can_pin_messages administrator right in the supergroup. +// Returns True to success. +func (t *Api) UnpinAllGeneralForumTopicMessages(c *types.UnpinAllGeneralForumTopicMessages) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// AnswerCallbackQuery Use this method to send answers to callback queries sent from inline keyboards. +// The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. +// On success, True is returned. +// Alternatively, the user can be redirected to the specified Game URL. +// For this option to work, you must first create a game for your bot via @BotFather and accept the terms. +// Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter. +func (t *Api) AnswerCallbackQuery(c *types.AnswerCallbackQuery) (bool, error) { + if c.CallbackQueryID == "" { + return false, errors.New("CallbackQueryID Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetUserChatBoosts Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object. +func (t *Api) GetUserChatBoosts(c *types.GetUserChatBoosts) (*types.UserChatBoosts, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.UserID == 0 { + return nil, errors.New("UserID Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var chatBoosts types.UserChatBoosts + err = json.Unmarshal(resp.Result, &chatBoosts) + + return &chatBoosts, err +} + +// GetBusinessConnection Use this method to get information about the connection of the bot with a business account. +// Returns a BusinessConnection object on success. +func (t *Api) GetBusinessConnection(c *types.GetBusinessConnection) (*types.BusinessConnection, error) { + if c.BusinessConnectionId == "" { + return nil, errors.New("BusinessConnectionId Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var businessConnection types.BusinessConnection + err = json.Unmarshal(resp.Result, &businessConnection) + + return &businessConnection, err +} + +// SetMyCommands Use this method to change the list of the bot commands. +// See https://core.telegram.org/bots#commands for more details about bot commands. +// Returns True to success. +func (t *Api) SetMyCommands(c *types.SetMyCommands) (bool, error) { + if c.Commands == nil { + return false, errors.New("commands Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteMyCommands Use this method to change the list of the bot commands. +// See https://core.telegram.org/bots#commands for more details about bot commands. +// Returns True to success. +func (t *Api) DeleteMyCommands(c *types.DeleteMyCommands) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetMyCommands Use this method to get the current list of the bot commands for the given scope and user language. +// Returns Array of BotCommand on success. +// If commands aren't set, an empty list is returned. +func (t *Api) GetMyCommands(c *types.GetMyCommands) ([]types.BotCommand, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var commands []types.BotCommand + err = json.Unmarshal(resp.Result, &commands) + + return commands, err +} + +// SetMyName Use this method to change the bot name. +// Returns True to success. +func (t *Api) SetMyName(c *types.SetMyName) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + + return result, err +} + +// GetMyName Use this method to get the current bot name for the given user language. Returns BotName on success. +func (t *Api) GetMyName(c *types.GetMyName) (*types.BotName, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var result types.BotName + err = json.Unmarshal(resp.Result, &result) + + return &result, err +} + +// SetMyDescription Use this method to change the bot description, +// which is shown in the chat with the bot if the chat is empty. +// Returns True to success. +func (t *Api) SetMyDescription(c *types.SetMyDescription) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetMyDescription Use this method to get the current bot description for the given user language. +// Returns BotDescription on success. +func (t *Api) GetMyDescription(c *types.GetMyDescription) (*types.BotDescription, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var result types.BotDescription + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return nil, err + } + + return &result, err +} + +// SetMyShortDescription Use this method to change the bot short description, +// which is shown on the bot profile page and is sent together with the link when users share the bot. +// Returns True to success. +func (t *Api) SetMyShortDescription(c *types.SetMyShortDescription) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetMyShortDescription Use this method to get the current bot short description for the given user language. +// Returns BotShortDescription on success. +func (t *Api) GetMyShortDescription(c *types.GetMyShortDescription) (*types.BotShortDescription, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var result types.BotShortDescription + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return nil, err + } + + return &result, err +} + +// SetChatMenuButton Use this method to change the bot menu button in a private chat, or the default menu button. +// Returns True to success. +func (t *Api) SetChatMenuButton(c *types.SetChatMenuButton) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetChatMenuButton Use this method to get the current value of the bot menu button in a private chat, +// or the default menu button. +// Returns MenuButton on success. +func (t *Api) GetChatMenuButton(c *types.GetChatMenuButton) (*types.MenuButtons, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var menuButton types.MenuButtons + err = json.Unmarshal(resp.Result, &menuButton) + + return &menuButton, err +} + +// SetMyDefaultAdministratorRights Use this method to change the default administrator rights requested by the bot +// when it's added as an administrator to groups or channels. +// These rights will be suggested to users, but they are free to modify the list before adding the bot. +// Returns True to success. +func (t *Api) SetMyDefaultAdministratorRights(c *types.SetMyDefaultAdministratorRights) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetMyDefaultAdministratorRights Use this method to get the current default administrator rights of the bot. +// Returns ChatAdministratorRights on success. +func (t *Api) GetMyDefaultAdministratorRights(c *types.GetMyDefaultAdministratorRights) (bool, error) { + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// EditMessageText Use this method to edit text and game messages. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +func (t *Api) EditMessageText(c *types.EditMessageText) (*types.Message, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + + if c.Text == "" { + return nil, errors.New("text Required") + } + + return t.Send(c) +} + +// EditInlineMessageText Use this method to edit text and game messages. +// On success, True is returned. +func (t *Api) EditInlineMessageText(c *types.EditMessageText) (bool, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + } + + if c.Text == "" { + return false, errors.New("text Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// EditMessageCaption Use this method to edit captions of messages. +// On success, the edited Message is returned. +func (t *Api) EditMessageCaption(c *types.EditMessageCaption) (*types.Message, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + + return t.Send(c) +} + +// EditInlineMessageCaption Use this method to edit captions of messages. +// On success, the edited Message is returned. +func (t *Api) EditInlineMessageCaption(c *types.EditMessageCaption) (bool, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// EditMessageMedia Use this method to edit animation, audio, document, photo, or video messages. +// If a message is part of a message album, then it can be edited only to an audio for audio albums, +// only to a document for document albums and to a photo or a video otherwise. +// When an inline message is edited, a new file can't be uploaded; +// use a previously uploaded file via its file_id or specify a URL. +// On success, the edited Message is returned. +func (t *Api) EditMessageMedia(c *types.EditMessageMedia) (*types.Message, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + if c.Media == nil { + return nil, errors.New("media Required") + } + + return t.Send(c) +} + +// EditInlineMessageMedia Use this method to edit animation, audio, document, photo, or video messages. +// If a message is part of a message album, then it can be edited only to an audio for audio albums, +// only to a document for document albums and to a photo or a video otherwise. +// When an inline message is edited, a new file can't be uploaded; +// use a previously uploaded file via its file_id or specify a URL. +// On success, True is returned. +func (t *Api) EditInlineMessageMedia(c *types.EditMessageMedia) (bool, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + } + if c.Media == nil { + return false, errors.New("media Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// EditMessageReplyMarkup Use this method to edit only the reply markup of messages. +// On success, the edited Message is returned. +func (t *Api) EditMessageReplyMarkup(c *types.EditMessageReplyMarkup) (*types.Message, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + + return t.Send(c) +} + +// EditInlineMessageReplyMarkup Use this method to edit only the reply markup of messages. +// On success, True is returned. +func (t *Api) EditInlineMessageReplyMarkup(c *types.EditMessageReplyMarkup) (bool, error) { + if c.InlineMessageID == "" { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// StopPoll Use this method to stop a poll which was sent by the bot. +// On success, the stopped Poll is returned. +func (t *Api) StopPoll(c *types.StopPoll) (*types.Poll, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var poll types.Poll + err = json.Unmarshal(resp.Result, &poll) + + return &poll, err +} + +// DeleteMessage Use this method to delete a message, including service messages, with the following limitations: +// - A message can only be deleted if it was sent less than 48 hours ago. +// - A die message in a private chat can only be deleted if it was sent more than 24 hours ago. +// - Bots can delete outgoing messages in private chats, groups, and supergroups. +// - Bots can delete incoming messages in private chats. +// - Bots granted can_post_messages permissions can delete outgoing messages in channels. +// - If the bot is an administrator of a group, it can delete any message there. +// - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. +// Returns True to success. +func (t *Api) DeleteMessage(c *types.DeleteMessage) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageID == 0 { + return false, errors.New("MessageID Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteMessages Use this method to delete multiple messages simultaneously. +// If some of the specified messages can't be found, they are skipped. +// Returns True on success. +func (t *Api) DeleteMessages(c *types.DeleteMessages) (bool, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return false, errors.New("ChatID or Username Required") + } + if c.MessageIds == nil { + return false, errors.New("MessageIds Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SendSticker Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. +// On success, the sent Message is returned. +func (t *Api) SendSticker(c *types.SendSticker) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Sticker == nil { + return nil, errors.New("MessageID Required") + } + + return t.Send(c) +} + +// GetStickerSet Use this method to get a sticker set. On success, a StickerSet object is returned. +func (t *Api) GetStickerSet(c *types.GetStickerSet) (*types.StickerSet, error) { + if c.Name == "" { + return nil, errors.New("name Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var stickerSet types.StickerSet + err = json.Unmarshal(resp.Result, &stickerSet) + + return &stickerSet, err +} + +// GetCustomEmojiStickers Use this method to get information about custom emoji stickers by their identifiers. +// Returns an Array of Sticker objects. +func (t *Api) GetCustomEmojiStickers(c *types.GetCustomEmojiStickers) ([]types.Sticker, error) { + if len(c.CustomEmojiIds) < 1 { + return nil, errors.New("customEmojiIds Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var stickerSet []types.Sticker + err = json.Unmarshal(resp.Result, &stickerSet) + + return stickerSet, err +} + +// UploadStickerFile Use this method to upload a file with a sticker for later use in the createNewStickerSet +// and addStickerToSet methods (the file can be used multiple times). +// Returns the uploaded File on success. +func (t *Api) UploadStickerFile(c *types.UploadStickerFile) (*types.File, error) { + if c.UserID == 0 { + return nil, errors.New("UserID Required") + } + if c.Sticker == nil { + return nil, errors.New("sticker Required") + } + if c.StickerFormat == "" { + return nil, errors.New("stickerFormat Required") + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var file types.File + err = json.Unmarshal(resp.Result, &file) + + return &file, err +} + +// CreateNewStickerSet Use this method to create a new sticker set owned by a user. +// The bot will be able to edit the sticker set thus created. +// Returns True to success. +func (t *Api) CreateNewStickerSet(c *types.CreateNewStickerSet) (bool, error) { + if c.UserID == 0 { + return false, errors.New("UserID Required") + } + if c.Name == "" { + return false, errors.New("name Required") + } + if c.Title == "" { + return false, errors.New("title Required") + } + if len(c.Stickers) < 1 { + return false, errors.New("stickers Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// AddStickerToSet Use this method to add a new sticker to a set created by the bot. +// The format of the added sticker must match the format of the other stickers in the set. +// Emoji sticker sets can have up to 200 stickers. +// Animated and video sticker sets can have up to 50 stickers. +// Static sticker sets can have up to 120 stickers. +// Returns True to success. +func (t *Api) AddStickerToSet(c *types.AddStickerToSet) (bool, error) { + if c.UserID == 0 { + return false, errors.New("UserID Required") + } + if c.Name == "" { + return false, errors.New("name Required") + } + if c.Sticker.Sticker == nil { + return false, errors.New("sticker Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetStickerPositionInSet Use this method to move a sticker in a set created by the bot to a specific position. +// Returns True to success. +func (t *Api) SetStickerPositionInSet(c *types.SetStickerPositionInSet) (bool, error) { + if c.Sticker == "" { + return false, errors.New("sticker Required") + } + if c.Position == 0 { + return false, errors.New("position Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteStickerFromSet Use this method to delete a sticker from a set created by the bot. +// Returns True to success. +func (t *Api) DeleteStickerFromSet(c *types.DeleteStickerFromSet) (bool, error) { + if c.Sticker == "" { + return false, errors.New("sticker Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// ReplaceStickerInSet Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. +// Returns True on success +func (t *Api) ReplaceStickerInSet(c *types.ReplaceStickerInSet) (bool, error) { + if c.UserID == 0 { + return false, errors.New("UserID Required") + } + if c.Name == "" { + return false, errors.New("name Required") + } + if c.OldSticker == "" { + return false, errors.New("OldSticker Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetStickerEmojiList Use this method to change the list of emoji assigned to a regular or custom emoji sticker. +// The sticker must belong to a sticker set created by the bot. +// Returns True to success. +func (t *Api) SetStickerEmojiList(c *types.SetStickerEmojiList) (bool, error) { + if c.Sticker == "" { + return false, errors.New("sticker Required") + } + if len(c.EmojiList) < 1 { + return false, errors.New("emojiList Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetStickerKeywords Use this method to change search keywords assigned to a regular or custom emoji sticker. +// The sticker must belong to a sticker set created by the bot. +// Returns True to success. +func (t *Api) SetStickerKeywords(c *types.SetStickerKeywords) (bool, error) { + if c.Sticker == "" { + return false, errors.New("sticker Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetStickerMaskPosition Use this method to change the mask position of a mask sticker. +// The sticker must belong to a sticker set that was created by the bot. +// Returns True to success. +func (t *Api) SetStickerMaskPosition(c *types.SetStickerMaskPosition) (bool, error) { + if c.Sticker == "" { + return false, errors.New("sticker Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetStickerSetTitle Use this method to set the title of a created sticker set. +// Returns True to success. +func (t *Api) SetStickerSetTitle(c *types.SetStickerSetTitle) (bool, error) { + if c.Name == "" { + return false, errors.New("name Required") + } + if c.Title == "" { + return false, errors.New("title Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetStickerSetThumbnail Use this method to set the thumbnail of a regular or mask sticker set. +// The format of the thumbnail file must match the format of the stickers in the set. +// Returns True to success. +func (t *Api) SetStickerSetThumbnail(c *types.SetStickerSetThumbnail) (bool, error) { + if c.Name == "" { + return false, errors.New("name Required") + } + if c.UserID == 0 { + return false, errors.New("userID Required") + } + if c.Format == "" { + return false, errors.New("format Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetCustomEmojiStickerSetThumbnail Use this method to set the thumbnail of a custom emoji sticker set. +// Returns True to success. +func (t *Api) SetCustomEmojiStickerSetThumbnail(c *types.SetCustomEmojiStickerSetThumbnail) (bool, error) { + if c.Name == "" { + return false, errors.New("name Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// DeleteStickerSet Use this method to delete a sticker set that was created by the bot. Returns True to success. +func (t *Api) DeleteStickerSet(c *types.DeleteStickerSet) (bool, error) { + if c.Name == "" { + return false, errors.New("name Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// AnswerInlineQuery Use this method to send answers to an inline query. +// On success, True is returned. +// No more than 50 results per query are allowed. +func (t *Api) AnswerInlineQuery(c *types.AnswerInlineQuery) (bool, error) { + if c.InlineQueryID == "" { + return false, errors.New("InlineQueryID Required") + } + if c.Results == nil { + return false, errors.New("results Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// AnswerWebAppQuery Use this method to set the result of an interaction with a Web App +// and send a corresponding message on behalf of the user to the chat from which the query originated. +// On success, a SentWebAppMessage object is returned. +func (t *Api) AnswerWebAppQuery(c *types.AnswerWebAppQuery) (bool, error) { + if c.WebAppQueryID == "" { + return false, errors.New("WebAppQueryID Required") + } + if c.Result == nil { + return false, errors.New("result Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SendInvoice Use this method to send invoices. On success, the sent Message is returned. +func (t *Api) SendInvoice(c *types.SendInvoice) (*types.Message, error) { + if c.ChatID == 0 && c.ChatIDStr == "" && c.Username == "" { + return nil, errors.New("ChatID or Username Required") + } + if c.Title == "" { + return nil, errors.New("title Required") + } + if c.Description == "" { + return nil, errors.New("description Required") + } + if c.Payload == "" { + return nil, errors.New("payload Required") + } + if c.Currency == "" { + return nil, errors.New("currency Required") + } + if c.Prices == nil { + return nil, errors.New("prices Required") + } + + return t.Send(c) +} + +// CreateInvoiceLink Use this method to create a link for an invoice. Returns the created invoice link as String on success. +func (t *Api) CreateInvoiceLink(c *types.CreateInvoiceLink) (string, error) { + if c.Title == "" { + return "", errors.New("title Required") + } + if c.Description == "" { + return "", errors.New("description Required") + } + if c.Payload == "" { + return "", errors.New("payload Required") + } + if c.Currency == "" { + return "", errors.New("currency Required") + } + if c.Prices == nil { + return "", errors.New("prices Required") + } + + resp, err := t.Request(c) + if err != nil { + return "", err + } + + var createInvoiceLink string + + err = json.Unmarshal(resp.Result, &createInvoiceLink) + if err != nil { + return "", err + } + + return createInvoiceLink, nil +} + +// AnswerShippingQuery If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, +// the Bot API will send an Update with a shipping_query field to the bot. +// Use this method to reply to shipping queries. +// On success, True is returned. +func (t *Api) AnswerShippingQuery(c *types.AnswerShippingQuery) (string, error) { + if c.ShippingQueryID == "" { + return "", errors.New("ShippingQueryID Required") + } + if c.OK { + if c.ShippingOptions == nil { + return "", errors.New("ShippingOptions Required") + } + } else { + if c.ErrorMessage == "" { + return "", errors.New("ErrorMessage Required") + } + } + + resp, err := t.Request(c) + if err != nil { + return "", err + } + + var createInvoiceLink string + + err = json.Unmarshal(resp.Result, &createInvoiceLink) + if err != nil { + return "", err + } + + return createInvoiceLink, nil +} + +// AnswerPreCheckoutQuery If you sent an invoice requesting a shipping address, +// and the parameter is_flexible was specified, +// the Bot API will send an Update with a shipping_query field to the bot. +// Use this method to reply to shipping queries. +// On success, True is returned. +func (t *Api) AnswerPreCheckoutQuery(c *types.AnswerPreCheckoutQuery) (bool, error) { + if c.PreCheckoutQueryID == "" { + return false, errors.New("ShippingQueryID Required") + } + if !c.OK { + if c.ErrorMessage == "" { + return false, errors.New("ErrorMessage Required") + } + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// GetStarTransactions Returns the bot's Telegram Star transactions in chronological order. +// On success, returns a StarTransactions object. +func (t *Api) GetStarTransactions(c *types.GetStarTransactions) (*types.StarTransactions, error) { + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var starTransactions types.StarTransactions + err = json.Unmarshal(resp.Result, &starTransactions) + + return &starTransactions, err +} + +// RefundStarPayment Refunds a successful payment in Telegram Stars. +// Returns True on success. +func (t *Api) RefundStarPayment(c *types.RefundStarPayment) (bool, error) { + if c.UserId == "" { + return false, errors.New("UserId Required") + } + if c.TelegramPaymentChargeId == "" { + return false, errors.New("TelegramPaymentChargeId Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SetPassportDataErrors Informs a user that some of the Telegram Passport elements they provided contains errors. +// The user will not be able to re-submit their Passport to you until the errors are fixed +// (the contents of the field for which you returned the error must change). +// Returns True to success. +// Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. +// For example, if a birthday date seems invalid, a submitted document is blurry; +// a scan shows evidence of tampering, +// etc. Supply some details in the error message to make sure the user knows how to correct the issues. +func (t *Api) SetPassportDataErrors(c *types.SetPassportDataErrors) (bool, error) { + if c.UserID == 0 { + return false, errors.New("UserID Required") + } + if c.Errors == nil { + return false, errors.New("errors Required") + } + + resp, err := t.Request(c) + if err != nil { + return false, err + } + + var result bool + err = json.Unmarshal(resp.Result, &result) + if err != nil { + return false, err + } + + return result, err +} + +// SendGame Use this method to send a game. On success, the sent Message is returned. +func (t *Api) SendGame(c *types.SendGame) (*types.Message, error) { + if c.ChatID == 0 { + return nil, errors.New("ChatID Required") + } + if c.GameShortName == "" { + return nil, errors.New("GameShortName Required") + } + + return t.Send(c) +} + +// SetGameScore Use this method to set the score of the specified user in a game message. +// On success, if the message is not an inline message, the Message is returned, otherwise True is returned. +// Returns an error, if the new score is not greater than the user's current score in the chat and force is False. +func (t *Api) SetGameScore(c *types.SetGameScore) (*types.Message, error) { + if c.UserID == 0 { + return nil, errors.New("UserID Required") + } + if c.Score == 0 { + return nil, errors.New("score Required") + } + if c.InlineMessageID == "" { + if c.ChatID == 0 { + return nil, errors.New("ChatID Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + + return t.Send(c) +} + +// GetGameHighScores Use this method to get data for high-score tables. +// Will return the score of the specified user and several of their neighbors in a game. +// On success, returns an Array of GameHighScore objects. +// This method will currently return scores for the target user, plus two of their closest neighbors on each side. +// Will also return the top three users if the user and their neighbors are not among them. +// Please note that this behavior is subject to change. +func (t *Api) GetGameHighScores(c *types.GetGameHighScores) ([]types.GameHighScore, error) { + if c.UserID == 0 { + return nil, errors.New("UserID Required") + } + if c.InlineMessageID == "" { + if c.ChatID == 0 { + return nil, errors.New("ChatID Required") + } + if c.MessageID == 0 { + return nil, errors.New("MessageID Required") + } + } + + resp, err := t.Request(c) + if err != nil { + return nil, err + } + + var gameHighScore []types.GameHighScore + + err = json.Unmarshal(resp.Result, &gameHighScore) + if err != nil { + return nil, err + } + + return gameHighScore, nil +} diff --git a/telegram/telegram.go b/telegram/telegram.go new file mode 100644 index 0000000..9371acc --- /dev/null +++ b/telegram/telegram.go @@ -0,0 +1,121 @@ +package telegram + +import ( + "encoding/json" + "errors" + "io" + "net/http" + + "github.com/alisapro/telegram-bot-api/client" + "github.com/alisapro/telegram-bot-api/config" + "github.com/alisapro/telegram-bot-api/types" +) + +var Core Api + +type Api struct { + Bot *types.BotApi +} + +// BaseUrl set custom api base url. +func (t *Api) BaseUrl(baseUrl string) { + t.Bot.BaseUrl = baseUrl +} + +// Client make new telegram client. +func Client() *client.Config { + return &client.Config{} +} + +// New make new telegram bot api response. +func New(token string) (*Api, error) { + if token == "" { + return nil, errors.New("bot token missed") + } + + c := Client() + c.BaseUrl = config.DefaultBaseUrl + + err := c.Setup() + if err != nil { + return nil, err + } + + Core.Bot = &types.BotApi{Token: token, BaseUrl: c.BaseUrl, Client: c.HttpC} + return &Core, nil +} + +// NewWithBaseUrl make new telegram bot api response with custom base url. +func NewWithBaseUrl(token, baseUrl string) (*Api, error) { + if token == "" { + return nil, errors.New("bot token missed") + } + if baseUrl == "" { + return nil, errors.New("base url missed") + } + + c := Client() + c.BaseUrl = baseUrl + + err := c.Setup() + if err != nil { + return nil, err + } + + Core.Bot = &types.BotApi{Token: token, BaseUrl: c.BaseUrl, Client: c.HttpC} + return &Core, nil +} + +// NewWithCustomClient make new telegram bot api response with a custom client. +func NewWithCustomClient(token string, c *client.Config) (*Api, error) { + if token == "" { + return nil, errors.New("bot token missed") + } + if c.BaseUrl == "" { + c.BaseUrl = config.DefaultBaseUrl + } + + err := c.Setup() + if err != nil { + return nil, err + } + + Core.Bot = &types.BotApi{Token: token, BaseUrl: c.BaseUrl, Client: c.HttpC} + return &Core, nil +} + +// HandleUpdate parses and return update received via webhook +func HandleUpdate(r *http.Request) (*types.Update, error) { + var update types.Update + + if r.Method != http.MethodPost { + return nil, errors.New("wrong HTTP method required POST") + } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(r.Body) + + err := json.NewDecoder(r.Body).Decode(&update) + if err != nil { + return nil, err + } + + return &update, nil +} + +// HandleUpdateError response writer error to requested server +func HandleUpdateError(w http.ResponseWriter, wErr error) error { + w.WriteHeader(http.StatusBadRequest) + w.Header().Set("Content-Type", "application/json") + errMsg, err := json.Marshal(map[string]string{ + "error": wErr.Error(), + }) + if err != nil { + return err + } + if _, err = w.Write(errMsg); err != nil { + return err + } + + return nil +} diff --git a/telegram/utils.go b/telegram/utils.go new file mode 100644 index 0000000..9511364 --- /dev/null +++ b/telegram/utils.go @@ -0,0 +1,1364 @@ +package telegram + +import ( + "io" + "strings" + + "github.com/alisapro/telegram-bot-api/config" + "github.com/alisapro/telegram-bot-api/types" +) + +// ModeMarkdown return markdown mode +func (t *Api) ModeMarkdown() string { + return config.ModeMarkdown +} + +// ModeMarkdownV2 return markdown2 mode +func (t *Api) ModeMarkdownV2() string { + return config.ModeMarkdownV2 +} + +// ModeHTML return html mode +func (t *Api) ModeHTML() string { + return config.ModeHTML +} + +// EscapeText takes an input text and escapes Telegram markup symbols. +// In this way, we can send a text without being afraid of having to escape the characters manually. +// Note that you don't have to include the formatting style in the input text, or it will be escaped too. +// If there is an error, an empty string will be returned. +func (t *Api) EscapeText(parseMode, text string) string { + var replacer *strings.Replacer + + if parseMode == config.ModeHTML { + replacer = strings.NewReplacer("<", "<", ">", ">", "&", "&") + } else if parseMode == config.ModeMarkdown { + replacer = strings.NewReplacer("_", "\\_", "*", "\\*", "`", "\\`", "[", "\\[") + } else if parseMode == config.ModeMarkdownV2 { + replacer = strings.NewReplacer( + "_", "\\_", "*", "\\*", "[", "\\[", "]", "\\]", "(", + "\\(", ")", "\\)", "~", "\\~", "`", "\\`", ">", "\\>", + "#", "\\#", "+", "\\+", "-", "\\-", "=", "\\=", "|", + "\\|", "{", "\\{", "}", "\\}", ".", "\\.", "!", "\\!", + ) + } else { + return "" + } + + return replacer.Replace(text) +} + +// FileBytes return file bytes style. +func (t *Api) FileBytes(name string, byte []byte) *types.FileBytes { + return &types.FileBytes{ + Name: name, + Bytes: byte, + } +} + +// FileReader return file reader style. +func (t *Api) FileReader(name string, reader io.Reader) *types.FileReader { + return &types.FileReader{ + Name: name, + Reader: reader, + } +} + +// FilePath return file path style. +func (t *Api) FilePath(path string) types.FilePath { + return types.FilePath(path) +} + +// FileURL return file url style. +func (t *Api) FileURL(Url string) types.FileURL { + return types.FileURL(Url) +} + +// FileID return file id style already uploaded to Telegram. +func (t *Api) FileID(ID string) types.FileID { + return types.FileID(ID) +} + +// FileAttach return file attaches style used for processed media groups. +func (t *Api) FileAttach(Attach string) types.FileAttach { + return types.FileAttach(Attach) +} + +// GetFileDirectURL returns direct download URL from file +func (t *Api) GetFileDirectURL(fileID string) (string, error) { + file, err := t.GetFile(&types.GetFile{FileID: fileID}) + if err != nil { + return "", err + } + + return file.Link(t.Bot.Token), nil +} + +// NewLinkPreviewOptions create a new link preview options message. +func (t *Api) NewLinkPreviewOptions() *types.LinkPreviewOptions { + return &types.LinkPreviewOptions{} +} + +// NewReplyParameters a new reply parameters message. +func (t *Api) NewReplyParameters() *types.ReplyParameters { + return &types.ReplyParameters{} +} + +// NewGetUpdates create a new get updates message. +func (t *Api) NewGetUpdates() *types.GetUpdates { + return &types.GetUpdates{} +} + +// NewSetWebhook create a new set webhook message. +func (t *Api) NewSetWebhook() *types.SetWebhook { + return &types.SetWebhook{} +} + +// NewDeleteWebhook create a new delete webhook message. +func (t *Api) NewDeleteWebhook() *types.DeleteWebhook { + return &types.DeleteWebhook{} +} + +// NewReplyKeyboardMarkup creates a new regular keyboard with correct defaults. +func (t *Api) NewReplyKeyboardMarkup(rows ...[]types.KeyboardButton) types.ReplyKeyboardMarkup { + var keyboard [][]types.KeyboardButton + + keyboard = append(keyboard, rows...) + + return types.ReplyKeyboardMarkup{ + ResizeKeyboard: true, + Keyboard: keyboard, + } +} + +// NewKeyboardButton creates a regular keyboard button. +func (t *Api) NewKeyboardButton(text string) types.KeyboardButton { + return types.KeyboardButton{ + Text: text, + } +} + +// NewKeyboardButtonContact creates a keyboard button that requests. user contact information upon click. +func (t *Api) NewKeyboardButtonContact(text string) types.KeyboardButton { + return types.KeyboardButton{ + Text: text, + RequestContact: true, + } +} + +// NewKeyboardButtonLocation creates a keyboard button that requests. user location information upon click. +func (t *Api) NewKeyboardButtonLocation(text string) types.KeyboardButton { + return types.KeyboardButton{ + Text: text, + RequestLocation: true, + } +} + +// NewKeyboardButtonPool creates a keyboard button that requests. +// For pool, if `quiz` is passed, the user will be allowed to create only polls in the quiz mode. +// If `regular` is passed, only regular polls will be allowed. +func (t *Api) NewKeyboardButtonPool(text, pool string) types.KeyboardButton { + return types.KeyboardButton{ + Text: text, + RequestPoll: &types.KeyboardButtonPollType{ + Type: pool, + }, + } +} + +// NewKeyboardButtonWebApp creates a keyboard button that requests. WebApp information upon click. +func (t *Api) NewKeyboardButtonWebApp(text, Url string) types.KeyboardButton { + return types.KeyboardButton{ + Text: text, + WebApp: &types.WebAppInfo{ + URL: Url, + }, + } +} + +// NewKeyboardButtonRow creates a row of keyboard buttons. +func (t *Api) NewKeyboardButtonRow(buttons ...types.KeyboardButton) []types.KeyboardButton { + var row []types.KeyboardButton + + row = append(row, buttons...) + + return row +} + +// NewReplyKeyboardRemove hides the keyboard, with the option for being selective or hiding for everyone. +func (t *Api) NewReplyKeyboardRemove(selective bool) types.ReplyKeyboardRemove { + return types.ReplyKeyboardRemove{ + RemoveKeyboard: true, + Selective: selective, + } +} + +// NewForceReply creates a new force reply. +func (t *Api) NewForceReply(inputFieldPlaceholder string, selective bool) types.ForceReply { + return types.ForceReply{ + ForceReply: true, + InputFieldPlaceholder: inputFieldPlaceholder, + Selective: selective, + } +} + +// NewInlineKeyboardMarkup creates a new inline keyboard. +func (t *Api) NewInlineKeyboardMarkup(rows ...[]types.InlineKeyboardButton) types.InlineKeyboardMarkup { + var keyboard [][]types.InlineKeyboardButton + + keyboard = append(keyboard, rows...) + + return types.InlineKeyboardMarkup{ + InlineKeyboard: keyboard, + } +} + +// NewInlineKeyboardButtonURL creates an inline keyboard url button with text +func (t *Api) NewInlineKeyboardButtonURL(text, url string) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + URL: url, + } +} + +// NewInlineKeyboardCallbackData creates an inline keyboard callback data button with text +func (t *Api) NewInlineKeyboardCallbackData(text, data string) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + CallbackData: data, + } +} + +// NewInlineKeyboardWebApp creates an inline keyboard webapp button with text +func (t *Api) NewInlineKeyboardWebApp(text, url string) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + WebApp: &types.WebAppInfo{ + URL: url, + }, + } +} + +// NewInlineKeyboardButtonLoginURL creates an inline keyboard login url button with text +func (t *Api) NewInlineKeyboardButtonLoginURL(text string, loginURL types.LoginURL) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + LoginURL: &loginURL, + } +} + +// NewInlineKeyboardButtonSwitch creates an inline keyboard switch inline query button with text +func (t *Api) NewInlineKeyboardButtonSwitch(text, switchInline string) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + SwitchInlineQuery: &switchInline, + } +} + +// NewInlineKeyboardButtonSwitchCurrentChat creates an inline keyboard switch inline query bot chat button with text +func (t *Api) NewInlineKeyboardButtonSwitchCurrentChat(text, switchInline string) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + SwitchInlineQueryCurrentChat: &switchInline, + } +} + +// NewInlineKeyboardButtonSwitchChosenChat creates an inline keyboard switch inline query chosen chat-bot chat button with text +func (t *Api) NewInlineKeyboardButtonSwitchChosenChat(text string, switchInline *types.SwitchInlineQueryChosenChat) types.InlineKeyboardButton { + return types.InlineKeyboardButton{ + Text: text, + SwitchInlineQueryChosenChat: switchInline, + } +} + +// NewInlineKeyboardRow creates an inline keyboard row with buttons. +func (t *Api) NewInlineKeyboardRow(buttons ...types.InlineKeyboardButton) []types.InlineKeyboardButton { + var row []types.InlineKeyboardButton + + row = append(row, buttons...) + + return row +} + +// NewSendMessage create a new sent message. +func (t *Api) NewSendMessage() *types.SendMessage { + return &types.SendMessage{} +} + +// NewForwardMessage create a new forward message. +func (t *Api) NewForwardMessage() *types.ForwardMessage { + return &types.ForwardMessage{} +} + +// NewForwardMessages create a new forward messages. +func (t *Api) NewForwardMessages() *types.ForwardMessages { + return &types.ForwardMessages{} +} + +// NewCopyMessage create a new copy message. +func (t *Api) NewCopyMessage() *types.CopyMessage { + return &types.CopyMessage{} +} + +// NewCopyMessages create a new copy messages. +func (t *Api) NewCopyMessages() *types.CopyMessages { + return &types.CopyMessages{} +} + +// NewSendPhoto create a new photo message. +func (t *Api) NewSendPhoto() *types.SendPhoto { + return &types.SendPhoto{} +} + +// NewSendAudio create a new audio message. +func (t *Api) NewSendAudio() *types.SendAudio { + return &types.SendAudio{} +} + +// NewSendDocument create a new document message. +func (t *Api) NewSendDocument() *types.SendDocument { + return &types.SendDocument{} +} + +// NewSendVideo create a new video message. +func (t *Api) NewSendVideo() *types.SendVideo { + return &types.SendVideo{} +} + +// NewSendAnimation create a new animation message. +func (t *Api) NewSendAnimation() *types.SendAnimation { + return &types.SendAnimation{} +} + +// NewSendVoice create a new voice message. +func (t *Api) NewSendVoice() *types.SendVoice { + return &types.SendVoice{} +} + +// NewSendVideoNote create a new videoNote message. +func (t *Api) NewSendVideoNote() *types.SendVideoNote { + return &types.SendVideoNote{} +} + +// NewSendPaidMedia create a new paidMedia message. +func (t *Api) NewSendPaidMedia() *types.SendPaidMedia { + return &types.SendPaidMedia{} +} + +// NewSendMediaGroup create a new mediaGroup message. +func (t *Api) NewSendMediaGroup() *types.SendMediaGroup { + return &types.SendMediaGroup{} +} + +// NewInputMediaPhoto creates a new inputMediaPhoto. +func (t *Api) NewInputMediaPhoto() types.InputMediaPhoto { + return types.InputMediaPhoto{Type: "photo"} +} + +// NewInputMediaVideo creates a new inputMediaVideo. +func (t *Api) NewInputMediaVideo() types.InputMediaVideo { + return types.InputMediaVideo{Type: "video"} +} + +// NewInputMediaAnimation creates a new inputMediaAnimation. +func (t *Api) NewInputMediaAnimation() types.InputMediaAnimation { + return types.InputMediaAnimation{Type: "animation"} +} + +// NewInputMediaAudio creates a new inputMediaAudio. +func (t *Api) NewInputMediaAudio() types.InputMediaAudio { + return types.InputMediaAudio{Type: "audio"} +} + +// NewInputMediaDocument creates a new inputMediaDocument. +func (t *Api) NewInputMediaDocument() types.InputMediaDocument { + return types.InputMediaDocument{Type: "document"} +} + +// NewInputPaidMediaPhoto creates a new inputPaidMediaPhoto. +func (t *Api) NewInputPaidMediaPhoto() types.InputPaidMediaPhoto { + return types.InputPaidMediaPhoto{Type: "photo"} +} + +// NewInputPaidMediaVideo creates a new inputPaidMediaVideo. +func (t *Api) NewInputPaidMediaVideo() types.InputPaidMediaVideo { + return types.InputPaidMediaVideo{Type: "video"} +} + +// NewSendLocation creates a new location message. +func (t *Api) NewSendLocation() *types.SendLocation { + return &types.SendLocation{} +} + +// NewEditMessageLiveLocation creates a new edit message live location message. +func (t *Api) NewEditMessageLiveLocation() *types.EditMessageLiveLocation { + return &types.EditMessageLiveLocation{} +} + +// NewStopMessageLiveLocation creates a new stop message live location message. +func (t *Api) NewStopMessageLiveLocation() *types.StopMessageLiveLocation { + return &types.StopMessageLiveLocation{} +} + +// NewSendVenue creates a new venue message. +func (t *Api) NewSendVenue() *types.SendVenue { + return &types.SendVenue{} +} + +// NewSendContact creates a new contact message. +func (t *Api) NewSendContact() *types.SendContact { + return &types.SendContact{} +} + +// NewSendPoll creates a new poll message. +func (t *Api) NewSendPoll() *types.SendPoll { + return &types.SendPoll{} +} + +// NewSendDice creates a new dice message. +func (t *Api) NewSendDice() *types.SendDice { + return &types.SendDice{} +} + +// NewSendChatAction creates a new chat action message. +func (t *Api) NewSendChatAction() *types.SendChatAction { + return &types.SendChatAction{} +} + +// TypingChatAction return typing chat action +func (t *Api) TypingChatAction() string { + return config.ChatTyping +} + +// UploadPhotoChatAction return upload photo action +func (t *Api) UploadPhotoChatAction() string { + return config.ChatUploadPhoto +} + +// RecordVideoChatAction return record video chat action +func (t *Api) RecordVideoChatAction() string { + return config.ChatRecordVideo +} + +// UploadVideoChatAction return upload video chat action +func (t *Api) UploadVideoChatAction() string { + return config.ChatUploadVideo +} + +// RecordVoiceChatAction return record voice chat action +func (t *Api) RecordVoiceChatAction() string { + return config.ChatRecordVoice +} + +// UploadVoiceChatAction return upload voice chat action +func (t *Api) UploadVoiceChatAction() string { + return config.ChatUploadVoice +} + +// UploadDocumentChatAction return upload document chat action +func (t *Api) UploadDocumentChatAction() string { + return config.ChatUploadDocument +} + +// ChooseStickerChatAction return choose sticker chat action +func (t *Api) ChooseStickerChatAction() string { + return config.ChatChooseSticker +} + +// FindLocationChatAction return find location chat action +func (t *Api) FindLocationChatAction() string { + return config.ChatFindLocation +} + +// RecordVideoNoteChatAction return record video note chat action +func (t *Api) RecordVideoNoteChatAction() string { + return config.ChatRecordVideoNote +} + +// UploadVideoNoteChatAction return upload video note chat action +func (t *Api) UploadVideoNoteChatAction() string { + return config.ChatUploadVideoNote +} + +// NewSetMessageReaction creates a new set message reaction. +func (t *Api) NewSetMessageReaction() *types.SetMessageReaction { + return &types.SetMessageReaction{} +} + +// NewGetUserProfilePhotos creates a new get user profile photos message. +func (t *Api) NewGetUserProfilePhotos() *types.GetUserProfilePhotos { + return &types.GetUserProfilePhotos{} +} + +// NewGetFile creates a new get file message. +func (t *Api) NewGetFile() *types.GetFile { + return &types.GetFile{} +} + +// NewBanChatMember creates a new ban chat member message. +func (t *Api) NewBanChatMember() *types.BanChatMember { + return &types.BanChatMember{} +} + +// NewUnbanChatMember creates a new unban chat member message. +func (t *Api) NewUnbanChatMember() *types.UnbanChatMember { + return &types.UnbanChatMember{} +} + +// NewRestrictChatMember creates a new restrict chat member message. +func (t *Api) NewRestrictChatMember() *types.RestrictChatMember { + return &types.RestrictChatMember{} +} + +// NewChatPermissions creates a new chat permissions message. +func (t *Api) NewChatPermissions() types.ChatPermissions { + return types.ChatPermissions{} +} + +// NewPromoteChatMember creates a new promote chat member message. +func (t *Api) NewPromoteChatMember() *types.PromoteChatMember { + return &types.PromoteChatMember{} +} + +// NewSetChatAdministratorCustomTitle creates a new set chat administrator custom title message. +func (t *Api) NewSetChatAdministratorCustomTitle() *types.SetChatAdministratorCustomTitle { + return &types.SetChatAdministratorCustomTitle{} +} + +// NewBanChatSenderChat creates a new ban chat sender chat message. +func (t *Api) NewBanChatSenderChat() *types.BanChatSenderChat { + return &types.BanChatSenderChat{} +} + +// NewUnbanChatSenderChat creates a new unban chat sender chat message. +func (t *Api) NewUnbanChatSenderChat() *types.UnbanChatSenderChat { + return &types.UnbanChatSenderChat{} +} + +// NewSetChatPermissions creates a new set chat permission message. +func (t *Api) NewSetChatPermissions() *types.SetChatPermissions { + return &types.SetChatPermissions{} +} + +// NewExportChatInviteLink creates a new export chat invite link message. +func (t *Api) NewExportChatInviteLink() *types.ExportChatInviteLink { + return &types.ExportChatInviteLink{} +} + +// NewCreateChatInviteLink creates a new create chat invite link message. +func (t *Api) NewCreateChatInviteLink() *types.CreateChatInviteLink { + return &types.CreateChatInviteLink{} +} + +// NewEditChatInviteLink creates a new edit chat invite link message. +func (t *Api) NewEditChatInviteLink() *types.EditChatInviteLink { + return &types.EditChatInviteLink{} +} + +// NewRevokeChatInviteLink creates a new revoke chat invite link message. +func (t *Api) NewRevokeChatInviteLink() *types.RevokeChatInviteLink { + return &types.RevokeChatInviteLink{} +} + +// NewApproveChatJoinRequest creates a new approval chat join request message. +func (t *Api) NewApproveChatJoinRequest() *types.ApproveChatJoinRequest { + return &types.ApproveChatJoinRequest{} +} + +// NewDeclineChatJoinRequest creates a new decline chat join request message. +func (t *Api) NewDeclineChatJoinRequest() *types.DeclineChatJoinRequest { + return &types.DeclineChatJoinRequest{} +} + +// NewSetChatPhoto creates a new set chat photo message. +func (t *Api) NewSetChatPhoto() *types.SetChatPhoto { + return &types.SetChatPhoto{} +} + +// NewDeleteChatPhoto creates a new delete chat photo message. +func (t *Api) NewDeleteChatPhoto() *types.DeleteChatPhoto { + return &types.DeleteChatPhoto{} +} + +// NewSetChatTitle creates a new set chat title message. +func (t *Api) NewSetChatTitle() *types.SetChatTitle { + return &types.SetChatTitle{} +} + +// NewSetChatDescription creates a new set chat description message. +func (t *Api) NewSetChatDescription() *types.SetChatDescription { + return &types.SetChatDescription{} +} + +// NewPinChatMessage creates a new pin chat message. +func (t *Api) NewPinChatMessage() *types.PinChatMessage { + return &types.PinChatMessage{} +} + +// NewUnpinChatMessage creates a new unpin chat message. +func (t *Api) NewUnpinChatMessage() *types.UnpinChatMessage { + return &types.UnpinChatMessage{} +} + +// NewUnpinAllChatMessages creates a new unpin all chat message. +func (t *Api) NewUnpinAllChatMessages() *types.UnpinAllChatMessages { + return &types.UnpinAllChatMessages{} +} + +// NewLeaveChat creates a new leave chat message. +func (t *Api) NewLeaveChat() *types.LeaveChat { + return &types.LeaveChat{} +} + +// NewGetChat creates a new get chat message. +func (t *Api) NewGetChat() *types.GetChat { + return &types.GetChat{} +} + +// NewGetChatAdministrators creates a new get chat administrators message. +func (t *Api) NewGetChatAdministrators() *types.GetChatAdministrators { + return &types.GetChatAdministrators{} +} + +// NewGetChatMemberCount creates a new get chat member count message. +func (t *Api) NewGetChatMemberCount() *types.GetChatMemberCount { + return &types.GetChatMemberCount{} +} + +// NewGetChatMember creates a new get chat member message. +func (t *Api) NewGetChatMember() *types.GetChatMember { + return &types.GetChatMember{} +} + +// NewSetChatStickerSet creates a new set chat sticker set message. +func (t *Api) NewSetChatStickerSet() *types.SetChatStickerSet { + return &types.SetChatStickerSet{} +} + +// NewDeleteChatStickerSet creates a new delete chat sticker set message. +func (t *Api) NewDeleteChatStickerSet() *types.DeleteChatStickerSet { + return &types.DeleteChatStickerSet{} +} + +// NewCreateForumTopic creates a new create forum topic message. +func (t *Api) NewCreateForumTopic() *types.CreateForumTopic { + return &types.CreateForumTopic{} +} + +// NewEditForumTopic creates a new edit forum topic message. +func (t *Api) NewEditForumTopic() *types.EditForumTopic { + return &types.EditForumTopic{} +} + +// NewCloseForumTopic creates a new close forum topic message. +func (t *Api) NewCloseForumTopic() *types.CloseForumTopic { + return &types.CloseForumTopic{} +} + +// NewReopenForumTopic creates a new reopen forum topic message. +func (t *Api) NewReopenForumTopic() *types.ReopenForumTopic { + return &types.ReopenForumTopic{} +} + +// NewDeleteForumTopic creates a new delete forum topic message. +func (t *Api) NewDeleteForumTopic() *types.DeleteForumTopic { + return &types.DeleteForumTopic{} +} + +// NewUnpinAllForumTopicMessages creates a new unpinned all forum topic messages. +func (t *Api) NewUnpinAllForumTopicMessages() *types.UnpinAllForumTopicMessages { + return &types.UnpinAllForumTopicMessages{} +} + +// NewEditGeneralForumTopic creates a new edit general forum topic message. +func (t *Api) NewEditGeneralForumTopic() *types.EditGeneralForumTopic { + return &types.EditGeneralForumTopic{} +} + +// NewCloseGeneralForumTopic creates a new close general forum topic message. +func (t *Api) NewCloseGeneralForumTopic() *types.CloseGeneralForumTopic { + return &types.CloseGeneralForumTopic{} +} + +// NewUnHideGeneralForumTopic creates a new unHide general forum topic. +func (t *Api) NewUnHideGeneralForumTopic() *types.UnHideGeneralForumTopic { + return &types.UnHideGeneralForumTopic{} +} + +// NewUnpinAllGeneralForumTopicMessages creates a new unpin all general forum topic messages. +func (t *Api) NewUnpinAllGeneralForumTopicMessages() *types.UnpinAllGeneralForumTopicMessages { + return &types.UnpinAllGeneralForumTopicMessages{} +} + +// NewHideGeneralForumTopic creates a new hide general forum topic. +func (t *Api) NewHideGeneralForumTopic() *types.HideGeneralForumTopic { + return &types.HideGeneralForumTopic{} +} + +// NewReopenGeneralForumTopic creates a new reopened general forum topic message. +func (t *Api) NewReopenGeneralForumTopic() *types.ReopenGeneralForumTopic { + return &types.ReopenGeneralForumTopic{} +} + +// NewGetForumTopicIconStickers creates a new get forum topic icon stickers. +func (t *Api) NewGetForumTopicIconStickers() *types.GetForumTopicIconStickers { + return &types.GetForumTopicIconStickers{} +} + +// NewAnswerCallbackQuery creates a new answer callback query message. +func (t *Api) NewAnswerCallbackQuery() *types.AnswerCallbackQuery { + return &types.AnswerCallbackQuery{} +} + +// NewGetUserChatBoosts creates a new get user chat boosts. +func (t *Api) NewGetUserChatBoosts() *types.GetUserChatBoosts { + return &types.GetUserChatBoosts{} +} + +// NewGetBusinessConnection creates a new get business connection. +func (t *Api) NewGetBusinessConnection() *types.GetBusinessConnection { + return &types.GetBusinessConnection{} +} + +// NewSetMyCommands creates a new set my commands message. +func (t *Api) NewSetMyCommands(commands ...types.BotCommand) *types.SetMyCommands { + return &types.SetMyCommands{Commands: commands} +} + +// NewSetMyCommandsWithScope creates a set my commands with a scope message. +func (t *Api) NewSetMyCommandsWithScope(scope *types.BotCommandScope, commands ...types.BotCommand) *types.SetMyCommands { + return &types.SetMyCommands{Commands: commands, Scope: scope} +} + +// NewSetMyCommandsWithScopeAndLanguage creates a set my commands with scope and language message. +func (t *Api) NewSetMyCommandsWithScopeAndLanguage(scope *types.BotCommandScope, languageCode string, commands ...types.BotCommand) *types.SetMyCommands { + return &types.SetMyCommands{Commands: commands, Scope: scope, LanguageCode: languageCode} +} + +// NewGetMyCommandsWithScope creates a get my commands with a scope message. +func (t *Api) NewGetMyCommandsWithScope(scope *types.BotCommandScope) *types.GetMyCommands { + return &types.GetMyCommands{Scope: scope} +} + +// NewGetMyCommandsWithScopeAndLanguage creates a get my commands with scope and language message. +func (t *Api) NewGetMyCommandsWithScopeAndLanguage(scope *types.BotCommandScope, languageCode string) *types.GetMyCommands { + return &types.GetMyCommands{Scope: scope, LanguageCode: languageCode} +} + +// NewDeleteMyCommands creates a new deleted my commands message. +func (t *Api) NewDeleteMyCommands() *types.DeleteMyCommands { + return &types.DeleteMyCommands{} +} + +// NewDeleteMyCommandsWithScope creates a new delete my commands with a scope message. +func (t *Api) NewDeleteMyCommandsWithScope(scope *types.BotCommandScope) *types.DeleteMyCommands { + return &types.DeleteMyCommands{Scope: scope} +} + +// NewDeleteMyCommandsWithScopeAndLanguage creates a new delete my commands with a scope and language message. +func (t *Api) NewDeleteMyCommandsWithScopeAndLanguage(scope *types.BotCommandScope, languageCode string) *types.DeleteMyCommands { + return &types.DeleteMyCommands{Scope: scope, LanguageCode: languageCode} +} + +// NewBotCommand creates a new bot command message. +func (t *Api) NewBotCommand(command, description string) types.BotCommand { + return types.BotCommand{ + Command: command, + Description: description, + } +} + +// NewBotCommandScopeDefault represents the default scope of bot commands. +func (t *Api) NewBotCommandScopeDefault() *types.BotCommandScope { + return &types.BotCommandScope{Type: "default"} +} + +// NewBotCommandScopeAllPrivateChats represents the scope of bot commands, +// covering all private chats. +func (t *Api) NewBotCommandScopeAllPrivateChats() *types.BotCommandScope { + return &types.BotCommandScope{Type: "all_private_chats"} +} + +// NewBotCommandScopeAllGroupChats represents the scope of bot commands, +// covering all group and supergroup chats. +func (t *Api) NewBotCommandScopeAllGroupChats() *types.BotCommandScope { + return &types.BotCommandScope{Type: "all_group_chats"} +} + +// NewBotCommandScopeAllChatAdministrators represents the scope of bot commands, covering all group and supergroup chat administrators. +func (t *Api) NewBotCommandScopeAllChatAdministrators() *types.BotCommandScope { + return &types.BotCommandScope{Type: "all_chat_administrators"} +} + +// NewBotCommandScopeChat represents the scope of bot commands, covering a specific chat. +func (t *Api) NewBotCommandScopeChat(chatID int64) *types.BotCommandScope { + return &types.BotCommandScope{ + Type: "chat", + ChatID: chatID, + } +} + +// NewBotCommandScopeChatAdministrators represents the scope of bot commands, +// covering all administrators of a specific group or supergroup chat. +func (t *Api) NewBotCommandScopeChatAdministrators(chatID int64) *types.BotCommandScope { + return &types.BotCommandScope{ + Type: "chat_administrators", + ChatID: chatID, + } +} + +// NewBotCommandScopeChatMember represents the scope of bot commands, covering a specific member of a group or supergroup chat. +func (t *Api) NewBotCommandScopeChatMember(chatID, userID int64) *types.BotCommandScope { + return &types.BotCommandScope{ + Type: "chat_member", + ChatID: chatID, + UserID: userID, + } +} + +// NewSetMyName creates a set my name message. +func (t *Api) NewSetMyName() *types.SetMyName { + return &types.SetMyName{} +} + +// NewGetMyName creates a get my name message. +func (t *Api) NewGetMyName() *types.GetMyName { + return &types.GetMyName{} +} + +// NewSetMyDescription creates a set my description message. +func (t *Api) NewSetMyDescription() *types.SetMyDescription { + return &types.SetMyDescription{} +} + +// NewGetMyDescription creates a get my description message. +func (t *Api) NewGetMyDescription() *types.GetMyDescription { + return &types.GetMyDescription{} +} + +// NewSetMyShortDescription creates a set my short description message. +func (t *Api) NewSetMyShortDescription() *types.SetMyShortDescription { + return &types.SetMyShortDescription{} +} + +// NewGetMyShortDescription creates a get my short description message. +func (t *Api) NewGetMyShortDescription() *types.GetMyShortDescription { + return &types.GetMyShortDescription{} +} + +// NewSetChatMenuButton creates a new set chat menu button message. +func (t *Api) NewSetChatMenuButton() *types.SetChatMenuButton { + return &types.SetChatMenuButton{} +} + +// NewMenuButtonCommands represents the menu button of a bot menu. +func (t *Api) NewMenuButtonCommands(command string) *types.MenuButton { + return &types.MenuButton{ + Type: command, + } +} + +// NewMenuButtonWebApp represents the menu button of a bot menu. +func (t *Api) NewMenuButtonWebApp(text, Url string) *types.MenuButton { + return &types.MenuButton{ + Type: "web_app", + Text: text, + WebApp: &types.WebAppInfo{ + URL: Url, + }, + } +} + +// NewMenuButtonDefault represents the menu button of a bot menu. +func (t *Api) NewMenuButtonDefault() *types.MenuButton { + return &types.MenuButton{ + Type: "default", + } +} + +// NewGetChatMenuButton creates a new get chat menu button message. +func (t *Api) NewGetChatMenuButton() *types.GetChatMenuButton { + return &types.GetChatMenuButton{} +} + +// NewSetMyDefaultAdministratorRights creates a new a set my default administrator rights message. +func (t *Api) NewSetMyDefaultAdministratorRights() *types.SetMyDefaultAdministratorRights { + return &types.SetMyDefaultAdministratorRights{} +} + +// NewGetMyDefaultAdministratorRights creates a new get my default administrator rights message. +func (t *Api) NewGetMyDefaultAdministratorRights() *types.GetMyDefaultAdministratorRights { + return &types.GetMyDefaultAdministratorRights{} +} + +// NewEditMessageText creates a new edit message text message. +func (t *Api) NewEditMessageText() *types.EditMessageText { + return &types.EditMessageText{} +} + +// NewEditMessageCaption creates a new edit message caption message. +func (t *Api) NewEditMessageCaption() *types.EditMessageCaption { + return &types.EditMessageCaption{} +} + +// NewEditMessageMedia creates a new edit message media message. +func (t *Api) NewEditMessageMedia() *types.EditMessageMedia { + return &types.EditMessageMedia{} +} + +// NewEditMessageReplyMarkup creates a new edit message reply markup message. +func (t *Api) NewEditMessageReplyMarkup() *types.EditMessageReplyMarkup { + return &types.EditMessageReplyMarkup{} +} + +// NewStopPoll creates a new stop poll message. +func (t *Api) NewStopPoll() *types.StopPoll { + return &types.StopPoll{} +} + +// NewDeleteMessage creates a new delete message. +func (t *Api) NewDeleteMessage() *types.DeleteMessage { + return &types.DeleteMessage{} +} + +// NewDeleteMessages creates a new delete messages. +func (t *Api) NewDeleteMessages() *types.DeleteMessages { + return &types.DeleteMessages{} +} + +// NewSendSticker creates a new send sticker message. +func (t *Api) NewSendSticker() *types.SendSticker { + return &types.SendSticker{} +} + +// NewGetStickerSet creates a new get sticker set message. +func (t *Api) NewGetStickerSet() *types.GetStickerSet { + return &types.GetStickerSet{} +} + +// NewGetCustomEmojiStickers creates a new get custom emoji stickers message. +func (t *Api) NewGetCustomEmojiStickers() *types.GetCustomEmojiStickers { + return &types.GetCustomEmojiStickers{} +} + +// NewUploadStickerFile creates a new upload sticker file message. +func (t *Api) NewUploadStickerFile() *types.UploadStickerFile { + return &types.UploadStickerFile{} +} + +// NewCreateNewStickerSet creates a new creation new sticker set message. +func (t *Api) NewCreateNewStickerSet() *types.CreateNewStickerSet { + return &types.CreateNewStickerSet{} +} + +// NewAddStickerToSet creates a new added sticker to set a message. +func (t *Api) NewAddStickerToSet() *types.AddStickerToSet { + return &types.AddStickerToSet{} +} + +// NewInputSticker creates a new input sticker message. +func (t *Api) NewInputSticker() types.InputSticker { + return types.InputSticker{} +} + +// NewMaskPosition creates a new mask position message. +func (t *Api) NewMaskPosition() *types.MaskPosition { + return &types.MaskPosition{} +} + +// NewSetStickerPositionInSet creates a new set sticker position in a set message. +func (t *Api) NewSetStickerPositionInSet() *types.SetStickerPositionInSet { + return &types.SetStickerPositionInSet{} +} + +// NewDeleteStickerFromSet creates a new delete sticker from set message. +func (t *Api) NewDeleteStickerFromSet() *types.DeleteStickerFromSet { + return &types.DeleteStickerFromSet{} +} + +// NewReplaceStickerInSet creates a new replace sticker in set. +func (t *Api) NewReplaceStickerInSet() *types.ReplaceStickerInSet { + return &types.ReplaceStickerInSet{} +} + +// NewSetStickerEmojiList creates a new set sticker emoji list message. +func (t *Api) NewSetStickerEmojiList() *types.SetStickerEmojiList { + return &types.SetStickerEmojiList{} +} + +// NewSetStickerKeywords creates a new set sticker keywords message. +func (t *Api) NewSetStickerKeywords() *types.SetStickerKeywords { + return &types.SetStickerKeywords{} +} + +// NewSetStickerMaskPosition creates a new set sticker mask position message. +func (t *Api) NewSetStickerMaskPosition() *types.SetStickerMaskPosition { + return &types.SetStickerMaskPosition{} +} + +// NewSetStickerSetTitle creates a new set sticker set title message. +func (t *Api) NewSetStickerSetTitle() *types.SetStickerSetTitle { + return &types.SetStickerSetTitle{} +} + +// NewSetStickerSetThumbnail creates a new set sticker set thumbnail message. +func (t *Api) NewSetStickerSetThumbnail() *types.SetStickerSetThumbnail { + return &types.SetStickerSetThumbnail{} +} + +// NewSetCustomEmojiStickerSetThumbnail creates a new set custom emoji sticker set thumbnail message. +func (t *Api) NewSetCustomEmojiStickerSetThumbnail() *types.SetCustomEmojiStickerSetThumbnail { + return &types.SetCustomEmojiStickerSetThumbnail{} +} + +// NewDeleteStickerSet creates a new delete sticker set message. +func (t *Api) NewDeleteStickerSet() *types.DeleteStickerSet { + return &types.DeleteStickerSet{} +} + +// NewInlineQueryResultsButtonStartParameter creates a new inline query results button startParameter. +func (t *Api) NewInlineQueryResultsButtonStartParameter(title, startParameter string) *types.InlineQueryResultsButton { + return &types.InlineQueryResultsButton{ + Text: title, + StartParameter: &startParameter, + } +} + +// NewInlineQueryResultsButtonWebApp creates a new inline query results button webApp. +func (t *Api) NewInlineQueryResultsButtonWebApp(title string, webApp *types.WebAppInfo) *types.InlineQueryResultsButton { + return &types.InlineQueryResultsButton{ + Text: title, + WebApp: webApp, + } +} + +// NewAnswerInlineQuery creates a new answer inline query message. +func (t *Api) NewAnswerInlineQuery() *types.AnswerInlineQuery { + return &types.AnswerInlineQuery{} +} + +// NewInlineQueryResultArticle creates a new inline query article. +func (t *Api) NewInlineQueryResultArticle(id, title string) *types.InlineQueryResultArticle { + return &types.InlineQueryResultArticle{ + Type: "article", + ID: id, + Title: title, + } +} + +// NewInputTextMessageContent creates a new input text message content. +func (t *Api) NewInputTextMessageContent() *types.InputTextMessageContent { + return &types.InputTextMessageContent{} +} + +// NewInputLocationMessageContent creates a new input location message content. +func (t *Api) NewInputLocationMessageContent() *types.InputLocationMessageContent { + return &types.InputLocationMessageContent{} +} + +// NewInputVenueMessageContent creates a new input venue message content. +func (t *Api) NewInputVenueMessageContent() *types.InputVenueMessageContent { + return &types.InputVenueMessageContent{} +} + +// NewInputContactMessageContent creates a new input contact message content. +func (t *Api) NewInputContactMessageContent() *types.InputContactMessageContent { + return &types.InputContactMessageContent{} +} + +// NewInputInvoiceMessageContent creates a new input invoice message content. +func (t *Api) NewInputInvoiceMessageContent() *types.InputInvoiceMessageContent { + return &types.InputInvoiceMessageContent{} +} + +// NewInlineQueryResultGIF creates a new inline query GIF. +func (t *Api) NewInlineQueryResultGIF(id, url string) *types.InlineQueryResultGIF { + return &types.InlineQueryResultGIF{ + Type: "gif", + ID: id, + URL: url, + } +} + +// NewInlineQueryResultCachedGIF create a new inline query with a cached photo. +func (t *Api) NewInlineQueryResultCachedGIF(id, gifID string) *types.InlineQueryResultCachedGIF { + return &types.InlineQueryResultCachedGIF{ + Type: "gif", + ID: id, + GifID: gifID, + } +} + +// NewInlineQueryResultMPEG4GIF creates a new inline query MPEG4 GIF. +func (t *Api) NewInlineQueryResultMPEG4GIF(id, url string) *types.InlineQueryResultMPEG4GIF { + return &types.InlineQueryResultMPEG4GIF{ + Type: "mpeg4_gif", + ID: id, + URL: url, + } +} + +// NewInlineQueryResultCachedMPEG4GIF create a new inline query with cached MPEG4 GIF. +func (t *Api) NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) *types.InlineQueryResultCachedMPEG4GIF { + return &types.InlineQueryResultCachedMPEG4GIF{ + Type: "mpeg4_gif", + ID: id, + MPEG4FileID: MPEG4GifID, + } +} + +// NewInlineQueryResultPhoto creates a new inline query photo. +func (t *Api) NewInlineQueryResultPhoto(id, url string) *types.InlineQueryResultPhoto { + return &types.InlineQueryResultPhoto{ + Type: "photo", + ID: id, + URL: url, + } +} + +// NewInlineQueryResultPhotoWithThumbnail creates a new inline query photo. +func (t *Api) NewInlineQueryResultPhotoWithThumbnail(id, url, thumbnail string) *types.InlineQueryResultPhoto { + return &types.InlineQueryResultPhoto{ + Type: "photo", + ID: id, + URL: url, + ThumbnailURL: thumbnail, + } +} + +// NewInlineQueryResultCachedPhoto create a new inline query with a cached photo. +func (t *Api) NewInlineQueryResultCachedPhoto(id, photoID string) *types.InlineQueryResultCachedPhoto { + return &types.InlineQueryResultCachedPhoto{ + Type: "photo", + ID: id, + PhotoID: photoID, + } +} + +// NewInlineQueryResultVideo creates a new inline query video. +func (t *Api) NewInlineQueryResultVideo(id, url string) *types.InlineQueryResultVideo { + return &types.InlineQueryResultVideo{ + Type: "video", + ID: id, + URL: url, + } +} + +// NewInlineQueryResultCachedVideo create a new inline query with cached video. +func (t *Api) NewInlineQueryResultCachedVideo(id, videoID, title string) *types.InlineQueryResultCachedVideo { + return &types.InlineQueryResultCachedVideo{ + Type: "video", + ID: id, + VideoID: videoID, + Title: title, + } +} + +// NewInlineQueryResultCachedSticker create a new inline query with cached sticker. +func (t *Api) NewInlineQueryResultCachedSticker(id, stickerID string) *types.InlineQueryResultCachedSticker { + return &types.InlineQueryResultCachedSticker{ + Type: "sticker", + ID: id, + StickerID: stickerID, + } +} + +// NewInlineQueryResultAudio creates a new inline query audio. +func (t *Api) NewInlineQueryResultAudio(id, url, title string) *types.InlineQueryResultAudio { + return &types.InlineQueryResultAudio{ + Type: "audio", + ID: id, + URL: url, + Title: title, + } +} + +// NewInlineQueryResultCachedAudio create a new inline query with a cached photo. +func (t *Api) NewInlineQueryResultCachedAudio(id, audioID string) *types.InlineQueryResultCachedAudio { + return &types.InlineQueryResultCachedAudio{ + Type: "audio", + ID: id, + AudioID: audioID, + } +} + +// NewInlineQueryResultVoice creates a new inline query voice. +func (t *Api) NewInlineQueryResultVoice(id, url, title string) *types.InlineQueryResultVoice { + return &types.InlineQueryResultVoice{ + Type: "voice", + ID: id, + URL: url, + Title: title, + } +} + +// NewInlineQueryResultCachedVoice create a new inline query with a cached photo. +func (t *Api) NewInlineQueryResultCachedVoice(id, voiceID, title string) *types.InlineQueryResultCachedVoice { + return &types.InlineQueryResultCachedVoice{ + Type: "voice", + ID: id, + VoiceID: voiceID, + Title: title, + } +} + +// NewInlineQueryResultDocument creates a new inline query document. +func (t *Api) NewInlineQueryResultDocument(id, url, title, mimeType string) *types.InlineQueryResultDocument { + return &types.InlineQueryResultDocument{ + Type: "document", + ID: id, + URL: url, + Title: title, + MimeType: mimeType, + } +} + +// NewInlineQueryResultCachedDocument create a new inline query with a cached photo. +func (t *Api) NewInlineQueryResultCachedDocument(id, documentID, title string) *types.InlineQueryResultCachedDocument { + return &types.InlineQueryResultCachedDocument{ + Type: "document", + ID: id, + DocumentID: documentID, + Title: title, + } +} + +// NewInlineQueryResultLocation creates a new inline query location. +func (t *Api) NewInlineQueryResultLocation(id, title string, latitude, longitude float64) *types.InlineQueryResultLocation { + return &types.InlineQueryResultLocation{ + Type: "location", + ID: id, + Title: title, + Latitude: latitude, + Longitude: longitude, + } +} + +// NewInlineQueryResultVenue creates a new inline query venue. +func (t *Api) NewInlineQueryResultVenue(id, title, address string, latitude, longitude float64) *types.InlineQueryResultVenue { + return &types.InlineQueryResultVenue{ + Type: "venue", + ID: id, + Title: title, + Address: address, + Latitude: latitude, + Longitude: longitude, + } +} + +// NewAnswerWebAppQuery creates a new answer web app query. +func (t *Api) NewAnswerWebAppQuery() *types.AnswerWebAppQuery { + return &types.AnswerWebAppQuery{} +} + +// NewSendInvoice creates a new sent invoice message. +func (t *Api) NewSendInvoice() *types.SendInvoice { + return &types.SendInvoice{} +} + +// NewLabeledPrice creates a new labeled price message. +func (t *Api) NewLabeledPrice(label string, amount int) types.LabeledPrice { + return types.LabeledPrice{ + Label: label, + Amount: amount, + } +} + +// NewLabeledPrices creates a new labeled prices message. +func (t *Api) NewLabeledPrices(labeledPrice ...types.LabeledPrice) []types.LabeledPrice { + var row []types.LabeledPrice + + row = append(row, labeledPrice...) + + return row +} + +// NewCreateInvoiceLink creates a new create invoice link. +func (t *Api) NewCreateInvoiceLink() *types.CreateInvoiceLink { + return &types.CreateInvoiceLink{} +} + +// NewAnswerShippingQuery creates a new answer shipping query. +func (t *Api) NewAnswerShippingQuery() *types.AnswerShippingQuery { + return &types.AnswerShippingQuery{} +} + +// NewAnswerPreCheckoutQuery creates a new answer pre-checkout query. +func (t *Api) NewAnswerPreCheckoutQuery() *types.AnswerPreCheckoutQuery { + return &types.AnswerPreCheckoutQuery{} +} + +// NewGetStarTransactions creates a new get star transactions query. +func (t *Api) NewGetStarTransactions() *types.GetStarTransactions { + return &types.GetStarTransactions{} +} + +// NewRefundStarPayment creates a new refund star payment. +func (t *Api) NewRefundStarPayment() *types.RefundStarPayment { + return &types.RefundStarPayment{} +} + +// NewSetPassportDataErrors creates a new set passport data errors. +func (t *Api) NewSetPassportDataErrors() *types.SetPassportDataErrors { + return &types.SetPassportDataErrors{} +} + +// PassportElementErrorDataField creates a passport element error data field. +func (t *Api) PassportElementErrorDataField() *types.PassportElementErrorDataField { + return &types.PassportElementErrorDataField{} +} + +// PassportElementErrorFrontSide creates a passport element error front side. +func (t *Api) PassportElementErrorFrontSide() *types.PassportElementErrorFrontSide { + return &types.PassportElementErrorFrontSide{} +} + +// PassportElementErrorReverseSide creates a passport element error reverse side. +func (t *Api) PassportElementErrorReverseSide() *types.PassportElementErrorReverseSide { + return &types.PassportElementErrorReverseSide{} +} + +// PassportElementErrorSelfie creates a passport element error selfie. +func (t *Api) PassportElementErrorSelfie() *types.PassportElementErrorSelfie { + return &types.PassportElementErrorSelfie{} +} + +// PassportElementErrorFile creates a passport element error file. +func (t *Api) PassportElementErrorFile() *types.PassportElementErrorFile { + return &types.PassportElementErrorFile{} +} + +// PassportElementErrorFiles creates a passport element error files. +func (t *Api) PassportElementErrorFiles() *types.PassportElementErrorFiles { + return &types.PassportElementErrorFiles{} +} + +// PassportElementErrorTranslationFile creates a passport element error translation file. +func (t *Api) PassportElementErrorTranslationFile() *types.PassportElementErrorTranslationFile { + return &types.PassportElementErrorTranslationFile{} +} + +// PassportElementErrorTranslationFiles creates a passport element error translation files. +func (t *Api) PassportElementErrorTranslationFiles() *types.PassportElementErrorTranslationFiles { + return &types.PassportElementErrorTranslationFiles{} +} + +// PassportElementErrorUnspecified creates a passport element error unspecified. +func (t *Api) PassportElementErrorUnspecified() *types.PassportElementErrorUnspecified { + return &types.PassportElementErrorUnspecified{} +} + +// NewSendGame creates a new send game message. +func (t *Api) NewSendGame() *types.SendGame { + return &types.SendGame{} +} + +// NewSetGameScore creates a new send game message. +func (t *Api) NewSetGameScore() *types.SetGameScore { + return &types.SetGameScore{} +} + +// NewGetGameHighScores creates a new get game high scores. +func (t *Api) NewGetGameHighScores() *types.GetGameHighScores { + return &types.GetGameHighScores{} +} diff --git a/types/Bot.go b/types/Bot.go new file mode 100644 index 0000000..3bef30c --- /dev/null +++ b/types/Bot.go @@ -0,0 +1,19 @@ +package types + +import ( + "bytes" + "net/http" + "time" +) + +// BotApi api config data +type BotApi struct { + Token string + BaseUrl string + Debug bool + Log bytes.Buffer + RequestTimeout time.Duration + Client *http.Client + SecretToken string + GetUpdateChannel chan any +} diff --git a/types/helpers.go b/types/helpers.go new file mode 100644 index 0000000..f2b884f --- /dev/null +++ b/types/helpers.go @@ -0,0 +1,363 @@ +package types + +import ( + "bytes" + "encoding/json" + "errors" + "io" + "os" + "reflect" + "strconv" + "strings" +) + +func (fb FileBytes) NeedsUpload() bool { + return true +} + +func (fb FileBytes) UploadData() (string, io.Reader, error) { + return fb.Name, bytes.NewReader(fb.Bytes), nil +} + +func (fb FileBytes) SendData() string { + return "FileBytes must be uploaded" +} + +func (fr FileReader) NeedsUpload() bool { + return true +} + +func (fr FileReader) UploadData() (string, io.Reader, error) { + return fr.Name, fr.Reader, nil +} + +func (fr FileReader) SendData() string { + return "FileReader must be uploaded" +} + +func (fp FilePath) NeedsUpload() bool { + return true +} + +func (fp FilePath) UploadData() (string, io.Reader, error) { + fileHandle, err := os.Open(string(fp)) + if err != nil { + return "", nil, err + } + + name := fileHandle.Name() + return name, fileHandle, err +} + +func (fp FilePath) SendData() string { + return "FilePath must be uploaded" +} + +func (fu FileURL) NeedsUpload() bool { + return false +} + +func (fu FileURL) UploadData() (string, io.Reader, error) { + return "", nil, errors.New("FileURL cannot be uploaded") +} + +func (fu FileURL) SendData() string { + return string(fu) +} + +func (fi FileID) NeedsUpload() bool { + return false +} + +func (fi FileID) UploadData() (string, io.Reader, error) { + return "", nil, errors.New("FileID cannot be uploaded") +} + +func (fi FileID) SendData() string { + return string(fi) +} + +func (fa FileAttach) NeedsUpload() bool { + return false +} + +func (fa FileAttach) UploadData() (string, io.Reader, error) { + return "", nil, errors.New("fileAttach cannot be uploaded") +} + +func (fa FileAttach) SendData() string { + return string(fa) +} + +// AddNonEmpty adds a value if it not an empty string. +func (p Params) AddNonEmpty(key, value string) { + if value != "" { + p[key] = value + } +} + +// AddNonZero adds a value if it is not zero. +func (p Params) AddNonZero(key string, value int) { + if value != 0 { + p[key] = strconv.Itoa(value) + } +} + +// AddNonZero64 is the same as AddNonZero except uses an int64. +func (p Params) AddNonZero64(key string, value int64) { + if value != 0 { + p[key] = strconv.FormatInt(value, 10) + } +} + +// AddBool adds a value of a bool if it is true. +func (p Params) AddBool(key string, value bool) { + if value { + p[key] = strconv.FormatBool(value) + } +} + +// AddNonZeroFloat adds a floating point value that is not zero. +func (p Params) AddNonZeroFloat(key string, value float64) { + if value != 0 { + p[key] = strconv.FormatFloat(value, 'f', 6, 64) + } +} + +// AddAny adds an any if it is not nil and can be JSON marshaled. +func (p Params) AddAny(key string, value any) error { + if value == nil || (reflect.ValueOf(value).Kind() == reflect.Ptr && reflect.ValueOf(value).IsNil()) { + return nil + } + + b, err := json.Marshal(value) + if err != nil { + return err + } + + p[key] = string(b) + + return nil +} + +// AddAt adds @ if it not an empty string. +func (p Params) AddAt(value string) { + if value != "" && value[0:1] != "@" { + value = "@" + value + } +} + +// AddFirstValid attempts to add the first item that is not a default value. +// For example, AddFirstValid(0, "", "test") would add "test". +func (p Params) AddFirstValid(key string, args ...any) error { + for _, arg := range args { + switch v := arg.(type) { + case int: + if v != 0 { + p[key] = strconv.Itoa(v) + return nil + } + case int64: + if v != 0 { + p[key] = strconv.FormatInt(v, 10) + return nil + } + case string: + if v != "" { + p[key] = v + return nil + } + case nil: + default: + b, err := json.Marshal(arg) + if err != nil { + return err + } + + p[key] = string(b) + return nil + } + } + + return nil +} + +// Error message string. +func (e *Error) Error() string { + return e.Message +} + +// SentFrom returns the user who sent an update. +// Can be nil if Telegram did not provide information about the user in the update object. +func (u *Update) SentFrom() *User { + switch { + case u.Message != nil: + return u.Message.From + case u.EditedMessage != nil: + return u.EditedMessage.From + case u.InlineQuery != nil: + return &u.InlineQuery.From + case u.ChosenInlineResult != nil: + return &u.ChosenInlineResult.From + case u.CallbackQuery != nil: + return &u.CallbackQuery.From + case u.ShippingQuery != nil: + return &u.ShippingQuery.From + case u.PreCheckoutQuery != nil: + return &u.PreCheckoutQuery.From + default: + return nil + } +} + +// CallbackData returns the callback query data if it exists. +func (u *Update) CallbackData() string { + if u.CallbackQuery != nil { + return u.CallbackQuery.Data + } + return "" +} + +// FromChat returns the chat where an update occurred. +func (u *Update) FromChat() Chat { + switch { + case u.Message != nil: + return u.Message.Chat + case u.EditedMessage != nil: + return u.EditedMessage.Chat + case u.ChannelPost != nil: + return u.ChannelPost.Chat + case u.EditedChannelPost != nil: + return u.EditedChannelPost.Chat + case u.CallbackQuery != nil: + return u.CallbackQuery.Message.Chat + default: + return Chat{} + } +} + +// String displays a simple text version of a user. +// It is normally a user's username, but falls back to a first/last name as available. +func (u *User) String() string { + if u == nil { + return "" + } + if u.UserName != "" { + return u.UserName + } + + name := u.FirstName + if u.LastName != "" { + name += " " + u.LastName + } + + return name +} + +// IsPrivate returns if the Chat is a private conversation. +func (c *Chat) IsPrivate() bool { + return c.Type == "private" +} + +// IsGroup returns if the Chat is a group. +func (c *Chat) IsGroup() bool { + return c.Type == "group" +} + +// IsSuperGroup returns if the Chat is a supergroup. +func (c *Chat) IsSuperGroup() bool { + return c.Type == "supergroup" +} + +// IsChannel returns if the Chat is a channel. +func (c *Chat) IsChannel() bool { + return c.Type == "channel" +} + +// IsCommand returns true if a message starts with a "bot_command" entity. +func (m *Message) IsCommand() bool { + if m.Entities == nil || len(m.Entities) == 0 { + return false + } + + entity := m.Entities[0] + return entity.Offset == 0 && entity.IsCommand() +} + +// Command checks if the message was a command and if it was, returns the command. +// If the Message was not a command, it returns an empty string. +// If the command contains the at name syntax, it is removed. +// Use CommandWithAt() if you do not want that. +func (m *Message) Command() string { + command := m.CommandWithAt() + + if i := strings.Index(command, "@"); i != -1 { + command = command[:i] + } + + return command +} + +// CommandWithAt checks if the message was a command and if it was, returns the command. +// If the Message was not a command, it returns an empty string. +// If the command contains the at name syntax, it is not removed. +// Use Command() if you want that. +func (m *Message) CommandWithAt() string { + if !m.IsCommand() { + return "" + } + + // IsCommand() checks that the message begins with a bot_command entity + entity := m.Entities[0] + return m.Text[1:entity.Length] +} + +// IsMention returns true if the type of the message entity is "mention" (@username). +func (e *MessageEntity) IsMention() bool { + return e.Type == "mention" +} + +// IsHashtag returns true if the type of the message entity is "hashtag". +func (e *MessageEntity) IsHashtag() bool { + return e.Type == "hashtag" +} + +// IsCommand returns true if the type of the message entity is "bot_command". +func (e *MessageEntity) IsCommand() bool { + return e.Type == "bot_command" +} + +// IsURL returns true if the type of the message entity is "url". +func (e *MessageEntity) IsURL() bool { + return e.Type == "url" +} + +// IsEmail returns true if the type of the message entity is "email". +func (e *MessageEntity) IsEmail() bool { + return e.Type == "email" +} + +// IsBold returns true if the type of the message entity is "bold" (bold text). +func (e *MessageEntity) IsBold() bool { + return e.Type == "bold" +} + +// IsItalic returns true if the type of the message entity is "italic" (italic text). +func (e *MessageEntity) IsItalic() bool { + return e.Type == "italic" +} + +// IsCode returns true if the type of the message entity is "code" (monoWidth string). +func (e *MessageEntity) IsCode() bool { + return e.Type == "code" +} + +// IsPre returns true if the type of the message entity is "pre" (monoWidth block). +func (e *MessageEntity) IsPre() bool { + return e.Type == "pre" +} + +// IsTextLink returns true if the type of the message entity is "text_link" (clickable text URL). +func (e *MessageEntity) IsTextLink() bool { + return e.Type == "text_link" +} diff --git a/types/methods.go b/types/methods.go new file mode 100644 index 0000000..778c58d --- /dev/null +++ b/types/methods.go @@ -0,0 +1,4308 @@ +package types + +import ( + "fmt" + "net/url" + "strconv" + + "github.com/alisapro/telegram-bot-api/config" +) + +// SetWebhook Specify a URL and receive incoming updates via an outgoing webhook. +//Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, +//containing a JSON-serialized Update. +//In case of an unsuccessful request, we will give up after a reasonable number of attempts. +//Returns True to success. +//If you'd like to make sure that you set the webhook, +//you can specify secret data in the parameter secret_token. +//If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content. +// Notes: +//1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up. +//2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. +//Please upload as InputFile, sending a String will not work. +//3. Ports currently supported for webhooks: 443, 80, 88, 8443. +//If you're having any trouble setting up webhooks, please check out this amazing guide to webhooks. + +// GetUpdates Receive incoming updates using long polling (wiki). An Array of Update objects is returned. +type GetUpdates struct { + Offset int + Limit int + Timeout int + AllowedUpdates []string +} + +func (s *GetUpdates) Params() (Params, error) { + params := make(Params, 4) + + params.AddNonZero("offset", s.Offset) + params.AddNonZero("limit", s.Limit) + params.AddNonZero("timeout", s.Timeout) + err := params.AddAny("allowed_updates", s.AllowedUpdates) + + return params, err +} +func (*GetUpdates) EndPoint() string { + return config.EndpointGetUpdates +} + +// UpdatesChannel is the channel for getting updates. +type UpdatesChannel <-chan Update + +// Clear discards all unprocessed incoming updates. +func (ch UpdatesChannel) Clear() { + for len(ch) != 0 { + <-ch + } +} + +type SetWebhook struct { + URL *url.URL // HTTPS URL to send updates to. Use an empty string to remove webhook integration + Certificate RequestFileData // Optional. + // Upload your public key certificate + // so that the root certificate in use can be checked. + // See our self-signed guide for details. + IPAddress string // Optional. The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS + MaxConnections int // Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot server, and higher values to increase your bot's throughput. + AllowedUpdates []string // Optional. A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message” “edited_channel_post” “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. + DropPendingUpdates bool // Optional. Pass True to drop all pending updates + SecretToken string // A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. +} + +func (s *SetWebhook) Params() (Params, error) { + params := make(Params, 6) + + if s.URL != nil { + params["url"] = s.URL.String() + } + params.AddNonEmpty("ip_address", s.IPAddress) + params.AddNonZero("max_connections", s.MaxConnections) + err := params.AddAny("allowed_updates", s.AllowedUpdates) + if err != nil { + return params, err + } + params.AddBool("drop_pending_updates", s.DropPendingUpdates) + params.AddNonEmpty("secret_token", s.SecretToken) + + return params, nil +} +func (s *SetWebhook) Files() []RequestFile { + if s.Certificate != nil { + return []RequestFile{{ + Name: "certificate", + Data: s.Certificate, + }} + } + + return nil +} +func (s *SetWebhook) EndPoint() string { + return config.EndpointSetWebhook +} + +// DeleteWebhook Remove webhook integration if you decide to switch back to getUpdates. Returns True to success. +type DeleteWebhook struct { + DropPendingUpdates bool // Optional. Pass True to drop all pending updates +} + +func (s *DeleteWebhook) Params() (Params, error) { + params := make(Params, 1) + + params.AddBool("drop_pending_updates", s.DropPendingUpdates) + + return params, nil +} +func (s *DeleteWebhook) EndPoint() string { + return config.EndpointDeleteWebhook +} + +// SendMessage Send text messages. On success, the sent Message is returned. +type SendMessage struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Text string // required + ParseMode string + Entities []MessageEntity + LinkPreviewOptions *LinkPreviewOptions + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendMessage) Params() (Params, error) { + params := make(Params, 12) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["text"] = s.Text + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("entities", s.Entities) + if err != nil { + return params, err + } + err = params.AddAny("link_preview_options", s.LinkPreviewOptions) + if err != nil { + return params, err + } + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendMessage) EndPoint() string { + return config.EndpointSendMessage +} + +// ForwardMessage Forward messages of any kind. +// Service messages can't be forwarded. +// On success, the sent Message is returned. +type ForwardMessage struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + FromChatID int64 // required. use for user|channel as int + FromChatIDStr string // required. use for user|channel as string + FromUsername string // required. use for channel + DisableNotification bool + ProtectContent bool + MessageID int // required +} + +func (s *ForwardMessage) Params() (Params, error) { + params := make(Params, 6) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + err = params.AddFirstValid("from_chat_id", s.FromChatID, s.FromChatIDStr, s.FromUsername) + if err != nil { + return params, err + } + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params["message_id"] = strconv.Itoa(s.MessageID) + + return params, nil +} +func (s *ForwardMessage) EndPoint() string { + return config.EndpointForwardMessage +} + +// ForwardMessages Forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. +// Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. +// On success, an array of MessageId of the sent messages is returned. +type ForwardMessages struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadId int + FromChatID int64 // required. use for user|channel as int + FromChatIDStr string // required. use for user|channel as string + FromUsername string // required. use for channel + MessageIds []int // required + DisableNotification bool + ProtectContent bool +} + +func (s ForwardMessages) Params() (Params, error) { + params := make(Params, 6) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_thread_id", s.MessageThreadId) + err = params.AddFirstValid("from_chat_id", s.FromChatID, s.FromChatIDStr, s.FromUsername) + if err != nil { + return params, err + } + err = params.AddAny("message_ids", s.MessageIds) + if err != nil { + return params, err + } + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + + return params, nil +} +func (s ForwardMessages) EndPoint() string { + return config.EndpointForwardMessages +} + +// CopyMessage Copy messages of any kind. +// Service messages and invoice messages can't be copied. +// The method is analogous to the method forwardMessage, +// but the copied message doesn't have a link to the original message. +// Returns the MessageId of the sent message on success. +type CopyMessage struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + FromChatID int64 // required. use for user|channel as int + FromChatIDStr string // required. use for user|channel as string + FromUsername string // required. use for channel + MessageID int + Caption string + ParseMode string + CaptionEntities []MessageEntity + ShowCaptionAboveMedia bool + DisableNotification bool + ProtectContent bool + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *CopyMessage) Params() (Params, error) { + params := make(Params, 12) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + err = params.AddFirstValid("from_chat_id", s.FromChatID, s.FromChatIDStr, s.FromUsername) + if err != nil { + return params, err + } + params["message_id"] = strconv.Itoa(s.MessageID) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("show_caption_above_media", s.ShowCaptionAboveMedia) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *CopyMessage) EndPoint() string { + return config.EndpointCopyMessage +} + +// CopyMessages Copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. +// Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. +// A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. +// The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. +// Album grouping is kept for copied messages. +// On success, an array of MessageId of the sent messages is returned. +type CopyMessages struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadId int + FromChatID int64 // required. use for user|channel as int + FromChatIDStr string // required. use for user|channel as string + FromUsername string // required. use for channel + MessageIds []int // required. + Caption string + ParseMode string + CaptionEntities []MessageEntity + DisableNotification bool + ProtectContent bool + ReplyParameters *ReplyParameters + ReplyMarkup interface{} +} + +func (s CopyMessages) Params() (Params, error) { + params := make(Params, 11) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_thread_id", s.MessageThreadId) + err = params.AddFirstValid("from_chat_id", s.FromChatID, s.FromChatIDStr, s.FromUsername) + if err != nil { + return params, err + } + err = params.AddAny("message_ids", s.MessageIds) + if err != nil { + return params, err + } + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s CopyMessages) EndPoint() string { + return config.EndpointCopyMessages +} + +// SendPhoto Send photos. On success, the sent Message is returned. +type SendPhoto struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Photo RequestFileData // required + Caption string + ParseMode string + CaptionEntities []MessageEntity + ShowCaptionAboveMedia bool + HasSpoiler bool + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string +} + +func (s *SendPhoto) Params() (Params, error) { + params := make(Params, 13) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("show_caption_above_media", s.ShowCaptionAboveMedia) + params.AddBool("has_spoiler", s.HasSpoiler) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendPhoto) Files() []RequestFile { + files := []RequestFile{{ + Name: "photo", + Data: s.Photo, + FileName: s.CustomFileName, + }} + + return files +} +func (s *SendPhoto) EndPoint() string { + return config.EndpointSendPhoto +} + +// SendAudio Send audio files if you want Telegram clients to display them in the music player. +// Your audio must be in the .MP3 or .M4A format. +// On success, the sent Message is returned. +// Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. +// For sending voice messages, use the sendVoice method instead. +type SendAudio struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Audio RequestFileData // required + Caption string + ParseMode string + CaptionEntities []MessageEntity + Duration int + Performer string + Title string + Thumbnail RequestFileData + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string + ThumbCustomFileName string +} + +func (s *SendAudio) Params() (Params, error) { + params := make(Params, 14) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddNonZero("duration", s.Duration) + params.AddNonEmpty("performer", s.Performer) + params.AddNonEmpty("title", s.Title) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendAudio) Files() []RequestFile { + files := []RequestFile{{ + Name: "audio", + Data: s.Audio, + FileName: s.CustomFileName, + }} + + if s.Thumbnail != nil { + files = append(files, + RequestFile{ + Name: "thumb", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + RequestFile{ + Name: "thumbnail", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }) + } + + return files +} +func (s *SendAudio) EndPoint() string { + return config.EndpointSendAudio +} + +// SendDocument Send general files. +// On success, the sent Message is returned. +// Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. +type SendDocument struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Document RequestFileData // required + Thumbnail RequestFileData + Caption string + ParseMode string + CaptionEntities []MessageEntity + DisableContentTypeDetection bool + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string + ThumbCustomFileName string +} + +func (s *SendDocument) Params() (Params, error) { + params := make(Params, 12) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("disable_content_type_detection", s.DisableContentTypeDetection) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendDocument) Files() []RequestFile { + files := []RequestFile{{ + Name: "document", + Data: s.Document, + FileName: s.CustomFileName, + }} + if s.Thumbnail != nil { + files = append(files, + RequestFile{ + Name: "thumb", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + RequestFile{ + Name: "thumbnail", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + ) + } + + return files +} +func (s *SendDocument) EndPoint() string { + return config.EndpointSendDocument +} + +// SendVideo Send video files, Telegram clients support MPEG4 videos (other formats may be sent as Document). +// On success, the sent Message is returned. +// Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. +type SendVideo struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Video RequestFileData // required + Duration int + Width int + Height int + Thumbnail RequestFileData + Caption string + ParseMode string + CaptionEntities []MessageEntity + ShowCaptionAboveMedia bool + HasSpoiler bool + SupportsStreaming bool + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string + ThumbCustomFileName string +} + +func (s *SendVideo) Params() (Params, error) { + params := make(Params, 17) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonZero("duration", s.Duration) + params.AddNonZero("width", s.Width) + params.AddNonZero("height", s.Height) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("show_caption_above_media", s.ShowCaptionAboveMedia) + params.AddBool("has_spoiler", s.HasSpoiler) + params.AddBool("supports_streaming", s.SupportsStreaming) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendVideo) Files() []RequestFile { + files := []RequestFile{{ + Name: "video", + Data: s.Video, + FileName: s.CustomFileName, + }} + if s.Thumbnail != nil { + files = append(files, + RequestFile{ + Name: "thumb", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + RequestFile{ + Name: "thumbnail", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + ) + } + + return files +} +func (s *SendVideo) EndPoint() string { + return config.EndpointSendVideo +} + +// SendAnimation Send animation files (GIF or H.264/MPEG-4 AVC video without a sound). +// On success, the sent Message is returned. +// Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. +type SendAnimation struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Animation RequestFileData // required + Duration int + Width int + Height int + Thumbnail RequestFileData + Caption string + ParseMode string + CaptionEntities []MessageEntity + ShowCaptionAboveMedia bool + HasSpoiler bool + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string + ThumbCustomFileName string +} + +func (s *SendAnimation) Params() (Params, error) { + params := make(Params, 16) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonZero("duration", s.Duration) + params.AddNonZero("width", s.Width) + params.AddNonZero("height", s.Height) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("show_caption_above_media", s.ShowCaptionAboveMedia) + params.AddBool("has_spoiler", s.HasSpoiler) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendAnimation) Files() []RequestFile { + files := []RequestFile{{ + Name: "animation", + Data: s.Animation, + FileName: s.CustomFileName, + }} + if s.Thumbnail != nil { + files = append(files, + RequestFile{ + Name: "thumb", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + RequestFile{ + Name: "thumbnail", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + ) + } + + return files +} +func (s *SendAnimation) EndPoint() string { + return config.EndpointSendAnimation +} + +// SendVoice Send audio files if you want Telegram clients to display the file as a playable voice message. +// For this to work, your audio must be in an .OGG file encoded with OPUS +// (other formats may be sent as Audio or Document). +// On success, the sent Message is returned. +// Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. +type SendVoice struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Voice RequestFileData // required + Caption string + ParseMode string + CaptionEntities []MessageEntity + Duration int + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string +} + +func (s *SendVoice) Params() (Params, error) { + params := make(Params, 13) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddNonZero("duration", s.Duration) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendVoice) Files() []RequestFile { + files := []RequestFile{{ + Name: "voice", + Data: s.Voice, + FileName: s.CustomFileName, + }} + + return files +} +func (s *SendVoice) EndPoint() string { + return config.EndpointSendVoice +} + +// SendVideoNote As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. +// Use this method to send video messages. +// On success, the sent Message is returned. +type SendVideoNote struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + VideoNote RequestFileData // required. + Duration int + Length int + Thumbnail RequestFileData + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string + ThumbCustomFileName string +} + +func (s *SendVideoNote) Params() (Params, error) { + params := make(Params, 10) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonZero("duration", s.Duration) + params.AddNonZero("length", s.Length) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendVideoNote) Files() []RequestFile { + files := []RequestFile{{ + Name: "video_note", + Data: s.VideoNote, + FileName: s.CustomFileName, + }} + if s.Thumbnail != nil { + files = append(files, + RequestFile{ + Name: "thumb", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + RequestFile{ + Name: "thumbnail", + Data: s.Thumbnail, + FileName: s.ThumbCustomFileName, + }, + ) + } + + return files +} +func (s *SendVideoNote) EndPoint() string { + return config.EndpointSendVideoNote +} + +// SendPaidMedia Use this method to send paid media to channel chats. +// On success, the sent Message is returned. +type SendPaidMedia struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + StarCount int // required + Media []any // required + Caption string + ParseMode string + CaptionEntities []MessageEntity + ShowCaptionAboveMedia bool + DisableNotification bool + ProtectContent bool + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendPaidMedia) Params() (Params, error) { + params := make(Params, 11) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("star_count", s.StarCount) + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err = params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("show_caption_above_media", s.ShowCaptionAboveMedia) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + if err != nil { + return params, err + } + err = params.AddAny("media", prepareInputPaidMediaForParams(s.Media)) + + return params, err +} +func (s *SendPaidMedia) Files() []RequestFile { + return prepareInputPaidMediaForFiles(s.Media) +} +func (s *SendPaidMedia) EndPoint() string { + return config.EndpointSendPaidMedia +} + +// SendMediaGroup Use this method to send a group of photos, videos, documents or audios as an album. +// Documents and audio files can be only grouped on an album with messages of the same type. +// On success, an array of Messages that were sent is returned. +type SendMediaGroup struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Media []any // required + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters +} + +func (s *SendMediaGroup) Params() (Params, error) { + params := make(Params, 7) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("media", prepareInputMediaForParams(s.Media)) + + return params, err +} +func (s *SendMediaGroup) Files() []RequestFile { + return prepareInputMediaForFiles(s.Media) +} +func (s *SendMediaGroup) EndPoint() string { + return config.EndpointSendMediaGroup +} + +// prepareInputMediaParam evaluates a single InputMedia +// and determines if it needs to be modified for a successful upload. +// If it returns nil, then the value does not need to be included in the params. +// Otherwise, it will return the same type as was originally provided. +// The idx is used to calculate the file field name. +// If you only have a single file, 0 may be used. +// It is formatted into "attach://file-%d" for the primary media and "attach://file-%d-thumbnail" for thumbnails. +// It is expected to be used in conjunction with prepareInputMediaFile. +func prepareInputMediaParam(inputMedia any, idx int) any { + switch m := inputMedia.(type) { + case InputMediaPhoto: + if m.Media.NeedsUpload() { + m.Media = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + return m + case InputMediaVideo: + if m.Media.NeedsUpload() { + m.Media = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + m.Thumbnail = FileAttach(fmt.Sprintf("attach://file-%d-thumb", idx)) + } + + return m + case InputMediaAudio: + if m.Media.NeedsUpload() { + m.Media = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + m.Thumbnail = FileAttach(fmt.Sprintf("attach://file-%d-thumb", idx)) + } + + return m + case InputMediaDocument: + if m.Media.NeedsUpload() { + m.Media = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + m.Thumbnail = FileAttach(fmt.Sprintf("attach://file-%d-thumb", idx)) + } + + return m + } + + return nil +} + +// prepareInputMediaFile generates an array of RequestFile to provide for Fileable files method. +// It returns an array as a single InputMedia may have multiple files for the primary media and a thumbnail. +// The idx parameter is used to generate file field names. +// It uses the names "file-%d" for the main file and "file-%d-thumbnail" for the thumbnail. +// It is expected to be used in conjunction with prepareInputMediaParam. +func prepareInputMediaFile(inputMedia any, idx int) []RequestFile { + var files []RequestFile + + switch m := inputMedia.(type) { + case InputMediaPhoto: + if m.Media.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Media, + }) + } + case InputMediaVideo: + if m.Media.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Media, + }) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Thumbnail, + }) + } + case InputMediaDocument: + if m.Media.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Media, + }) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Thumbnail, + }) + } + case InputMediaAudio: + if m.Media.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Media, + }) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Thumbnail, + }) + } + } + + return files +} + +// prepareInputMediaForParams calls prepareInputMediaParam for each item provided +// and returns a new array with the correct params for a request. +// It is expected that files will get data from the associated function, prepareInputMediaForFiles. +func prepareInputMediaForParams(inputMedia []any) []any { + newMedia := make([]any, len(inputMedia)) + copy(newMedia, inputMedia) + + for idx, media := range inputMedia { + if param := prepareInputMediaParam(media, idx); param != nil { + newMedia[idx] = param + } + } + + return newMedia +} + +// prepareInputMediaForFiles calls prepareInputMediaFile, +// for each item provided and returns a new array with the correct files for a request. +// It is expected that params will get data from the associated function, prepareInputMediaForParams. +func prepareInputMediaForFiles(inputMedia []any) []RequestFile { + var files []RequestFile + + for idx, media := range inputMedia { + if file := prepareInputMediaFile(media, idx); file != nil { + files = append(files, file...) + } + } + + return files +} + +// prepareInputPaidMediaParam evaluates a single InputPaidMedia +// and determines if it needs to be modified for a successful upload. +// If it returns nil, then the value does not need to be included in the params. +// Otherwise, it will return the same type as was originally provided. +// The idx is used to calculate the file field name. +// If you only have a single file, 0 may be used. +// It is formatted into "attach://file-%d" for the primary media and "attach://file-%d-thumbnail" for thumbnails. +// It is expected to be used in conjunction with prepareInputPaidMediaFile. +func prepareInputPaidMediaParam(InputPaidMedia any, idx int) any { + switch m := InputPaidMedia.(type) { + case InputPaidMediaPhoto: + if m.Media.NeedsUpload() { + m.Media = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + return m + case InputPaidMediaVideo: + if m.Media.NeedsUpload() { + m.Media = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + m.Thumbnail = FileAttach(fmt.Sprintf("attach://file-%d-thumb", idx)) + } + + return m + } + + return nil +} + +// prepareInputPaidMediaFile generates an array of RequestFile to provide for Fileable files method. +// It returns an array as a single InputPaidMedia may have multiple files for the primary media and a thumbnail. +// The idx parameter is used to generate file field names. +// It uses the names "file-%d" for the main file and "file-%d-thumbnail" for the thumbnail. +// It is expected to be used in conjunction with prepareInputPaidMediaParam. +func prepareInputPaidMediaFile(InputPaidMedia any, idx int) []RequestFile { + var files []RequestFile + + switch m := InputPaidMedia.(type) { + case InputPaidMediaPhoto: + if m.Media.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Media, + }) + } + case InputPaidMediaVideo: + if m.Media.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Media, + }) + } + + if m.Thumbnail != nil && m.Thumbnail.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Thumbnail, + }) + } + } + + return files +} + +// prepareInputPaidMediaForParams calls prepareInputPaidMediaParam for each item provided +// and returns a new array with the correct params for a request. +// It is expected that files will get data from the associated function, prepareInputPaidMediaForFiles. +func prepareInputPaidMediaForParams(InputPaidMedia []any) []any { + newMedia := make([]any, len(InputPaidMedia)) + copy(newMedia, InputPaidMedia) + + for idx, media := range InputPaidMedia { + if param := prepareInputPaidMediaParam(media, idx); param != nil { + newMedia[idx] = param + } + } + + return newMedia +} + +// prepareInputPaidMediaForFiles calls prepareInputPaidMediaFile, +// for each item provided and returns a new array with the correct files for a request. +// It is expected that params will get data from the associated function, prepareInputPaidMediaForParams. +func prepareInputPaidMediaForFiles(InputPaidMedia []any) []RequestFile { + var files []RequestFile + + for idx, media := range InputPaidMedia { + if file := prepareInputPaidMediaFile(media, idx); file != nil { + files = append(files, file...) + } + } + + return files +} + +// SendLocation Send point on the map. On success, the sent Message is returned. +type SendLocation struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Latitude float64 // required + Longitude float64 // required + HorizontalAccuracy float64 + LivePeriod int + Heading int + ProximityAlertRadius int + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendLocation) Params() (Params, error) { + params := make(Params, 14) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["latitude"] = strconv.FormatFloat(s.Latitude, 'f', 6, 64) + params["longitude"] = strconv.FormatFloat(s.Longitude, 'f', 6, 64) + params.AddNonZeroFloat("horizontal_accuracy", s.HorizontalAccuracy) + params.AddNonZero("live_period", s.LivePeriod) + params.AddNonZero("heading", s.Heading) + params.AddNonZero("proximity_alert_radius", s.ProximityAlertRadius) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendLocation) EndPoint() string { + return config.EndpointSendLocation +} + +// EditMessageLiveLocation Edit live location messages. +// A location can be edited +// until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +type EditMessageLiveLocation struct { + BusinessConnectionId string + ChatID int64 // required if InlineMessageID is not specified. use for user|channel as int + ChatIDStr string // required if InlineMessageID is not specified. use for user|channel as string + Username string // required if InlineMessageID is not specified. use for a channel + MessageID int // required if InlineMessageID is not specified + InlineMessageID string // required if ChatID & Username & MessageID are not specified + Latitude float64 // required + Longitude float64 // required + LivePeriod int + HorizontalAccuracy float64 + Heading int + ProximityAlertRadius int + ReplyMarkup *InlineKeyboardMarkup +} + +func (s *EditMessageLiveLocation) Params() (Params, error) { + var params Params + + if s.InlineMessageID != "" { + params = make(Params, 9) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["inline_message_id"] = s.InlineMessageID + } else { + params = make(Params, 10) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + } + + params["latitude"] = strconv.FormatFloat(s.Latitude, 'f', 6, 64) + params["longitude"] = strconv.FormatFloat(s.Longitude, 'f', 6, 64) + params["live_period"] = strconv.Itoa(s.LivePeriod) + params.AddNonZeroFloat("horizontal_accuracy", s.HorizontalAccuracy) + params.AddNonZero("heading", s.Heading) + params.AddNonZero("proximity_alert_radius", s.ProximityAlertRadius) + + err := params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *EditMessageLiveLocation) EndPoint() string { + return config.EndpointEditMessageLiveLocation +} + +// StopMessageLiveLocation Stop updating a live location message before live_period expires. +// On success, if the message is not an inline message, the edited Message is returned, otherwise True is returned. +type StopMessageLiveLocation struct { + BusinessConnectionId string + ChatID int64 // required if InlineMessageID is not specified. use for user|channel as int + ChatIDStr string // required if InlineMessageID is not specified. use for user|channel as string + Username string // required if InlineMessageID is not specified. use for a channel + MessageID int // required if InlineMessageID is not specified + InlineMessageID string // required if ChatID & Username & MessageID are not specified + ReplyMarkup *InlineKeyboardMarkup +} + +func (s *StopMessageLiveLocation) Params() (Params, error) { + var params Params + + if s.InlineMessageID != "" { + params = make(Params, 3) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["inline_message_id"] = s.InlineMessageID + } else { + params = make(Params, 4) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + } + + err := params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *StopMessageLiveLocation) EndPoint() string { + return config.EndpointStopMessageLiveLocation +} + +// SendVenue Send information about a venue. On success, the sent Message is returned. +type SendVenue struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Latitude float64 // required + Longitude float64 // required + Title string // required + Address string // required + FoursquareID string + FoursquareType string + GooglePlaceID string + GooglePlaceType string + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendVenue) Params() (Params, error) { + params := make(Params, 16) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["latitude"] = strconv.FormatFloat(s.Latitude, 'f', 6, 64) + params["longitude"] = strconv.FormatFloat(s.Longitude, 'f', 6, 64) + params["title"] = s.Title + params["address"] = s.Address + params.AddNonEmpty("foursquare_id", s.FoursquareID) + params.AddNonEmpty("foursquare_type", s.FoursquareType) + params.AddNonEmpty("google_place_id", s.GooglePlaceID) + params.AddNonEmpty("google_place_type", s.GooglePlaceType) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendVenue) EndPoint() string { + return config.EndpointSendVenue +} + +// SendContact Send phone contacts. On success, the sent Message is returned. +type SendContact struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + PhoneNumber string // required + FirstName string // required + LastName string + VCard string + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendContact) Params() (Params, error) { + params := make(Params, 12) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["phone_number"] = s.PhoneNumber + params["first_name"] = s.FirstName + params.AddNonEmpty("last_name", s.LastName) + params.AddNonEmpty("vcard", s.VCard) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendContact) EndPoint() string { + return config.EndpointSendContact +} + +// SendPoll Send a native poll. On success, the sent Message is returned. +type SendPoll struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Question string // required + QuestionParseMode string + Options []InputPollOption // required + IsAnonymous bool + Type string + AllowsMultipleAnswers bool + CorrectOptionID int64 + Explanation string + ExplanationParseMode string + ExplanationEntities []MessageEntity + OpenPeriod int + CloseDate int64 + IsClosed bool + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendPoll) Params() (Params, error) { + params := make(Params, 21) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["question"] = s.Question + params.AddNonEmpty("question_parse_mode", s.QuestionParseMode) + err = params.AddAny("options", s.Options) + if err != nil { + return params, err + } + params.AddBool("is_anonymous", s.IsAnonymous) + params.AddNonEmpty("type", s.Type) + params.AddBool("allows_multiple_answers", s.AllowsMultipleAnswers) + params.AddNonZero64("correct_option_id", s.CorrectOptionID) + params.AddBool("is_closed", s.IsClosed) + params.AddNonEmpty("explanation", s.Explanation) + params.AddNonEmpty("explanation_parse_mode", s.ExplanationParseMode) + params.AddNonZero("open_period", s.OpenPeriod) + params.AddNonZero64("close_date", s.CloseDate) + err = params.AddAny("explanation_entities", s.ExplanationEntities) + if err != nil { + return params, err + } + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendPoll) EndPoint() string { + return config.EndpointSendPoll +} + +// SendDice Send an animated emoji that will display a random value. On success, the sent Message is returned. +type SendDice struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Emoji string // Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲 + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendDice) Params() (Params, error) { + params := make(Params, 9) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonEmpty("emoji", s.Emoji) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendDice) EndPoint() string { + return config.EndpointSendDice +} + +// SendChatAction Send an animated emoji that will display a random value. +// On success, the sent Message is returned. +type SendChatAction struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Action string // required. `typing` for text messages, `upload_photo` for photos, `record_video` or `upload_video` for videos, `record_voice` or `upload_voice` for voice notes, `upload_document` for general files, `choose_sticker` for stickers, `find_location` for location data, `record_video_note` or `upload_video_note` for video notes. +} + +func (s *SendChatAction) Params() (Params, error) { + params := make(Params, 3) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["action"] = s.Action + + return params, nil +} +func (s *SendChatAction) EndPoint() string { + return config.EndpointSendChatAction +} + +// SetMessageReaction Change the chosen reactions on a message. Service messages can't be reacted to. +// Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. +// In albums, bots must react to the first message. +// Returns True on success. +type SetMessageReaction struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageID int // required. Identifier of the target message + Reaction []ReactionType // New list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. + IsBig bool // Pass True to set the reaction with a big animation +} + +func (s SetMessageReaction) Params() (Params, error) { + params := make(Params, 4) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_id"] = strconv.Itoa(s.MessageID) + err = params.AddAny("reaction", s.Reaction) + if err != nil { + return params, err + } + params.AddBool("is_big", s.IsBig) + + return params, nil +} +func (s SetMessageReaction) EndPoint() string { + return config.EndpointSetMessageReaction +} + +// GetUserProfilePhotos Get a list of profile pictures for a user. Returns a UserProfilePhotos object. +type GetUserProfilePhotos struct { + UserID int64 // required + Offset int + Limit int +} + +func (s *GetUserProfilePhotos) Params() (Params, error) { + params := make(Params, 3) + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params.AddNonZero("offset", s.Offset) + params.AddNonZero("limit", s.Limit) + + return params, nil +} +func (s *GetUserProfilePhotos) EndPoint() string { + return config.EndpointGetUserProfilePhotos +} + +// Link returns a full path to the download URL for a File. +// +// It requires the Bot token to create the link. +func (f *File) Link(token string) string { + return fmt.Sprintf(config.APIFileEndpoint, token, f.FilePath) +} + +// GetFile Get basic information about a file and prepare it for downloading. +// For the moment, bots can download files of up to 20MB in size. +// On success, a File object is returned. +// The file can then be downloaded via the link https://api.telegram.org/file/bot/, +// where is taken from the response. +// It is guaranteed that the link will be valid for at least 1 hour. +// When the link expires, a new one can be requested by calling getFile again. +// Note: This function may not preserve the original file name and MIME type. +// You should save the file's MIME type and name (if available) when the File object is received. +type GetFile struct { + FileID string // required +} + +func (s *GetFile) Params() (Params, error) { + params := make(Params, 1) + + params["file_id"] = s.FileID + + return params, nil +} +func (s *GetFile) EndPoint() string { + return config.EndpointGetFile +} + +// BanChatMember Ban a user in a group, a supergroup or a channel. +// In the case of supergroups and channels, +// the user will not be able to return to the chat on their own using invite links, etc., +// unless unbanned first. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +type BanChatMember struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + UserID int64 // required + UntilDate int64 + RevokeMessages bool +} + +func (s *BanChatMember) Params() (Params, error) { + params := make(Params, 4) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params.AddNonZero64("until_date", s.UntilDate) + params.AddBool("revoke_messages", s.RevokeMessages) + + return params, nil +} +func (s *BanChatMember) EndPoint() string { + return config.EndpointBanChatMember +} + +// UnbanChatMember Unban a previously banned user in a supergroup or channel. +// The user will not return to the group or channel automatically, +// but will be able to join via a link, etc. The bot must be an administrator for this to work. +// By default, this method guarantees that after the call the user is not a member of the chat, +// but will be able to join it. +// So if the user is a member of the chat, they will also be removed from the chat. +// If you don't want this, use the parameter only_if_banned. +// Returns True to success. +type UnbanChatMember struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + UserID int64 // required + OnlyIfBanned bool +} + +func (s *UnbanChatMember) Params() (Params, error) { + params := make(Params, 3) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params.AddBool("only_if_banned", s.OnlyIfBanned) + + return params, nil +} +func (s *UnbanChatMember) EndPoint() string { + return config.EndpointUnbanChatMember +} + +// RestrictChatMember Restrict a user in a supergroup. +// The bot must be an administrator in the supergroup for this to work +// and must have the appropriate administrator rights. +// Pass True for all permissions to lift restrictions from a user. +// Returns True to success. +type RestrictChatMember struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + UserID int64 // required + Permissions ChatPermissions // required + UseIndependentChatPermissions bool + UntilDate int64 +} + +func (s *RestrictChatMember) Params() (Params, error) { + params := make(Params, 5) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + err = params.AddAny("permissions", s.Permissions) + if err != nil { + return params, err + } + params.AddBool("use_independent_chat_permissions", s.UseIndependentChatPermissions) + params.AddNonZero64("until_date", s.UntilDate) + + return params, nil +} +func (s *RestrictChatMember) EndPoint() string { + return config.EndpointRestrictChatMember +} + +// PromoteChatMember Promote or demote a user in a supergroup or a channel. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Pass False for all boolean parameters to demote a user. +// Returns True to success. +type PromoteChatMember struct { + ChatID int64 // required. use for supergroup|channel as int + ChatIDStr string // required. use for supergroup|channel as string + Username string // required. use for supergroup|channel + UserID int64 // required + IsAnonymous bool + CanManageChat bool + CanDeleteMessages bool + CanManageVideoChats bool + CanRestrictMembers bool + CanPromoteMembers bool + CanChangeInfo bool + CanInviteUsers bool + CanPostMessages bool + CanEditMessages bool + CanPinMessages bool + CanPostStories bool + CanEditStories bool + CanDeleteStories bool + CanManageTopics bool +} + +func (s *PromoteChatMember) Params() (Params, error) { + params := make(Params, 17) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params.AddBool("is_anonymous", s.IsAnonymous) + params.AddBool("can_manage_chat", s.CanManageChat) + params.AddBool("can_delete_messages", s.CanDeleteMessages) + params.AddBool("can_manage_video_chats", s.CanManageVideoChats) + params.AddBool("can_restrict_members", s.CanRestrictMembers) + params.AddBool("can_promote_members", s.CanPromoteMembers) + params.AddBool("can_change_info", s.CanChangeInfo) + params.AddBool("can_invite_users", s.CanInviteUsers) + params.AddBool("can_post_messages", s.CanPostMessages) + params.AddBool("can_edit_messages", s.CanEditMessages) + params.AddBool("can_pin_messages", s.CanPinMessages) + params.AddBool("can_post_stories", s.CanPostStories) + params.AddBool("can_edit_stories", s.CanEditStories) + params.AddBool("can_delete_stories", s.CanDeleteStories) + params.AddBool("can_manage_topics", s.CanManageTopics) + + return params, nil +} +func (s *PromoteChatMember) EndPoint() string { + return config.EndpointPromoteChatMember +} + +// SetChatAdministratorCustomTitle Set a custom title for an administrator in a supergroup promoted by the bot. +// Returns True to success. +type SetChatAdministratorCustomTitle struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + UserID int64 // required + CustomTitle string // required +} + +func (s *SetChatAdministratorCustomTitle) Params() (Params, error) { + params := make(Params, 3) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["custom_title"] = s.CustomTitle + + return params, nil +} +func (s *SetChatAdministratorCustomTitle) EndPoint() string { + return config.EndpointSetChatAdministratorCustomTitle +} + +// BanChatSenderChat Ban a channel chat in a supergroup or a channel. +// Until the chat is unbanned, +// the owner of the banned chat won't be able to send messages on behalf of any of their channels. +// The bot must be an administrator in the supergroup or channel for this to work +// and must have the appropriate administrator rights. +// Returns True to success. +type BanChatSenderChat struct { + ChatID int64 // required. use for supergroup|channel as int + ChatIDStr string // required. use for supergroup|channel as string + Username string // required. use for supergroup|channel + SenderChatID int64 // required +} + +func (s *BanChatSenderChat) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["sender_chat_id"] = strconv.FormatInt(s.SenderChatID, 10) + + return params, nil +} +func (s *BanChatSenderChat) EndPoint() string { + return config.EndpointBanChatSenderChat +} + +// UnbanChatSenderChat Unban a previously banned channel chat in a supergroup or channel. +// The bot must be an administrator for this to work and must have the appropriate administrator rights. +// Returns True to success. +type UnbanChatSenderChat struct { + ChatID int64 // required. use for supergroup|channel as int + ChatIDStr string // required. use for supergroup|channel as string + Username string // required. use for supergroup|channel + SenderChatID int64 // required +} + +func (s *UnbanChatSenderChat) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["sender_chat_id"] = strconv.FormatInt(s.SenderChatID, 10) + + return params, nil +} +func (s *UnbanChatSenderChat) EndPoint() string { + return config.EndpointUnbanChatSenderChat +} + +// SetChatPermissions Set default chat permissions for all members. +// The bot must be an administrator in the group or a supergroup +// for this to work and must have the can_restrict_members administrator rights. +// Returns True to success. +type SetChatPermissions struct { + ChatID int64 // required. use for group|supergroup as int + ChatIDStr string // required. use for group|supergroup as string + Username string // required. use for group|supergroup + Permissions ChatPermissions // required + UseIndependentChatPermissions bool +} + +func (s *SetChatPermissions) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + err = params.AddAny("permissions", s.Permissions) + if err != nil { + return params, err + } + params.AddBool("use_independent_chat_permissions", s.UseIndependentChatPermissions) + return params, nil +} +func (s *SetChatPermissions) EndPoint() string { + return config.EndpointSetChatPermissions +} + +// ExportChatInviteLink Generate a new primary invite link for a chat; +// any previously generated primary link is revoked. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns the new invite link as String on success. +// Note: Each administrator in a chat generates their own invite links. +// Bots can't use invite links generated by other administrators. +// If you want your bot to work with invite links, +// it will need to generate its own link using exportChatInviteLink or by calling the getChat method. +// If your bot needs to generate a new primary invite link replacing its previous one, use exportChatInviteLink again. +type ExportChatInviteLink struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *ExportChatInviteLink) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *ExportChatInviteLink) EndPoint() string { + return config.EndpointExportChatInviteLink +} + +// CreateChatInviteLink Create an additional invite link for a chat. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// The link can be revoked using the method revokeChatInviteLink. +// Returns the new invite link as ChatInviteLink object. +type CreateChatInviteLink struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + Name string + ExpireDate int64 + MemberLimit int + CreatesJoinRequest bool +} + +func (s *CreateChatInviteLink) Params() (Params, error) { + params := make(Params, 5) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonEmpty("name", s.Name) + params.AddNonZero64("expire_date", s.ExpireDate) + params.AddNonZero("member_limit", s.MemberLimit) + params.AddBool("creates_join_request", s.CreatesJoinRequest) + + return params, nil +} +func (s *CreateChatInviteLink) EndPoint() string { + return config.EndpointCreateChatInviteLink +} + +// EditChatInviteLink Edit a non-primary invite link created by the bot. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns the edited invite link as a ChatInviteLink object. +type EditChatInviteLink struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + InviteLink string // required + Name string + ExpireDate int64 + MemberLimit int + CreatesJoinRequest bool +} + +func (s *EditChatInviteLink) Params() (Params, error) { + params := make(Params, 6) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["invite_link"] = s.InviteLink + params.AddNonEmpty("name", s.Name) + params.AddNonZero64("expire_date", s.ExpireDate) + params.AddNonZero("member_limit", s.MemberLimit) + params.AddBool("creates_join_request", s.CreatesJoinRequest) + + return params, nil +} +func (s *EditChatInviteLink) EndPoint() string { + return config.EndpointEditChatInviteLink +} + +// RevokeChatInviteLink Revoke an invitation link created by the bot. +// If the primary link is revoked, a new link is automatically generated. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns the revoked invite link as ChatInviteLink object. +type RevokeChatInviteLink struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + InviteLink string // required +} + +func (s *RevokeChatInviteLink) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["invite_link"] = s.InviteLink + + return params, nil +} +func (s *RevokeChatInviteLink) EndPoint() string { + return config.EndpointRevokeChatInviteLink +} + +// ApproveChatJoinRequest Approve a chat join request. +// The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. +// Returns True to success. +type ApproveChatJoinRequest struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + UserID int64 // required +} + +func (s *ApproveChatJoinRequest) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + + return params, nil +} +func (s *ApproveChatJoinRequest) EndPoint() string { + return config.EndpointApproveChatJoinRequest +} + +// DeclineChatJoinRequest Decline a chat join request. +// The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. +// Returns True to success. +type DeclineChatJoinRequest struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + UserID int64 // required +} + +func (s *DeclineChatJoinRequest) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + + return params, nil +} +func (s *DeclineChatJoinRequest) EndPoint() string { + return config.EndpointDeclineChatJoinRequest +} + +// SetChatPhoto Set a new profile photo for the chat. +// Photos can't be changed for private chats. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +type SetChatPhoto struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + Photo RequestFileData // required must be uploaded or string path + CustomFileName string +} + +func (s *SetChatPhoto) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *SetChatPhoto) Files() []RequestFile { + return []RequestFile{{ + Name: "photo", + Data: s.Photo, + FileName: s.CustomFileName, + }} +} +func (s *SetChatPhoto) EndPoint() string { + return config.EndpointSetChatPhoto +} + +// DeleteChatPhoto Delete a chat photo. +// Photos can't be changed for private chats. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +type DeleteChatPhoto struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *DeleteChatPhoto) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *DeleteChatPhoto) EndPoint() string { + return config.EndpointDeleteChatPhoto +} + +// SetChatTitle Change the title of a chat. +// Titles can't be changed for private chats. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +type SetChatTitle struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + Title string // required +} + +func (s *SetChatTitle) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["title"] = s.Title + + return params, nil +} +func (s *SetChatTitle) EndPoint() string { + return config.EndpointSetChatTitle +} + +// SetChatDescription Change the description of a group, a supergroup or a channel. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Returns True to success. +type SetChatDescription struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + Description string +} + +func (s *SetChatDescription) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonEmpty("description", s.Description) + + return params, nil +} +func (s *SetChatDescription) EndPoint() string { + return config.EndpointSetChatDescription +} + +// PinChatMessage Add a message to the list of pinned messages in a chat. +// If the chat is not a private chat, +// the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' +// administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. +// Returns True to success. +type PinChatMessage struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + MessageID int // required + DisableNotification bool +} + +func (s *PinChatMessage) Params() (Params, error) { + params := make(Params, 3) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_id"] = strconv.Itoa(s.MessageID) + params.AddBool("disable_notification", s.DisableNotification) + + return params, nil +} +func (s *PinChatMessage) EndPoint() string { + return config.EndpointPinChatMessage +} + +// UnpinChatMessage Remove a message from the list of pinned messages in a chat. +// If the chat is not a private chat, +// the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' +// administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. +// Returns True to success. +type UnpinChatMessage struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + MessageID int +} + +func (s *UnpinChatMessage) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + + return params, nil +} +func (s *UnpinChatMessage) EndPoint() string { + return config.EndpointUnpinChatMessage +} + +// UnpinAllChatMessages Clear the list of pinned messages in a chat. +// If the chat is not a private chat, +// the bot must be an administrator in the chat for this to work and must have the 'can_pin_messages' +// administrator right in a supergroup or 'can_edit_messages' administrator right in a channel. +// Returns True to success. +type UnpinAllChatMessages struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *UnpinAllChatMessages) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *UnpinAllChatMessages) EndPoint() string { + return config.EndpointUnpinAllChatMessages +} + +// LeaveChat Your bot to leave a group, supergroup or channel. Returns True to success. +type LeaveChat struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *LeaveChat) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *LeaveChat) EndPoint() string { + return config.EndpointLeaveChat +} + +// GetChat Use this method to get up-to-date information about the chat +// (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). +// Returns a Chat object on success. +type GetChat struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *GetChat) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *GetChat) EndPoint() string { + return config.EndpointGetChat +} + +// GetChatAdministrators Get a list of administrators in a chat. +// On success, +// returns an Array of ChatMember objects that contains information about all chat administrators except other bots. +// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. +type GetChatAdministrators struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *GetChatAdministrators) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *GetChatAdministrators) EndPoint() string { + return config.EndpointGetChatAdministrators +} + +// GetChatMemberCount Get the number of members in a chat. Returns Int to success. +type GetChatMemberCount struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel +} + +func (s *GetChatMemberCount) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *GetChatMemberCount) EndPoint() string { + return config.EndpointGetChatMemberCount +} + +// GetChatMember Use this method to get information about a member of a chat. +// Returns a ChatMember object on success. +type GetChatMember struct { + ChatID int64 // required. use for group|supergroup|channel as int + ChatIDStr string // required. use for group|supergroup|channel as string + Username string // required. use for group|supergroup|channel + UserID int64 // required +} + +func (s *GetChatMember) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["user_id"] = strconv.FormatInt(s.UserID, 10) + + return params, nil +} +func (s *GetChatMember) EndPoint() string { + return config.EndpointGetChatMember +} + +// SetChatStickerSet Set a new group sticker set for a supergroup. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. +// Returns True to success. +type SetChatStickerSet struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + StickerSetName string // required +} + +func (s *SetChatStickerSet) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["sticker_set_name"] = s.StickerSetName + + return params, nil +} +func (s *SetChatStickerSet) EndPoint() string { + return config.EndpointSetChatStickerSet +} + +// DeleteChatStickerSet Delete a group sticker set from a supergroup. +// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. +// Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. +// Returns True to success. +type DeleteChatStickerSet struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup +} + +func (s *DeleteChatStickerSet) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *DeleteChatStickerSet) EndPoint() string { + return config.EndpointDeleteChatStickerSet +} + +// GetForumTopicIconStickers Use this method to get custom emoji stickers, +// which can be used as a forum topic icon by any user. +// Requires no parameters. +// Returns an Array of Sticker objects. +type GetForumTopicIconStickers struct { +} + +func (s *GetForumTopicIconStickers) Params() (Params, error) { + params := make(Params) + return params, nil +} +func (s *GetForumTopicIconStickers) EndPoint() string { + return config.EndpointGetForumTopicIconStickers +} + +// CreateForumTopic Use this method to create a topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// Returns information about the created topic as a ForumTopic object. +type CreateForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + Name string // required. use for supergroup + IconColor int // Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F) + IconCustomEmojiID string // Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. +} + +func (s *CreateForumTopic) Params() (Params, error) { + params := make(Params, 4) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["name"] = s.Name + params.AddNonZero("icon_color", s.IconColor) + params.AddNonEmpty("icon_custom_emoji_id", s.IconCustomEmojiID) + return params, nil +} +func (s *CreateForumTopic) EndPoint() string { + return config.EndpointCreateForumTopic +} + +// EditForumTopic Use this method to edit the name and icon of a topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, +// unless it is the creator of the topic. +// Returns True to success. +type EditForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + MessageThreadID int64 // Required. Unique identifier for the target message thread of the forum topic + Name string // New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept + IconCustomEmojiID string // New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept +} + +func (s *EditForumTopic) Params() (Params, error) { + params := make(Params, 4) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_thread_id"] = strconv.FormatInt(s.MessageThreadID, 10) + params.AddNonEmpty("name", s.Name) + params.AddNonEmpty("icon_custom_emoji_id", s.IconCustomEmojiID) + return params, nil +} +func (s *EditForumTopic) EndPoint() string { + return config.EndpointEditForumTopic +} + +// CloseForumTopic Use this method to close an open topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights, +// unless it is the creator of the topic. +// Returns True to success. +type CloseForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + MessageThreadID int64 // Required. Unique identifier for the target message thread of the forum topic +} + +func (s *CloseForumTopic) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_thread_id"] = strconv.FormatInt(s.MessageThreadID, 10) + + return params, nil +} +func (s *CloseForumTopic) EndPoint() string { + return config.EndpointCloseForumTopic +} + +// ReopenForumTopic Use this method to reopen a closed topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights, +// unless it is the creator of the topic. +// Returns True to success. +type ReopenForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + MessageThreadID int64 // Required. Unique identifier for the target message thread of the forum topic +} + +func (s *ReopenForumTopic) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_thread_id"] = strconv.FormatInt(s.MessageThreadID, 10) + + return params, nil +} +func (s *ReopenForumTopic) EndPoint() string { + return config.EndpointReopenForumTopic +} + +// DeleteForumTopic Use this method to delete a forum topic along with all its messages in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_delete_messages administrator rights. +// Returns True to success. +type DeleteForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + MessageThreadID int64 // Required. Unique identifier for the target message thread of the forum topic +} + +func (s *DeleteForumTopic) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_thread_id"] = strconv.FormatInt(s.MessageThreadID, 10) + + return params, nil +} +func (s *DeleteForumTopic) EndPoint() string { + return config.EndpointDeleteForumTopic +} + +// UnpinAllForumTopicMessages Use this method to clear the list of pinned messages in a forum topic. +// The bot must be an administrator in the chat for this to work +// and must have the can_pin_messages administrator right in the supergroup. +// Returns True to success. +type UnpinAllForumTopicMessages struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + MessageThreadID int64 // required. Unique identifier for the target message thread of the forum topic +} + +func (s *UnpinAllForumTopicMessages) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_thread_id"] = strconv.FormatInt(s.MessageThreadID, 10) + + return params, nil +} +func (s *UnpinAllForumTopicMessages) EndPoint() string { + return config.EndpointUnpinAllForumTopicMessages +} + +// EditGeneralForumTopic Use this method to edit the name of the 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. +// Returns True to success. +type EditGeneralForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup + Name string // Required. New topic name, 1-128 characters +} + +func (s *EditGeneralForumTopic) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["name"] = s.Name + + return params, nil +} +func (s *EditGeneralForumTopic) EndPoint() string { + return config.EndpointEditGeneralForumTopic +} + +// CloseGeneralForumTopic Use this method to close an open 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// Returns True to success. +type CloseGeneralForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup +} + +func (s *CloseGeneralForumTopic) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + return params, err +} +func (s *CloseGeneralForumTopic) EndPoint() string { + return config.EndpointCloseGeneralForumTopic +} + +// ReopenGeneralForumTopic Use this method to reopen a closed 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// The topic will be automatically unhidden if it was hidden. +// Returns True to success. +type ReopenGeneralForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup +} + +func (s *ReopenGeneralForumTopic) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + return params, err +} +func (s *ReopenGeneralForumTopic) EndPoint() string { + return config.EndpointReopenGeneralForumTopic +} + +// HideGeneralForumTopic Use this method to hide the 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// The topic will be automatically closed if it is open. +// Returns True to success. +type HideGeneralForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup +} + +func (s *HideGeneralForumTopic) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + return params, err +} +func (s *HideGeneralForumTopic) EndPoint() string { + return config.EndpointHideGeneralForumTopic +} + +// UnHideGeneralForumTopic Use this method to unhide the 'General' topic in a forum supergroup chat. +// The bot must be an administrator in the chat for this to work +// and must have the can_manage_topics administrator rights. +// Returns True to success. +type UnHideGeneralForumTopic struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup +} + +func (s *UnHideGeneralForumTopic) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + return params, err +} +func (s *UnHideGeneralForumTopic) EndPoint() string { + return config.EndpointUnHideGeneralForumTopic +} + +// UnpinAllGeneralForumTopicMessages Use this method to clear the list of pinned messages in a General forum topic. +// The bot must be an administrator in the chat for this to work +// and must have the can_pin_messages administrator right in the supergroup. +// Returns True to success. +type UnpinAllGeneralForumTopicMessages struct { + ChatID int64 // required. use for supergroup as int + ChatIDStr string // required. use for supergroup as string + Username string // required. use for supergroup +} + +func (s *UnpinAllGeneralForumTopicMessages) Params() (Params, error) { + params := make(Params, 1) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + return params, err +} +func (s *UnpinAllGeneralForumTopicMessages) EndPoint() string { + return config.EndpointUnpinAllGeneralForumTopicMessages +} + +// AnswerCallbackQuery Send answers to callback queries sent from inline keyboards. +// The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. +// On success, True is returned. +// Alternatively, the user can be redirected to the specified Game URL. +// For this option to work, you must first create a game for your bot via @BotFather and accept the terms. +// Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter. +type AnswerCallbackQuery struct { + CallbackQueryID string // required + Text string + ShowAlert bool + URL string + CacheTime int +} + +func (s *AnswerCallbackQuery) Params() (Params, error) { + params := make(Params, 5) + + params["callback_query_id"] = s.CallbackQueryID + params.AddNonEmpty("text", s.Text) + params.AddBool("show_alert", s.ShowAlert) + params.AddNonEmpty("url", s.URL) + params.AddNonZero("cache_time", s.CacheTime) + + return params, nil +} +func (s *AnswerCallbackQuery) EndPoint() string { + return config.EndpointAnswerCallbackQuery +} + +// GetUserChatBoosts Get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object. +type GetUserChatBoosts struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + UserID int64 // required +} + +func (s GetUserChatBoosts) Params() (Params, error) { + params := make(Params, 2) + + params.AddAt(s.Username) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("user_id", s.UserID) + + return params, nil +} +func (s GetUserChatBoosts) EndPoint() string { + return config.EndpointGetUserChatBoosts +} + +// GetBusinessConnection Get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object. +type GetBusinessConnection struct { + BusinessConnectionId string // required. unique identifier of the business connection +} + +func (s GetBusinessConnection) Params() (Params, error) { + params := make(Params, 1) + + params["business_connection_id"] = s.BusinessConnectionId + + return params, nil +} +func (s GetBusinessConnection) EndPoint() string { + return config.EndpointGetBusinessConnection +} + +// SetMyCommands Change the list of the bot's commands. +// See https://core.telegram.org/bots#commands for more details about bot commands. +// Returns True to success. +type SetMyCommands struct { + Commands []BotCommand // required + Scope *BotCommandScope + LanguageCode string +} + +func (s *SetMyCommands) Params() (Params, error) { + params := make(Params, 3) + + err := params.AddAny("commands", s.Commands) + if err != nil { + return params, err + } + err = params.AddAny("scope", s.Scope) + if err != nil { + return params, err + } + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *SetMyCommands) EndPoint() string { + return config.EndpointSetMyCommands +} + +// DeleteMyCommands Delete the list of the bot's commands for the given scope and user language. +// After deletion, higher level commands will be shown to affected users. +// Returns True to success. +type DeleteMyCommands struct { + Scope *BotCommandScope + LanguageCode string +} + +func (s *DeleteMyCommands) Params() (Params, error) { + params := make(Params, 2) + + err := params.AddAny("scope", s.Scope) + if err != nil { + return params, err + } + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *DeleteMyCommands) EndPoint() string { + return config.EndpointDeleteMyCommands +} + +// GetMyCommands Get the current list of the bot's commands for the given scope and user language. +// Returns Array of BotCommand on success. +// If commands aren't set, an empty list is returned. +type GetMyCommands struct { + Scope *BotCommandScope + LanguageCode string +} + +func (s *GetMyCommands) Params() (Params, error) { + params := make(Params, 2) + + err := params.AddAny("scope", s.Scope) + if err != nil { + return params, err + } + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *GetMyCommands) EndPoint() string { + return config.EndpointGetMyCommands +} + +// SetMyName Change the bot's name. Returns True to success. +type SetMyName struct { + Name string + LanguageCode string +} + +func (s *SetMyName) Params() (Params, error) { + params := make(Params, 2) + + params.AddNonEmpty("name", s.Name) + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *SetMyName) EndPoint() string { + return config.EndpointSetMyName +} + +// GetMyName Get the current bot name for the given user language. Returns BotName on success. +type GetMyName struct { + LanguageCode string +} + +func (s *GetMyName) Params() (Params, error) { + params := make(Params, 1) + + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *GetMyName) EndPoint() string { + return config.EndpointGetMyName +} + +// SetMyDescription Change the bot's description, which is shown in the chat with the bot if the chat is empty. +// Returns True to success. +type SetMyDescription struct { + Description string + LanguageCode string +} + +func (s *SetMyDescription) Params() (Params, error) { + params := make(Params, 2) + + params.AddNonEmpty("description", s.Description) + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *SetMyDescription) EndPoint() string { + return config.EndpointSetMyDescription +} + +// GetMyDescription Get the current bot description for the given user language. +// Returns BotDescription on success. +type GetMyDescription struct { + LanguageCode string +} + +func (s *GetMyDescription) Params() (Params, error) { + params := make(Params, 1) + + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *GetMyDescription) EndPoint() string { + return config.EndpointGetMyDescription +} + +// SetMyShortDescription Change the bot's short description, +// which is shown on the bot's profile page and is sent together with the link when users share the bot. +// Returns True to success. +type SetMyShortDescription struct { + ShortDescription string + LanguageCode string +} + +func (s *SetMyShortDescription) Params() (Params, error) { + params := make(Params, 2) + + params.AddNonEmpty("short_description", s.ShortDescription) + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *SetMyShortDescription) EndPoint() string { + return config.EndpointSetMyShortDescription +} + +// GetMyShortDescription Get the current bot short description for the given user language. +// Returns BotShortDescription on success. +type GetMyShortDescription struct { + LanguageCode string +} + +func (s *GetMyShortDescription) Params() (Params, error) { + params := make(Params, 1) + + params.AddNonEmpty("language_code", s.LanguageCode) + + return params, nil +} +func (s *GetMyShortDescription) EndPoint() string { + return config.EndpointGetMyShortDescription +} + +// SetChatMenuButton Change the bot's menu button in a private chat, or the default menu button. +// Returns True to success. +type SetChatMenuButton struct { + ChatID int64 // required. use for chat|channel as int + ChatIDStr string // required. use for chat|channel as string + Username string // required. use for chat|channel + + MenuButton *MenuButton +} + +func (s *SetChatMenuButton) Params() (Params, error) { + params := make(Params, 2) + + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + err = params.AddAny("menu_button", s.MenuButton) + + return params, err +} +func (s *SetChatMenuButton) EndPoint() string { + return config.EndpointSetChatMenuButton +} + +// GetChatMenuButton Get the current value of the bot's menu button in a private chat, +// or the default menu button. +// Returns MenuButton on success. +type GetChatMenuButton struct { + ChatID int64 // required. use for chat|channel as int + ChatIDStr string // required. use for chat|channel as string + Username string // required. use for chat|channel +} + +func (s *GetChatMenuButton) Params() (Params, error) { + params := make(Params, 1) + + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + + return params, err +} +func (s *GetChatMenuButton) EndPoint() string { + return config.EndpointGetChatMenuButton +} + +// SetMyDefaultAdministratorRights Change the default administrator rights requested by the bot +// when it's added as an administrator to groups or channels. +// These rights will be suggested to users, but they are free to modify the list before adding the bot. +// Returns True to success. +type SetMyDefaultAdministratorRights struct { + Rights *ChatAdministratorRights + ForChannels bool +} + +func (s *SetMyDefaultAdministratorRights) Params() (Params, error) { + params := make(Params, 2) + + err := params.AddAny("rights", s.Rights) + if err != nil { + return params, err + } + params.AddBool("for_channels", s.ForChannels) + + return params, nil +} +func (s *SetMyDefaultAdministratorRights) EndPoint() string { + return config.EndpointSetMyDefaultAdministratorRights +} + +// GetMyDefaultAdministratorRights Get the current default administrator rights of the bot. +// Returns ChatAdministratorRights on success. +type GetMyDefaultAdministratorRights struct { + ForChannels bool +} + +func (s *GetMyDefaultAdministratorRights) Params() (Params, error) { + params := make(Params, 1) + + params.AddBool("for_channels", s.ForChannels) + + return params, nil +} +func (s *GetMyDefaultAdministratorRights) EndPoint() string { + return config.EndpointGetMyDefaultAdministratorRights +} + +// EditMessageText Edit text and game messages. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +type EditMessageText struct { + BusinessConnectionId string + ChatID int64 // required if InlineMessageID is not specified. use for chat|channel as int + ChatIDStr string // required if InlineMessageID is not specified. use for chat|channel as string + Username string // required if InlineMessageID is not specified. use for chat|channel + MessageID int // required if InlineMessageID is not specified + InlineMessageID string // required if ChatID|Username & MessageID are not specified + Text string // required + ParseMode string + Entities []MessageEntity + LinkPreviewOptions *LinkPreviewOptions + ReplyMarkup any // only InlineKeyboardMarkup +} + +func (s *EditMessageText) Params() (Params, error) { + var params Params + + if s.InlineMessageID == "" { + params = make(Params, 8) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + } else { + params = make(Params, 7) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["inline_message_id"] = s.InlineMessageID + } + params["text"] = s.Text + params.AddNonEmpty("parse_mode", s.ParseMode) + err := params.AddAny("entities", s.Entities) + if err != nil { + return params, err + } + err = params.AddAny("link_preview_options", s.LinkPreviewOptions) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *EditMessageText) EndPoint() string { + return config.EndpointEditMessageText +} + +// EditMessageCaption Edit captions of messages. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +type EditMessageCaption struct { + BusinessConnectionId string + ChatID int64 // required if InlineMessageID is not specified. use for chat|channel as int + ChatIDStr string // required if InlineMessageID is not specified. use for chat|channel as string + Username string // required if InlineMessageID is not specified. use for chat|channel + MessageID int // required if InlineMessageID is not specified + InlineMessageID string // required if ChatID|Username & MessageID are not specified + Caption string + ParseMode string + CaptionEntities []MessageEntity + ShowCaptionAboveMedia bool + ReplyMarkup any // only InlineKeyboardMarkup +} + +func (s *EditMessageCaption) Params() (Params, error) { + var params Params + + if s.InlineMessageID == "" { + params = make(Params, 8) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + } else { + params = make(Params, 7) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["inline_message_id"] = s.InlineMessageID + } + params.AddNonEmpty("caption", s.Caption) + params.AddNonEmpty("parse_mode", s.ParseMode) + err := params.AddAny("caption_entities", s.CaptionEntities) + if err != nil { + return params, err + } + params.AddBool("show_caption_above_media", s.ShowCaptionAboveMedia) + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *EditMessageCaption) EndPoint() string { + return config.EndpointEditMessageCaption +} + +// EditMessageMedia Edit animation, audio, document, photo, or video messages. +// If a message is part of a message album, then it can be edited only to an audio for audio albums, +// only to a document for document albums and to a photo or a video otherwise. +// When an inline message is edited, a new file can't be uploaded; +// use a previously uploaded file via its file_id or specify a URL. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +type EditMessageMedia struct { + BusinessConnectionId string + ChatID int64 // required if InlineMessageID is not specified. use for chat|channel as int + ChatIDStr string // required if InlineMessageID is not specified. use for chat|channel as string + Username string // required if InlineMessageID is not specified. use for chat|channel + MessageID int // required if InlineMessageID is not specified + InlineMessageID string // required if ChatID|Username & MessageID are not specified + Media any // required + ReplyMarkup any // only InlineKeyboardMarkup +} + +func (s *EditMessageMedia) Params() (Params, error) { + var params Params + + if s.InlineMessageID == "" { + params = make(Params, 5) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + } else { + params = make(Params, 4) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["inline_message_id"] = s.InlineMessageID + } + err := params.AddAny("media", prepareInputMediaParam(s.Media, 0)) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *EditMessageMedia) Files() []RequestFile { + return prepareInputMediaFile(s.Media, 0) +} +func (s *EditMessageMedia) EndPoint() string { + return config.EndpointEditMessageMedia +} + +// EditMessageReplyMarkup Edit only the reply markup of messages. +// On success, if the edited message is not an inline message, the edited Message is returned; +// otherwise True is returned. +type EditMessageReplyMarkup struct { + BusinessConnectionId string + ChatID int64 // required if InlineMessageID is not specified. use for chat|channel as int + ChatIDStr string // required if InlineMessageID is not specified. use for chat|channel as string + Username string // required if InlineMessageID is not specified. use for chat|channel + MessageID int // required if InlineMessageID is not specified + InlineMessageID string // required if ChatID|Username & MessageID are not specified + ReplyMarkup any // only InlineKeyboardMarkup +} + +func (s *EditMessageReplyMarkup) Params() (Params, error) { + var params Params + + if s.InlineMessageID == "" { + params = make(Params, 4) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + } else { + params = make(Params, 3) + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["inline_message_id"] = s.InlineMessageID + } + err := params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *EditMessageReplyMarkup) EndPoint() string { + return config.EndpointEditMessageReplyMarkup +} + +// StopPoll Stop a poll which was sent by the bot. On success, the stopped Poll is returned +type StopPoll struct { + BusinessConnectionId string + ChatID int64 // required. use for chat|channel as int + ChatIDStr string // required. use for chat|channel as string + Username string // required. use for chat|channel + MessageID int // required + ReplyMarkup any // only InlineKeyboardMarkup +} + +func (s *StopPoll) Params() (Params, error) { + params := make(Params, 4) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero("message_id", s.MessageID) + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *StopPoll) EndPoint() string { + return config.EndpointStopPoll +} + +// DeleteMessage Use this method to delete a message, including service messages, with the following limitations: +// 1. A message can only be deleted if it was sent less than 48 hours ago. +// 2. Service messages about a supergroup, channel, or forum topic creation can't be deleted. +// 3. A dice message in a private chat can only be deleted if it was sent more than 24 hours ago. +// 4. Bots can delete outgoing messages in private chats, groups, and supergroups. +// 5. Bots can delete incoming messages in private chats. +// 6. Bots granted can_post_messages permissions can delete outgoing messages in channels. +// 7. If the bot is an administrator of a group, it can delete any message there. +// 8. If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. +// Returns True to success. +type DeleteMessage struct { + ChatID int64 // required. use for chat|channel as int + ChatIDStr string // required. use for chat|channel as string + Username string // required. use for chat|channel + MessageID int // required +} + +func (s *DeleteMessage) Params() (Params, error) { + params := make(Params, 2) + + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params["message_id"] = strconv.Itoa(s.MessageID) + + return params, nil +} +func (s *DeleteMessage) EndPoint() string { + return config.EndpointDeleteMessage +} + +// DeleteMessages Delete a message, including service messages, with the following limitations. Returns True on success. +type DeleteMessages struct { + ChatID int64 // required. use for chat|channel as int + ChatIDStr string // required. use for chat|channel as string + Username string // required. use for chat|channel + MessageIds []int // required +} + +func (s DeleteMessages) Params() (Params, error) { + params := make(Params, 2) + + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + err = params.AddAny("message_ids", s.MessageIds) + + return params, nil +} +func (s DeleteMessages) EndPoint() string { + return config.EndpointDeleteMessages +} + +// SendSticker Send static .WEBP, animated .TGS, or video .WEBM stickers. +// On success, the sent Message is returned. +type SendSticker struct { + BusinessConnectionId string // + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Sticker RequestFileData //required. + Emoji string + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any + CustomFileName string +} + +func (s *SendSticker) Params() (Params, error) { + params := make(Params, 9) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params.AddNonEmpty("emoji", s.Emoji) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, nil +} +func (s *SendSticker) Files() []RequestFile { + files := []RequestFile{{ + Name: "sticker", + Data: s.Sticker, + FileName: s.CustomFileName, + }} + + return files +} +func (s *SendSticker) EndPoint() string { + return config.EndpointSendSticker +} + +// GetStickerSet Get a sticker set. On success, a StickerSet object is returned. +type GetStickerSet struct { + Name string // required +} + +func (s *GetStickerSet) Params() (Params, error) { + params := make(Params, 1) + + params["name"] = s.Name + + return params, nil +} +func (s *GetStickerSet) EndPoint() string { + return config.EndpointGetStickerSet +} + +// GetCustomEmojiStickers Get information about custom emoji stickers by their identifiers. +// Returns an Array of Sticker objects. +type GetCustomEmojiStickers struct { + CustomEmojiIds []string // required +} + +func (s *GetCustomEmojiStickers) Params() (Params, error) { + params := make(Params, 1) + + err := params.AddAny("custom_emoji_ids", s.CustomEmojiIds) + + return params, err +} +func (s *GetCustomEmojiStickers) EndPoint() string { + return config.EndpointGetCustomEmojiStickers +} + +// UploadStickerFile Upload a file with a sticker for later use in the createNewStickerSet +// and addStickerToSet methods (the file can be used multiple times). +// Returns the uploaded File on success. +type UploadStickerFile struct { + UserID int64 // required + Sticker RequestFileData // required + StickerFormat string // required + CustomFileName string +} + +func (s *UploadStickerFile) Params() (Params, error) { + params := make(Params, 2) + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["sticker_format"] = s.StickerFormat + + return params, nil +} +func (s *UploadStickerFile) Files() []RequestFile { + return []RequestFile{{ + Name: "sticker", + Data: s.Sticker, + FileName: s.CustomFileName, + }} +} +func (s *UploadStickerFile) EndPoint() string { + return config.EndpointUploadStickerFile +} + +// CreateNewStickerSet Create a new sticker set owned by a user. +// The bot will be able to edit the sticker set thus created. +// Returns True to success. +type CreateNewStickerSet struct { + UserID int64 // required + Name string // required + Title string // required + Stickers []any // required + StickerType string + NeedsRepainting bool +} + +func (s *CreateNewStickerSet) Params() (Params, error) { + params := make(Params, 6) + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["name"] = s.Name + params["title"] = s.Title + err := params.AddAny("stickers", prepareInputStickerForParams(s.Stickers)) + if err != nil { + return nil, err + } + params.AddNonEmpty("sticker_type", s.StickerType) + params.AddBool("needs_repainting", s.NeedsRepainting) + + return params, nil +} +func (s *CreateNewStickerSet) Files() []RequestFile { + return prepareInputStickerForFiles(s.Stickers) +} +func (s *CreateNewStickerSet) EndPoint() string { + return config.EndpointCreateNewStickerSet +} + +// prepareInputStickerParam evaluates a InputSticker and determines if it needs to be modified for a successful upload. +// If it returns nil, then the value does not need to be included in the params. +// Otherwise, it will return the same type as was originally provided. +// The idx is used to calculate the file field name. +// If you only have a single file, 0 may be used. +// It is formatted into "attach://file-%d" for the primary sticker. +// It is expected to be used in conjunction with prepareInputStickerFile. +func prepareInputStickerParam(inputSticker any, idx int) any { + switch m := inputSticker.(type) { + case InputSticker: + if m.Sticker.NeedsUpload() { + m.Sticker = FileAttach(fmt.Sprintf("attach://file-%d", idx)) + } + + return m + } + + return nil +} + +// prepareInputStickerFile generates an array of RequestFile to provide for Fileable files method. +// It returns an array as an InputSticker may have multiple files for the primary sticker. +// The idx parameter is used to generate file field names. +// It uses the names "file-%d" for the main file. +// It is expected to be used in conjunction with prepareInputStickerParam. +func prepareInputStickerFile(inputSticker any, idx int) []RequestFile { + var files []RequestFile + + switch m := inputSticker.(type) { + case InputSticker: + if m.Sticker.NeedsUpload() { + files = append(files, RequestFile{ + Name: fmt.Sprintf("file-%d", idx), + Data: m.Sticker, + }) + } + } + + return files +} + +// prepareInputStickerForParams calls prepareInputStickerParam for each item provided +// and returns a new array with the correct params for a request. +// It is expected that files will get data from the associated function, prepareInputStickerForFiles. +func prepareInputStickerForParams(inputSticker []any) []any { + newSticker := make([]any, len(inputSticker)) + copy(newSticker, inputSticker) + + for idx, sticker := range inputSticker { + if param := prepareInputStickerParam(sticker, idx); param != nil { + newSticker[idx] = param + } + } + + return newSticker +} + +// prepareInputStickerForFiles calls prepareInputStickerFile for each item provided +// and returns a new array with the correct files for a request. +// It is expected that params will get data from the associated function, prepareInputStickerForParams. +func prepareInputStickerForFiles(inputSticker []any) []RequestFile { + var files []RequestFile + + for idx, sticker := range inputSticker { + if file := prepareInputStickerFile(sticker, idx); file != nil { + files = append(files, file...) + } + } + + return files +} + +// AddStickerToSet Add a new sticker to a set created by the bot. +// The format of the added sticker must match the format of the other stickers in the set. +// Emoji sticker sets can have up to 200 stickers. +// Animated and video sticker sets can have up to 50 stickers. +// Static sticker sets can have up to 120 stickers. +// Returns True to success. +type AddStickerToSet struct { + UserID int64 // required + Name string // required + Sticker InputSticker // required +} + +func (s *AddStickerToSet) Params() (Params, error) { + params := make(Params, 3) + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["name"] = s.Name + err := params.AddAny("stickers", prepareInputStickerParam(s.Sticker, 0)) + + return params, err +} +func (s *AddStickerToSet) Files() []RequestFile { + return prepareInputStickerFile(s.Sticker, 0) +} +func (s *AddStickerToSet) EndPoint() string { + return config.EndpointAddStickerToSet +} + +// SetStickerPositionInSet Move a sticker in a set created by the bot to a specific position. +// Returns True to success. +type SetStickerPositionInSet struct { + Sticker string // required + Position int // required +} + +func (s *SetStickerPositionInSet) Params() (Params, error) { + params := make(Params, 2) + + params["sticker"] = s.Sticker + params["position"] = strconv.Itoa(s.Position) + + return params, nil +} +func (s *SetStickerPositionInSet) EndPoint() string { + return config.EndpointSetStickerPositionInSet +} + +// DeleteStickerFromSet Delete a sticker from a set created by the bot. +// Returns True to success. +type DeleteStickerFromSet struct { + Sticker string // required +} + +func (s *DeleteStickerFromSet) Params() (Params, error) { + params := make(Params, 1) + + params["sticker"] = s.Sticker + + return params, nil +} +func (s *DeleteStickerFromSet) EndPoint() string { + return config.EndpointDeleteStickerFromSet +} + +// ReplaceStickerInSet Replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. +// Returns True to success. +type ReplaceStickerInSet struct { + UserID int64 // required + Name string // required + OldSticker string // required + Sticker InputSticker // required +} + +func (s *ReplaceStickerInSet) Params() (Params, error) { + params := make(Params, 4) + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["name"] = s.Name + params["old_sticker"] = s.OldSticker + err := params.AddAny("stickers", prepareInputStickerParam(s.Sticker, 0)) + + return params, err +} +func (s *ReplaceStickerInSet) Files() []RequestFile { + return prepareInputStickerFile(s.Sticker, 0) +} +func (s *ReplaceStickerInSet) EndPoint() string { + return config.EndpointReplaceStickerInSet +} + +// SetStickerEmojiList Change the list of emoji assigned to a regular or custom emoji sticker. +// The sticker must belong to a sticker set created by the bot. +// Returns True to success. +type SetStickerEmojiList struct { + Sticker string // required + EmojiList []string // required +} + +func (s *SetStickerEmojiList) Params() (Params, error) { + params := make(Params, 2) + + params["sticker"] = s.Sticker + err := params.AddAny("emoji_list", s.EmojiList) + + return params, err +} +func (s *SetStickerEmojiList) EndPoint() string { + return config.EndpointSetStickerEmojiList +} + +// SetStickerKeywords Change search keywords assigned to a regular or custom emoji sticker. +// The sticker must belong to a sticker set created by the bot. +// Returns True to success. +type SetStickerKeywords struct { + Sticker string // required + Keywords []string // required +} + +func (s *SetStickerKeywords) Params() (Params, error) { + params := make(Params, 2) + + params["sticker"] = s.Sticker + err := params.AddAny("keywords", s.Keywords) + + return params, err +} +func (s *SetStickerKeywords) EndPoint() string { + return config.EndpointSetStickerKeywords +} + +// SetStickerMaskPosition Change the mask position of a mask sticker. +// The sticker must belong to a sticker set that was created by the bot. +// Returns True to success. +type SetStickerMaskPosition struct { + Sticker string // required + MaskPosition *MaskPosition +} + +func (s *SetStickerMaskPosition) Params() (Params, error) { + params := make(Params, 2) + + params["sticker"] = s.Sticker + err := params.AddAny("mask_position", s.MaskPosition) + + return params, err +} +func (s *SetStickerMaskPosition) EndPoint() string { + return config.EndpointSetStickerMaskPosition +} + +// SetStickerSetTitle Set the title of a created sticker set. Returns True to success. +type SetStickerSetTitle struct { + Name string // required + Title string // required +} + +func (s *SetStickerSetTitle) Params() (Params, error) { + params := make(Params, 2) + + params["name"] = s.Name + params["title"] = s.Title + + return params, nil +} +func (s *SetStickerSetTitle) EndPoint() string { + return config.EndpointSetStickerSetTitle +} + +// SetStickerSetThumbnail Set the thumbnail of a regular or mask sticker set. +// The format of the thumbnail file must match the format of the stickers in the set. +// Returns True to success. +type SetStickerSetThumbnail struct { + Name string // required + UserID int64 // required + Thumbnail RequestFileData + ThumbnailCustomFileName string + Format string // required +} + +func (s *SetStickerSetThumbnail) Params() (Params, error) { + params := make(Params, 3) + + params["name"] = s.Name + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["format"] = s.Format + + return params, nil +} +func (s *SetStickerSetThumbnail) Files() []RequestFile { + if s.Thumbnail != nil { + return []RequestFile{ + { + Name: "thumb", + Data: s.Thumbnail, + FileName: s.ThumbnailCustomFileName, + }, + { + Name: "thumbnail", + Data: s.Thumbnail, + FileName: s.ThumbnailCustomFileName, + }, + } + } + + return nil +} +func (s *SetStickerSetThumbnail) EndPoint() string { + return config.EndpointSetStickerSetThumbnail +} + +// SetCustomEmojiStickerSetThumbnail Set the thumbnail of a custom emoji sticker set. +// Returns True to success. +type SetCustomEmojiStickerSetThumbnail struct { + Name string // required + CustomEmojiId string +} + +func (s *SetCustomEmojiStickerSetThumbnail) Params() (Params, error) { + params := make(Params, 2) + + params["name"] = s.Name + params.AddNonEmpty("custom_emoji_id", s.CustomEmojiId) + + return params, nil +} +func (s *SetCustomEmojiStickerSetThumbnail) EndPoint() string { + return config.EndpointSetCustomEmojiStickerSetThumbnail +} + +// DeleteStickerSet Delete a sticker set that was created by the bot. +// Returns True to success. +type DeleteStickerSet struct { + Name string // required +} + +func (s *DeleteStickerSet) Params() (Params, error) { + params := make(Params, 1) + + params["name"] = s.Name + + return params, nil +} +func (s *DeleteStickerSet) EndPoint() string { + return config.EndpointDeleteStickerSet +} + +// AnswerInlineQuery Send answers to an inline query. +// On success, True is returned. +// No more than 50 results per query are allowed. +type AnswerInlineQuery struct { + InlineQueryID string // required + Results []any // required + CacheTime int + IsPersonal bool + NextOffset string + Button *InlineQueryResultsButton + SwitchPMText string `json:"switch_pm_text"` + SwitchPMParameter string `json:"switch_pm_parameter"` +} + +func (s *AnswerInlineQuery) Params() (Params, error) { + params := make(Params, 8) + + params["inline_query_id"] = s.InlineQueryID + err := params.AddAny("results", s.Results) + if err != nil { + return nil, err + } + params.AddNonZero("cache_time", s.CacheTime) + params.AddBool("is_personal", s.IsPersonal) + params.AddNonEmpty("next_offset", s.NextOffset) + err = params.AddAny("button", s.Button) + if err != nil { + return nil, err + } + params.AddNonEmpty("switch_pm_text", s.SwitchPMText) + params.AddNonEmpty("switch_pm_parameter", s.SwitchPMParameter) + + return params, err +} +func (s *AnswerInlineQuery) EndPoint() string { + return config.EndpointAnswerInlineQuery +} + +// AnswerWebAppQuery Set the result of an interaction with a Web App +// and send a corresponding message on behalf of the user to the chat from which the query originated. +// On success, a SentWebAppMessage object is returned. +type AnswerWebAppQuery struct { + WebAppQueryID string // required + Result any // required +} + +func (s *AnswerWebAppQuery) Params() (Params, error) { + params := make(Params, 2) + + params["web_app_query_id"] = s.WebAppQueryID + err := params.AddAny("result", s.Result) + + return params, err +} +func (s *AnswerWebAppQuery) EndPoint() string { + return config.EndpointAnswerWebAppQuery +} + +// SendInvoice Send invoices. On success, the sent Message is returned. +type SendInvoice struct { + ChatID int64 // required. use for user|channel as int + ChatIDStr string // required. use for user|channel as string + Username string // required. use for channel + MessageThreadID int64 + Title string // required + Description string // required + Payload string // required + ProviderToken string + Currency string // required + Prices []LabeledPrice // required + MaxTipAmount int + SuggestedTipAmounts []int + StartParameter string + ProviderData string + PhotoURL string + PhotoSize int64 + PhotoWidth int + PhotoHeight int + NeedName bool + NeedPhoneNumber bool + NeedEmail bool + NeedShippingAddress bool + SendPhoneNumberToProvider bool + SendEmailToProvider bool + IsFlexible bool + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup any +} + +func (s *SendInvoice) Params() (Params, error) { + params := make(Params, 28) + + err := params.AddFirstValid("chat_id", s.ChatID, s.ChatIDStr, s.Username) + if err != nil { + return params, err + } + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["title"] = s.Title + params["description"] = s.Description + params["payload"] = s.Payload + params.AddNonEmpty("provider_token", s.ProviderToken) + params["currency"] = s.Currency + err = params.AddAny("prices", s.Prices) + if err != nil { + return params, err + } + params.AddNonZero("max_tip_amount", s.MaxTipAmount) + err = params.AddAny("suggested_tip_amounts", s.SuggestedTipAmounts) + if err != nil { + return params, err + } + params.AddNonEmpty("start_parameter", s.StartParameter) + params.AddNonEmpty("provider_data", s.ProviderData) + params.AddNonEmpty("photo_url", s.PhotoURL) + params.AddNonZero64("photo_size", s.PhotoSize) + params.AddNonZero("photo_width", s.PhotoWidth) + params.AddNonZero("photo_height", s.PhotoHeight) + params.AddBool("need_name", s.NeedName) + params.AddBool("need_phone_number", s.NeedPhoneNumber) + params.AddBool("need_email", s.NeedEmail) + params.AddBool("need_shipping_address", s.NeedShippingAddress) + params.AddBool("send_phone_number_to_provider", s.SendPhoneNumberToProvider) + params.AddBool("send_email_to_provider", s.SendEmailToProvider) + params.AddBool("is_flexible", s.IsFlexible) + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err = params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + return params, nil +} +func (s *SendInvoice) EndPoint() string { + return config.EndpointSendInvoice +} + +// CreateInvoiceLink Create a link for an invoice. +// Returns the created invoice link as String on success. +type CreateInvoiceLink struct { + Title string // required + Description string // required + Payload string // required + ProviderToken string + Currency string // required + Prices []LabeledPrice // required + MaxTipAmount int + SuggestedTipAmounts []int + ProviderData string + PhotoURL string + PhotoSize int64 + PhotoWidth int + PhotoHeight int + NeedName bool + NeedPhoneNumber bool + NeedEmail bool + NeedShippingAddress bool + SendPhoneNumberToProvider bool + SendEmailToProvider bool + IsFlexible bool +} + +func (s *CreateInvoiceLink) Params() (Params, error) { + params := make(Params, 20) + + params["title"] = s.Title + params["description"] = s.Description + params["payload"] = s.Payload + params.AddNonEmpty("provider_token", s.ProviderToken) + params["currency"] = s.Currency + err := params.AddAny("prices", s.Prices) + if err != nil { + return params, err + } + params.AddNonZero("max_tip_amount", s.MaxTipAmount) + err = params.AddAny("suggested_tip_amounts", s.SuggestedTipAmounts) + if err != nil { + return params, err + } + params.AddNonEmpty("provider_data", s.ProviderData) + params.AddNonEmpty("photo_url", s.PhotoURL) + params.AddNonZero64("photo_size", s.PhotoSize) + params.AddNonZero("photo_width", s.PhotoWidth) + params.AddNonZero("photo_height", s.PhotoHeight) + params.AddBool("need_name", s.NeedName) + params.AddBool("need_phone_number", s.NeedPhoneNumber) + params.AddBool("need_email", s.NeedEmail) + params.AddBool("need_shipping_address", s.NeedShippingAddress) + params.AddBool("is_flexible", s.IsFlexible) + params.AddBool("send_phone_number_to_provider", s.SendPhoneNumberToProvider) + params.AddBool("send_email_to_provider", s.SendEmailToProvider) + + return params, nil +} +func (s *CreateInvoiceLink) EndPoint() string { + return config.EndpointCreateInvoiceLink +} + +// AnswerShippingQuery Reply to shipping queries. On success, True is returned. +type AnswerShippingQuery struct { + ShippingQueryID string // required + OK bool // required + ShippingOptions []ShippingOption // required if ok is True + ErrorMessage string // required if ok is False +} + +func (s *AnswerShippingQuery) Params() (Params, error) { + params := make(Params, 4) + + params["shipping_query_id"] = s.ShippingQueryID + params.AddBool("ok", s.OK) + err := params.AddAny("shipping_options", s.ShippingOptions) + if err != nil { + return params, err + } + params.AddNonEmpty("error_message", s.ErrorMessage) + + return params, nil +} +func (s *AnswerShippingQuery) EndPoint() string { + return config.EndpointAnswerShippingQuery +} + +// AnswerPreCheckoutQuery Respond to such pre-checkout queries. +// On success, True is returned. +// Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. +type AnswerPreCheckoutQuery struct { + PreCheckoutQueryID string // required + OK bool // required + ErrorMessage string // required if ok is False +} + +func (s *AnswerPreCheckoutQuery) Params() (Params, error) { + params := make(Params, 3) + + params["pre_checkout_query_id"] = s.PreCheckoutQueryID + params.AddBool("ok", s.OK) + params.AddNonEmpty("error_message", s.ErrorMessage) + + return params, nil +} +func (s *AnswerPreCheckoutQuery) EndPoint() string { + return config.EndpointAnswerPreCheckoutQuery +} + +// GetStarTransactions Returns the bot's Telegram Star transactions in chronological order. +// On success, returns a StarTransactions object. +type GetStarTransactions struct { + Offset int + Limit int +} + +func (s *GetStarTransactions) Params() (Params, error) { + params := make(Params, 2) + + params.AddNonZero("offset", s.Offset) + params.AddNonZero("limit", s.Offset) + + return params, nil +} +func (s *GetStarTransactions) EndPoint() string { + return config.EndpointGetStarTransactions +} + +// RefundStarPayment Refunds a successful payment in Telegram Stars. +// Returns True on success. +type RefundStarPayment struct { + UserId string // required + TelegramPaymentChargeId string // required +} + +func (s *RefundStarPayment) Params() (Params, error) { + params := make(Params, 2) + + params["user_id"] = s.UserId + params["telegram_payment_charge_id"] = s.TelegramPaymentChargeId + + return params, nil +} +func (s *RefundStarPayment) EndPoint() string { + return config.EndpointRefundStarPayment +} + +// SetPassportDataErrors Informs a user that some of the Telegram Passport elements they provided contains errors. +// The user will not be able to re-submit their Passport to you until the errors are fixed +// (the contents of the field for which you returned the error must change). +// Returns True to success. +type SetPassportDataErrors struct { + UserID int64 // required + Errors []any // required +} + +func (s *SetPassportDataErrors) Params() (Params, error) { + params := make(Params, 2) + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + err := params.AddAny("errors", s.Errors) + + return params, err +} +func (s *SetPassportDataErrors) EndPoint() string { + return config.EndpointSetPassportDataErrors +} + +// SendGame Send a game. On success, the sent Message is returned. +type SendGame struct { + BusinessConnectionId string // + ChatID int64 // required + MessageThreadID int64 + GameShortName string // required + DisableNotification bool + ProtectContent bool + MessageEffectId string + ReplyParameters *ReplyParameters + ReplyMarkup *InlineKeyboardMarkup +} + +func (s *SendGame) Params() (Params, error) { + params := make(Params, 9) + + params.AddNonEmpty("business_connection_id", s.BusinessConnectionId) + params["chat_id"] = strconv.FormatInt(s.ChatID, 10) + params.AddNonZero64("message_thread_id", s.MessageThreadID) + params["game_short_name"] = s.GameShortName + params.AddBool("disable_notification", s.DisableNotification) + params.AddBool("protect_content", s.ProtectContent) + params.AddNonEmpty("message_effect_id", s.MessageEffectId) + err := params.AddAny("reply_parameters", s.ReplyParameters) + if err != nil { + return params, err + } + err = params.AddAny("reply_markup", s.ReplyMarkup) + + return params, err +} +func (s *SendGame) EndPoint() string { + return config.EndpointSendGame +} + +// SetGameScore Set the score of the specified user in a game message. +// On success, if the message is not an inline message, the Message is returned, otherwise True is returned. +// Returns an error, if the new score is not greater than the user's current score in the chat and force is False. +type SetGameScore struct { + UserID int64 // required + Score int // required + Force bool + DisableEditMessage bool + ChatID int64 // required if inline_message_id is not specified + MessageID int // required if inline_message_id is not specified + InlineMessageID string // required if chat_id and message_id are not specified +} + +func (s *SetGameScore) Params() (Params, error) { + var params Params + + if s.InlineMessageID != "" { + params = make(Params, 4) + params["inline_message_id"] = s.InlineMessageID + } else { + params = make(Params, 5) + params.AddNonZero64("chat_id", s.ChatID) + params.AddNonZero("message_id", s.MessageID) + } + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + params["scrore"] = strconv.Itoa(s.Score) + params.AddBool("disable_edit_message", s.DisableEditMessage) + + return params, nil +} +func (s *SetGameScore) EndPoint() string { + return config.EndpointSetGameScore +} + +// GetGameHighScores Use this method to get data for high-score tables. +// Will return the score of the specified user and several of their neighbors in a game. +// On success, returns an Array of GameHighScore objects. +// This method will currently return scores for the target user, plus two of their closest neighbors on each side. +// Will also return the top three users if the user and their neighbors are not among them. +// Please note that this behavior is subject to change. +type GetGameHighScores struct { + UserID int64 // required + ChatID int64 // required if inline_message_id is not specified + MessageID int // required if inline_message_id is not specified + InlineMessageID string // required if chat_id and message_id are not specified +} + +func (s *GetGameHighScores) Params() (Params, error) { + var params Params + + if s.InlineMessageID != "" { + params = make(Params, 2) + params["inline_message_id"] = s.InlineMessageID + } else { + params = make(Params, 3) + params.AddNonZero64("chat_id", s.ChatID) + params.AddNonZero("message_id", s.MessageID) + } + + params["user_id"] = strconv.FormatInt(s.UserID, 10) + + return params, nil +} +func (s *GetGameHighScores) EndPoint() string { + return config.EndpointGetGameHighScores +} diff --git a/types/types.go b/types/types.go new file mode 100644 index 0000000..62d76e4 --- /dev/null +++ b/types/types.go @@ -0,0 +1,2262 @@ +package types + +import ( + "encoding/json" +) + +// APIResponse is a response from the Telegram API with the result. stored raw. +type APIResponse struct { + Ok bool `json:"ok"` + Result json.RawMessage `json:"result,omitempty"` + ErrorCode int `json:"error_code,omitempty"` + Description string `json:"description,omitempty"` + Parameters *ResponseParameters `json:"parameters,omitempty"` +} + +// Update is an update response, from GetUpdates. +type Update struct { + UpdateID int `json:"update_id"` // The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you're using webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then the identifier of the next update will be chosen randomly instead of sequentially. + Message *Message `json:"message,omitempty"` // Optional. New incoming message of any kind - text, photo, sticker, etc. + EditedMessage *Message `json:"edited_message,omitempty"` // Optional. New version of a message that is known to the bot and was edited + ChannelPost *Message `json:"channel_post,omitempty"` // Optional. New incoming channel post of any kind - text, photo, sticker, etc. + EditedChannelPost *Message `json:"edited_channel_post,omitempty"` // Optional. New version of a channel post that is known to the bot and was edited + BusinessConnection *BusinessConnection `json:"business_connection,omitempty"` // Optional. The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot + BusinessMessage *Message `json:"business_message,omitempty"` // Optional. New non-service message from a connected business account + EditedBusinessMessage *Message `json:"edited_business_message,omitempty"` // Optional. New version of a message from a connected business account + DeletedBusinessMessages *BusinessMessagesDeleted `json:"deleted_business_messages,omitempty"` // Optional. Messages were deleted from a connected business account + MessageReaction *MessageReactionUpdated `json:"message_reaction,omitempty"` // Optional. A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify "message_reaction" in the list of allowed_updates to receive these updates. The update isn't received for reactions set by bots. + MessageReactionCount *MessageReactionCountUpdated `json:"message_reaction_count,omitempty"` // Optional. Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify "message_reaction_count" in the list of allowed_updates to receive these updates. + InlineQuery *InlineQuery `json:"inline_query,omitempty"` // Optional. New incoming inline query + ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"` // Optional. The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot. + CallbackQuery *CallbackQuery `json:"callback_query,omitempty"` // Optional. New incoming callback query + ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"` // Optional. New incoming shipping query. Only for invoices with flexible price + PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"` // Optional. New incoming pre-checkout query. Contains full information about checkout + Poll *Poll `json:"poll,omitempty"` // Optional. New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot + PollAnswer *PollAnswer `json:"poll_answer,omitempty"` // Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. + MyChatMember *ChatMemberUpdated `json:"my_chat_member,omitempty"` // Optional. The bot's chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user. + ChatMember *ChatMemberUpdated `json:"chat_member,omitempty"` // Optional. A chat member's status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates. + ChatJoinRequest *ChatJoinRequest `json:"chat_join_request,omitempty"` // Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates. + ChatBoost *ChatBoostUpdated `json:"chat_boost,omitempty"` // Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates. + RemovedChatBoost *ChatBoostRemoved `json:"removed_chat_boost,omitempty"` // Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates. +} + +// WebhookInfo Describes the current status of a webhook. +type WebhookInfo struct { + URL string `json:"url"` // Webhook URL, may be empty if webhook is not set up + HasCustomCertificate bool `json:"has_custom_certificate"` // True, if a custom certificate was provided for webhook certificate checks + PendingUpdateCount int `json:"pending_update_count"` // Number of updates awaiting delivery + IPAddress string `json:"ip_address,omitempty"` // Optional. Currently used webhook IP address + LastErrorDate int `json:"last_error_date,omitempty"` // Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook + LastErrorMessage string `json:"last_error_message,omitempty"` // Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook + LastSynchronizationErrorDate int `json:"last_synchronization_error_date,omitempty"` // Optional. Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters + MaxConnections int `json:"max_connections,omitempty"` // Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery + AllowedUpdates []string `json:"allowed_updates,omitempty"` // Optional. A list of update types the bot is subscribed to. Defaults to all update types except chat_member +} + +// User Represents a Telegram user or bot. +type User struct { + ID int64 `json:"id"` // Unique identifier for this user or bot. 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 is safe for storing this identifier. + IDString string `json:"-"` // String ID + IsBot bool `json:"is_bot"` // True, if this user is a bot + FirstName string `json:"first_name"` // User's or bot's first name + LastName string `json:"last_name,omitempty"` // Optional. User's or bot's last name + UserName string `json:"username,omitempty"` // Optional. user's or bot's username + LanguageCode string `json:"language_code,omitempty"` // Optional. (IETF language tag)[https://en.wikipedia.org/wiki/IETF_language_tag] of the user's language + IsPremium bool `json:"is_premium,omitempty"` // Optional. True, if this user is a Telegram Premium user + AddedToAttachmentMenu bool `json:"added_to_attachment_menu,omitempty"` // Optional. True, if this user added the bot to the attachment menu + CanJoinGroups bool `json:"can_join_groups,omitempty"` // Optional. Is true if the bot can be invited to groups. Returned only in getMe. + CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"` // Optional. is true if privacy mode is disabled for the bot. Returned only in getMe. + SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` // Optional. Is true if the bot supports inline queries. Returned only in getMe. + CanConnectToBusiness bool `json:"can_connect_to_business,omitempty"` // Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe. +} + +// Chat Represents a chat. +type Chat struct { + ID int64 `json:"id"` // Unique identifier for this chat. 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 signed 64-bit integer or double-precision float type are safe for storing this identifier. + IDString string `json:"-"` // String ID + Type string `json:"type"` // Type of the chat, can be either “private”, “group”, “supergroup” or “channel” + Title string `json:"title,omitempty"` // Optional. Title, for supergroups, channels and group chats + UserName string `json:"username,omitempty"` // Optional. Username, for private chats, supergroups and channels if available + FirstName string `json:"first_name,omitempty"` // Optional. First name of the other party in a private chat + LastName string `json:"last_name,omitempty"` // Optional. Last name of the other party in a private chat + IsForum bool `json:"is_forum,omitempty"` // Optional. True, if the supergroup chat is a forum (has topics enabled) +} + +// ChatFullInfo Contains full information about a chat. +type ChatFullInfo struct { + ID int64 `json:"id"` // Unique identifier for this chat. 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 signed 64-bit integer or double-precision float type is safe for storing this identifier. + IDString string `json:"-"` // String ID + Type string `json:"type"` // Type of chat can be either “private,” “group,” “supergroup” or “channel” + Title string `json:"title,omitempty"` // Optional. Title, for supergroups, channels and group chats + UserName string `json:"username,omitempty"` // Optional. Username, for private chats, supergroups and channels if available + FirstName string `json:"first_name,omitempty"` // Optional. First name of the other party in a private chat + LastName string `json:"last_name,omitempty"` // Optional. Last name of the other party in a private chat + IsForum bool `json:"is_forum,omitempty"` // Optional. True, if the supergroup chat is a forum (has topics enabled) + Photo *ChatPhoto `json:"photo,omitempty"` // Optional. Chat photo. Returned only in getChat. + ActiveUsernames []string `json:"active_usernames,omitempty"` // Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels. Returned only in getChat. + Birthdate *Birthdate `json:"birthdate,omitempty"` // Optional. For private chats, the date of birth of the user. Returned only in getChat. + BusinessIntro *BusinessIntro `json:"business_intro,omitempty"` // Optional. For private chats with business accounts, the intro of the business. Returned only in getChat. + BusinessLocation *BusinessLocation `json:"business_location,omitempty"` // Optional. For private chats with business accounts, the location of the business. Returned only in getChat. + BusinessOpeningHours *BusinessOpeningHours `json:"business_opening_hours,omitempty"` // Optional. For private chats with business accounts, the opening hours of the business. Returned only in getChat. + PersonalChat *Chat `json:"personal_chat,omitempty"` // Optional. For private chats, the personal channel of the user. Returned only in getChat. + AvailableReactions []ReactionType `json:"available_reactions,omitempty"` // Optional. List of available reactions allowed in the chat. If omitted, then all emoji reactions are allowed. Returned only in getChat. + AccentColorId int `json:"accent_color_id,omitempty"` // Identifier of the accent color for the chat name and backgrounds of the chat photo, reply header, and link preview. See accent colors for more details. Returned only in getChat. Always returned in getChat. + MaxReactionCount int `json:"max_reaction_count,omitempty"` // The maximum number of reactions that can be set on a message in the chat + BackgroundCustomEmojiId string `json:"background_custom_emoji_id,omitempty"` // Optional. Custom emoji identifier of emoji chosen by the chat for the reply header and link preview background. Returned only in getChat. + ProfileAccentColorId int `json:"profile_accent_color_id,omitempty"` // Optional. Identifier of the accent color for the chat's profile background. See profile accent colors for more details. Returned only in getChat. + ProfileBackgroundCustomEmojiId string `json:"profile_background_custom_emoji_id,omitempty"` // Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background. Returned only in getChat. + EmojiStatusCustomEmojiId string `json:"emoji_status_custom_emoji_id,omitempty"` // Optional. Custom emoji identifier of the emoji status of the chat or the other party in a private chat. Returned only in getChat. + EmojiStatusExpirationDate int64 `json:"emoji_status_expiration_date,omitempty"` // Optional. Expiration date of the emoji status of the chat or the other party in a private chat, in Unix time, if any. Returned only in getChat. + Bio string `json:"bio,omitempty"` // Optional. Bio of the other party in a private chat. Returned only in getChat. + HasPrivateForwards bool `json:"has_private_forwards,omitempty"` // Optional. True, if privacy settings of the other party in the private chat allow to use tg://user?id= links only in chats with the user. Returned only in getChat. + HasRestrictedVoiceAndVideoMessages bool `json:"has_restricted_voice_and_video_messages,omitempty"` // Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat. Returned only in getChat. + JoinToSendMessages bool `json:"join_to_send_messages,omitempty"` // Optional. True, if users need to join the supergroup before they can send messages. Returned only in getChat. + JoinByRequest bool `json:"join_by_request,omitempty"` // Optional. True, if all users directly joining the supergroup need to be approved by supergroup administrators. Returned only in getChat. + Description string `json:"description,omitempty"` // Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. + InviteLink string `json:"invite_link,omitempty"` // Optional. Primary invite link, for groups, supergroups and channel chats. Returned only in getChat. + PinnedMessage *Message `json:"pinned_message,omitempty"` // Optional. The most recent pinned message (by sending date). Returned only in getChat. + Permissions *ChatPermissions `json:"permissions,omitempty"` // Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. + CanSendPaidMedia bool `json:"can_send_paid_media,omitempty"` // Optional. True, if paid media messages can be sent or forwarded to the channel chat. The field is available only for channel chats. + SlowModeDelay int `json:"slow_mode_delay,omitempty"` // Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unprivileged user; in seconds. Returned only in getChat. + UnRestrictBoostCount int `json:"unrestrict_boost_count,omitempty"` // Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions. Returned only in getChat. + MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"` // Optional. The time after which all messages sent to the chat will be automatically deleted in seconds. Returned only in getChat. + HasAggressiveAntiSpamEnabled bool `json:"has_aggressive_anti_spam_enabled,omitempty"` // Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only available to chat administrators. Returned only in getChat. + HasHiddenMembers bool `json:"has_hidden_members,omitempty"` // Optional. True, if non-administrators can only get the list of bots and administrators in the chat. Returned only in getChat. + HasProtectedContent bool `json:"has_protected_content,omitempty"` // Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat. + HasVisibleHistory bool `json:"has_visible_history,omitempty"` // Optional. True, if new chat members will have access to old messages; available only to chat administrators. Returned only in getChat. + StickerSetName string `json:"sticker_set_name,omitempty"` // Optional. For supergroups, the name of a group sticker set. Returned only in getChat. + CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` // Optional. True, if the bot can change the group sticker set. Returned only in getChat. + CustomEmojiStickerSetName string `json:"custom_emoji_sticker_set_name,omitempty"` // Optional. For supergroups, the name of the group's custom emoji sticker set. Custom emoji from this set can be used by all users and bots in the group. Returned only in getChat. + LinkedChatID int64 `json:"linked_chat_id,omitempty"` // Optional. Unique identifier for the linked chat, i.e., the discussion group identifier for a channel and vice versa, for supergroups and channel chats. This identifier may be greater than 32 bits, and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64-bit integer or double-precision float type is safe for storing this identifier. Returned only in getChat. + Location *ChatLocation `json:"location,omitempty"` // Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. +} + +// Message Represents a message. +type Message struct { + MessageID int `json:"message_id"` // Unique message identifier inside this chat + MessageThreadID int `json:"message_thread_id,omitempty"` // Optional. Unique identifier of a message thread to which the message belongs; for supergroups only + From *User `json:"from,omitempty"` // Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats if the message was sent on behalf of a chat. + SenderChat *Chat `json:"sender_chat,omitempty"` // Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. For backward compatibility, the field contains a fake sender user in non-channel chats if the message was sent on behalf of a chat. + SenderBoostCount int `json:"sender_boost_count,omitempty"` // Optional. If the sender of the message boosted the chat, the number of boosts added by the user + SenderBusinessBot *User `json:"sender_business_bot,omitempty"` // 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. + Date int64 `json:"date"` // date the message was sent in Unix time + BusinessConnectionId string `json:"business_connection_id,omitempty"` // 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. + Chat Chat `json:"chat"` // The Conversation the message belongs to + ForwardOrigin *MessageOrigin `json:"forward_origin,omitempty"` // Optional. Information about the original message for forwarded messages + IsTopicMessage bool `json:"is_topic_message,omitempty"` // Optional. True, if the message is sent to a forum topic + IsAutomaticForward bool `json:"is_automatic_forward,omitempty"` // Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group + ReplyToMessage *Message `json:"reply_to_message,omitempty"` // Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply. + ExternalReply *ExternalReplyInfo `json:"external_reply,omitempty"` // Optional. Information about the message that is being replied to, which may come from another chat or forum topic + Quote *TextQuote `json:"quote,omitempty"` // Optional. For replies that quote part of the original message, the quoted part of the message + ReplyToStory *Story `json:"reply_to_story,omitempty"` // Optional. For replies to a story, the original story + ViaBot *User `json:"via_bot,omitempty"` // Optional. Bot through which the message was sent + EditDate int64 `json:"edit_date,omitempty"` // Optional. Date the message was last edited in Unix time + HasProtectedContent bool `json:"has_protected_content,omitempty"` // Optional. True, if the message can't be forwarded + IsFromOffline bool `json:"is_from_offline,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 + MediaGroupID string `json:"media_group_id,omitempty"` // Optional. The unique identifier of a media message group this message belongs to + AuthorSignature string `json:"author_signature,omitempty"` // Optional. Signature of the post-author for messages in channels, or the custom title of an anonymous group administrator + Text string `json:"text,omitempty"` // Optional. For text messages, the actual UTF-8 text of the message + Entities []*MessageEntity `json:"entities,omitempty"` // Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text + LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"` // Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed + EffectId string `json:"effect_id,omitempty"` // Optional. Unique identifier of the message effect added to the message + Animation *Animation `json:"animation,omitempty"` // Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set + Audio *Audio `json:"audio,omitempty"` // Optional. Message is an audio file, information about the file + Document *Document `json:"document,omitempty"` // Optional. Message is a general file, information about the file + PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"` // Optional. Message contains paid media; information about the paid media + Photo []*PhotoSize `json:"photo,omitempty"` // Optional. Message is a photo, available sizes of the photo + Sticker *Sticker `json:"sticker,omitempty"` // Optional. Message is a sticker, information about the sticker + Story *Story `json:"story,omitempty"` // Optional. Message is a forwarded story + Video *Video `json:"video,omitempty"` // Optional. Message is a video, information about the video + VideoNote *VideoNote `json:"video_note,omitempty"` // Optional. Message is a video note, information about the video message + Voice *Voice `json:"voice,omitempty"` // Optional. Message is a voice message, information about the file + Caption string `json:"caption,omitempty"` // Optional. Caption for the animation, audio, document, photo, video or voice + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. True, if the caption must be shown above the message media + HasMediaSpoiler bool `json:"has_media_spoiler,omitempty"` // Optional. True, if the message media is covered by a spoiler animation + Contact *Contact `json:"contact,omitempty"` // Optional. Message is a shared contact, information about the contact + Dice *Dice `json:"dice,omitempty"` // Optional. Message is a dice with random value + Game *Game `json:"game,omitempty"` // Optional. Message is a game, information about the game. + Poll *Poll `json:"poll,omitempty"` // Optional. Message is a native poll, information about the poll + Venue *Venue `json:"venue,omitempty"` // Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set + Location *Location `json:"location,omitempty"` // Optional. Message is a shared location, information about the location + NewChatMembers []*User `json:"new_chat_members,omitempty"` // Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members) + LeftChatMember *User `json:"left_chat_member,omitempty"` // Optional. A member was removed from the group, information about them (this member may be the bot itself) + NewChatTitle string `json:"new_chat_title,omitempty"` // Optional. A chat title was changed to this value + NewChatPhoto []*PhotoSize `json:"new_chat_photo,omitempty"` // Optional. A chat photo was changed to this value + DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` // Optional. Service message: the chat photo was deleted + GroupChatCreated bool `json:"group_chat_created,omitempty"` // Optional. Service message: the group has been created + SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"` // Optional. Service message: the supergroup has been created. This field can't be received in a message coming through updates, because bot can't be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup. + ChannelChatCreated bool `json:"channel_chat_created,omitempty"` // Optional. Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can't be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel. + MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed,omitempty"` // Optional. Service message: auto-delete timer settings changed in the chat + MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // Optional. The group has been migrated to a supergroup with the specified identifier. 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 signed 64-bit integer or double-precision float type is safe for storing this identifier. + MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` // Optional. The supergroup has been migrated from a group with the specified identifier. 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 signed 64-bit integer or double-precision float type is safe for storing this identifier. + PinnedMessage *Message `json:"pinned_message,omitempty"` // Optional. The Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. + Invoice *Invoice `json:"invoice,omitempty"` // Optional. Message is an invoice for a payment, information about the invoice. + SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` // Optional. Message is a service message about a successful payment, information about the payment. + RefundedPayment *RefundedPayment `json:"refunded_payment,omitempty"` // Optional. Message is a service message about a refunded payment, information about the payment. More about payments » + UsersShared *UsersShared `json:"users_shared,omitempty"` // Optional. Service message: a user was shared with the bot + ChatShared *ChatShared `json:"chat_shared,omitempty"` // Optional. Service message: a chat was shared with the bot + ConnectedWebsite string `json:"connected_website,omitempty"` // Optional. The domain name of the website on which the user has logged in. + WriteAccessAllowed *WriteAccessAllowed `json:"write_access_allowed,omitempty"` // Optional. Service message: the user allowed the bot added to the attachment menu to write messages + PassportData *PassportData `json:"passport_data,omitempty"` // Optional. Telegram Passport data + ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered,omitempty"` // Optional. Service message. A user in the chat triggered another user's proximity alert while sharing a Live Location. + BoostAdded *ChatBoostAdded `json:"boost_added,omitempty"` // Optional. Service message: user boosted the chat + ChatBackgroundSet *ChatBackground `json:"chat_background_set,omitempty"` // Optional. Service message: chat background set + ForumTopicCreated *ForumTopicCreated `json:"forum_topic_created,omitempty"` // Optional. Service message: forum topic created + ForumTopicEdited *ForumTopicEdited `json:"forum_topic_edited,omitempty"` // Optional. Service message: forum topic edited + ForumTopicClosed *ForumTopicClosed `json:"forum_topic_closed,omitempty"` // Optional. Service message: a forum topic closed + ForumTopicReopened *ForumTopicReopened `json:"forum_topic_reopened,omitempty"` // Optional. Service message: a forum topic reopened + GeneralForumTopicHidden *GeneralForumTopicHidden `json:"general_forum_topic_hidden,omitempty"` // Optional. Service message: the 'General' forum topic hidden + GeneralForumTopicUnhidden *GeneralForumTopicUnhidden `json:"general_forum_topic_unhidden,omitempty"` // Optional. Service message: the 'General' forum topic unhidden + GiveawayCreated *GiveawayCreated `json:"giveaway_created,omitempty"` // Optional. Service message: a scheduled giveaway was created + Giveaway *Giveaway `json:"giveaway,omitempty"` // Optional. The message is a scheduled giveaway message + GiveawayWinners *GiveawayWinners `json:"giveaway_winners,omitempty"` // Optional. A giveaway with public winners was completed + GiveawayCompleted *GiveawayCompleted `json:"giveaway_completed,omitempty"` // Optional. a giveaway without public winners was completed + VideoChatScheduled *VideoChatScheduled `json:"video_chat_scheduled,omitempty"` // Optional. Service message: video chat scheduled + VideoChatStarted *VideoChatStarted `json:"video_chat_started,omitempty"` // Optional. Service message: video chat started + VideoChatEnded *VideoChatEnded `json:"video_chat_ended,omitempty"` // Optional. Service message: video chat ended + VideoChatParticipantsInvited *VideoChatParticipantsInvited `json:"video_chat_participants_invited,omitempty"` // Optional. Service message: new participants invited to a video chat + WebAppData *WebAppData `json:"web_app_data,omitempty"` // Optional. Service message: data sent by a Web App + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message. Login_url buttons are represented as ordinary url buttons. +} + +// MessageID Represents a unique message identifier. +type MessageID struct { + MessageID int `json:"message_id"` // Unique message identifier +} + +// InaccessibleMessage Describes a message that was deleted or is otherwise inaccessible to the bot. +type InaccessibleMessage struct { + Chat Chat `json:"chat"` // Chat the message belonged to + MessageID int `json:"message_id"` // Unique message identifier inside the chat + Date int64 `json:"date"` // Always 0. The field can be used to differentiate regular and inaccessible messages. +} + +// MaybeInaccessibleMessage Describes a message that can be inaccessible to the bot. It can be one of +type MaybeInaccessibleMessage struct { + Message + InaccessibleMessage +} + +// MessageEntity Represents one special entity in a text message. For example, hashtags, usernames, URLs, etc +type MessageEntity struct { + Type string `json:"type"` // Type of the entity. Currently, can be “mention” (@username), “hashtag” (#hashtag), “hashtag” ($USD), “bot_command” (/start@jobs_bot), “url” (https://telegram.org), “email” (do-not-reply@telegram.org), “phone_number” (+1-212-555-0123), “bold” (bold text), “italic” (italic text), “underline” (underlined text), “strikethrough” (strikethrough text), “spoiler” (spoiler message), “code” (mono-width string), “pre” (mono-width block), “text_link” (for clickable text URLs), “text_mention” (for users without usernames) + Offset int `json:"offset"` // Offset in UTF-16 code units to the start of the entity + Length int `json:"length"` // Length of the entity in UTF-16 code units + URL string `json:"url,omitempty"` // Optional. For “text_link” only, URL that will be opened after user taps on the text + User *User `json:"user,omitempty"` // Optional. For “text_mention” only, the mentioned user + Language string `json:"language,omitempty"` // Optional. For “pre” only, the programming language of the entity text + CustomEmojiId string `json:"custom_emoji_id,omitempty"` // Optional. For “custom_emoji” only, unique identifier of the custom emoji. Use getCustomEmojiStickers to get full information about the sticker +} + +// TextQuote Contains information about the quoted part of a message that is replied to by the given message. +type TextQuote struct { + Text string `json:"text"` // Text of the quoted part of a message that is replied to by the given message + Entities []MessageEntity `json:"entities,omitempty"` // Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are kept in quotes. + Position int `json:"position"` // Approximate quote position in the original message in UTF-16 code units as specified by the sender + IsManual bool `json:"is_manual,omitempty"` // Optional. True, if the quote was chosen manually by the message sender. Otherwise, the quote was added automatically by the server. +} + +// ExternalReplyInfo Contains information about a message that is being replied to, which may come from another chat or forum topic. +type ExternalReplyInfo struct { + Origin MessageOrigin `json:"origin"` // Origin of the message replied to by the given message + Chat *Chat `json:"chat,omitempty"` // Optional. Chat the original message belongs to. Available only if the chat is a supergroup or a channel. + MessageID int `json:"message_id,omitempty"` // Optional. Unique message identifier inside the original chat. Available only if the original chat is a supergroup or a channel. + LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"` // Optional. Options used for link preview generation for the original message, if it is a text message + Animation *Animation `json:"animation,omitempty"` // Optional. Message is an animation, information about the animation + Audio *Audio `json:"audio,omitempty"` // Optional. Message is an audio file, information about the file + Document *Document `json:"document,omitempty"` // Optional. Message is a general file, information about the file + PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"` // Optional. Message contains paid media; information about the paid media + Photo []PhotoSize `json:"photo,omitempty"` // Optional. Message is a photo, available sizes of the photo + Sticker *Sticker `json:"sticker,omitempty"` // Optional. Message is a sticker, information about the sticker + Story *Story `json:"story,omitempty"` // Optional. Message is a forwarded story + Video *Video `json:"video,omitempty"` // Optional. Message is a video, information about the video + VideoNote *VideoNote `json:"video_note,omitempty"` // Optional. Message is a video note, information about the video message + Voice *Voice `json:"voice,omitempty"` // Optional. Message is a voice message, information about the file + HasMediaSpoiler bool `json:"has_media_spoiler,omitempty"` // Optional. True, if the message media is covered by a spoiler animation + Contact *Contact `json:"contact,omitempty"` // Optional. Message is a shared contact, information about the contact + Dice *Dice `json:"dice,omitempty"` // Optional. Message is a dice with random value + Game *Game `json:"game,omitempty"` // Optional. Message is a game, information about the game. More about games + Giveaway *Giveaway `json:"giveaway,omitempty"` // Optional. Message is a scheduled giveaway, information about the giveaway + GiveawayWinners *GiveawayWinners `json:"giveaway_winners,omitempty"` // Optional. A giveaway with public winners was completed + Invoice *Invoice `json:"invoice,omitempty"` // Optional. Message is an invoice for a payment, information about the invoice. + Location *Location `json:"location,omitempty"` // Optional. Message is a shared location, information about the location + Poll *Poll `json:"poll,omitempty"` // Optional. Message is a native poll, information about the poll + Venue *Venue `json:"venue,omitempty"` // Optional. Message is a venue, information about the venue +} + +// ReplyParameters Describes reply parameters for the message that is being sent. +type ReplyParameters struct { + MessageID int `json:"message_id"` // Identifier of the message that will be replied to in the current chat, or in the chat chat_id if it is specified + ChatID string `json:"chat_id,omitempty"` // Optional. If the message to be replied to is from a different chat, unique identifier for the chat or username of the channel (in the format @channelusername) + AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"` // Optional. Pass True if the message should be sent even if the specified message to be replied to is not found; can be used only for replies in the same chat and forum topic. + Quote string `json:"quote,omitempty"` // Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing. The quote must be an exact substring of the message to be replied to, including bold, italic, underline, strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in the original message. + QuoteParseMode string `json:"quote_parse_mode,omitempty"` // Optional. Mode for parsing entities in the quote. See formatting options for more details. + QuoteEntities []MessageEntity `json:"quote_entities,omitempty"` // Optional. A JSON-serialized list of special entities that appear in the quote. It can be specified instead of quote_parse_mode. + QuotePosition int `json:"quote_position,omitempty"` // Optional. Position of the quote in the original message in UTF-16 code units +} + +// MessageOrigin Describes the origin of a message. It can be one of +type MessageOrigin struct { + MessageOriginUser + MessageOriginHiddenUser + MessageOriginChat + MessageOriginChannel +} + +// MessageOriginUser Originally sent by a known user. +type MessageOriginUser struct { + Type string `json:"type"` // Type of the message origin, always “user” + Date int64 `json:"date"` // Date the message was sent originally in Unix time + SenderUser User `json:"sender_user"` // User that sent the message originally +} + +// MessageOriginHiddenUser Originally sent by an unknown user. +type MessageOriginHiddenUser struct { + Type string `json:"type"` // Type of the message origin, always “hidden_user” + Date int64 `json:"date"` // Date the message was sent originally in Unix time + SenderUserName string `json:"sender_user_name"` // Name of the user that sent the message originally +} + +// MessageOriginChat Originally sent on behalf of a chat to a group chat. +type MessageOriginChat struct { + Type string `json:"type"` // Type of the message origin, always “chat” + Date int64 `json:"date"` // Date the message was sent originally in Unix time + SenderChat Chat `json:"sender_chat"` // Chat that sent the message originally + AuthorSignature string `json:"author_signature,omitempty"` // Optional. For messages originally sent by an anonymous chat administrator, original message author signature +} + +// MessageOriginChannel Originally sent to a channel chat. +type MessageOriginChannel struct { + Type string `json:"type"` // Type of the message origin, always “channel” + Date int64 `json:"date"` // Date the message was sent originally in Unix time + SenderChat Chat `json:"sender_chat"` // Channel chat to which the message was originally sent + MessageID int `json:"message_id"` // Unique message identifier inside the chat + AuthorSignature string `json:"author_signature,omitempty"` // Optional. Signature of the original post author +} + +// PhotoSize Represents one size of a photo or a file / sticker thumbnail. +type PhotoSize struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Width int `json:"width"` // Photo width + Height int `json:"height"` // Photo height + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes +} + +// Animation Represents an animation file (GIF or H.264/MPEG-4 AVC video without a sound). +type Animation struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Width int `json:"width"` // Video width as defined by sender + Height int `json:"height"` // Video height as defined by sender + Duration int `json:"duration"` // Duration of the video in seconds as defined by sender + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Animation thumbnail as defined by sender + FileName string `json:"file_name,omitempty"` // Optional. Original animation filename as defined by sender + MimeType string `json:"mime_type,omitempty"` // Optional. MIME type of the file as defined by sender + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31, and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type is safe for storing this value. +} + +// Audio Represents an audio file to be treated as music by the Telegram clients. +type Audio struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Duration int `json:"duration"` // Duration of the audio in seconds as defined by sender + Performer string `json:"performer,omitempty"` // Optional. Performer of the audio as defined by sender or by audio tags + Title string `json:"title,omitempty"` // Optional. Title of the audio as defined by sender or by audio tags + FileName string `json:"file_name,omitempty"` // Optional. Original filename as defined by sender + MimeType string `json:"mime_type,omitempty"` // Optional. MIME type of the file as defined by sender + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31, and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type is safe for storing this value. + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Thumbnail of the album cover to which the music file belongs +} + +// The Document Represents a general file (as opposed to photos, voice messages and audio files). +type Document struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Document thumbnail as defined by sender + FileName string `json:"file_name,omitempty"` // Optional. Original filename as defined by sender + MimeType string `json:"mime_type,omitempty"` // Optional. MIME type of the file as defined by sender + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31, and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type is safe for storing this value. +} + +// Story Represents a message about a forwarded story in the chat. Currently, holds no information. +type Story struct { + Chat Chat `json:"chat"` // Chat that posted the story + ID int64 `json:"id"` // Unique identifier for the story in the chat +} + +// Video Represents a video file. +type Video struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Width int `json:"width"` // Video width as defined by sender + Height int `json:"height"` // Video height as defined by sender + Duration int `json:"duration"` // Duration of the video in seconds as defined by sender + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Video thumbnail + FileName string `json:"file_name,omitempty"` // Optional. Original filename as defined by sender + MimeType string `json:"mime_type,omitempty"` // Optional. MIME type of the file as defined by sender + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31, and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type is safe for storing this value. +} + +// VideoNote Represents a video message (available in Telegram apps as of v.4.0). +type VideoNote struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Length int `json:"length"` // Video width and height (diameter of the video message) as defined by sender + Duration int `json:"duration"` // Duration of the video in seconds as defined by sender + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Video thumbnail + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes +} + +// Voice Represents a voice note. +type Voice struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Duration int `json:"duration"` // Duration of the audio in seconds as defined by sender + MimeType string `json:"mime_type,omitempty"` // Optional. MIME type of the file as defined by sender + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31, and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type is safe for storing this value. +} + +// PaidMediaInfo Describes the paid media added to a message. +type PaidMediaInfo struct { + StarCount int `json:"star_count"` // The number of Telegram Stars that must be paid to buy access to the media + PaidMedia []PaidMedia `json:"paid_media"` // Information about the paid media +} + +type PaidMedia struct { + PaidMediaPreview + PaidMediaPhoto + PaidMediaVideo +} + +// PaidMediaPreview The paid media isn't available before the payment. +type PaidMediaPreview struct { + Type int `json:"type"` // Type of the paid media, always “preview” + Width int `json:"width"` // Optional. Media width as defined by the sender + Height int `json:"height"` // Optional. Media height as defined by the sender + Duration int64 `json:"duration"` // Optional. Duration of the media in seconds as defined by the sender +} + +// PaidMediaPhoto The paid media is a photo. +type PaidMediaPhoto struct { + Type int `json:"type"` // Type of the paid media, always “photo” + Photo []PhotoSize `json:"photo"` // The photo +} + +// PaidMediaVideo The paid media is a video. +type PaidMediaVideo struct { + Type int `json:"type"` // Type of the paid media, always “video” + Video Video `json:"video"` // The video +} + +// Contact Represents a phone contact. +type Contact struct { + PhoneNumber string `json:"phone_number"` // Contact's phone number + FirstName string `json:"first_name"` // Contact's first name + LastName string `json:"last_name,omitempty"` // Optional. Contact's last name + UserID int64 `json:"user_id,omitempty"` // Optional. Contact's user identifier in Telegram. 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 is safe for storing this identifier. + VCard string `json:"vcard,omitempty"` // Optional. Additional data about the contact in the form of a vCard +} + +// Dice Represents an animated emoji that displays a random value. +type Dice struct { + Emoji string `json:"emoji"` // Emoji on which the dice throw animation is based + Value int `json:"value"` // Value of the dice, 1-6 for “🎲”, “🎯” and “🎳” base emoji, 1-5 for “🏀” and “⚽” base emoji, 1-64 for “🎰” base emoji +} + +// PollOption Contains information about one answer option in a poll. +type PollOption struct { + Text string `json:"text"` // Option text, 1-100 characters + TextEntities []*MessageEntity `json:"text_entities"` // Optional. Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts + VoterCount int `json:"voter_count"` // Number of users that voted for this option +} + +// InputPollOption Contains information about one answer option in a poll to send. +type InputPollOption struct { + Text string `json:"text"` // Option text, 1-100 characters + TextParseMode string `json:"text_parse_mode"` // Optional. Mode for parsing entities in the text. See formatting options for more details. Currently, only custom emoji entities are allowed + TextEntities []*MessageEntity `json:"text_entities"` // Optional. A JSON-serialized list of special entities that appear in the poll option text. It can be specified instead of text_parse_mode +} + +// PollAnswer Represents an answer of a user in a non-anonymous poll. +type PollAnswer struct { + PollID string `json:"poll_id"` // Unique poll identifier + VoterChat *Chat `json:"voter_chat,omitempty"` // Optional. The chat that changed the answer to the poll if the voter is anonymous + User *User `json:"user,omitempty"` // Optional. The user that changed the answer to the poll if the voter isn't anonymous + OptionIDs []int `json:"option_ids"` // 0-based identifiers of answer options, chosen by the user. Maybe empty if the user retracted their vote. +} + +// The Poll Contains information about a poll. +type Poll struct { + ID string `json:"id"` // Unique poll identifier + Question string `json:"question"` // Poll question, 1-300 characters + QuestionEntities []*MessageEntity `json:"question_entities"` // Optional. Special entities that appear in the question. Currently, only custom emoji entities are allowed in poll questions + Options []PollOption `json:"options"` // List of poll options + TotalVoterCount int `json:"total_voter_count"` // Total number of users that voted in the poll + IsClosed bool `json:"is_closed"` // True, if the poll is closed + IsAnonymous bool `json:"is_anonymous"` // True, if the poll is anonymous + Type string `json:"type"` // Poll type, currently can be “regular” or “quiz” + AllowsMultipleAnswers bool `json:"allows_multiple_answers"` // True, if the poll allows multiple answers + CorrectOptionID int `json:"correct_option_id,omitempty"` // Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot. + Explanation string `json:"explanation,omitempty"` // Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters + ExplanationEntities []*MessageEntity `json:"explanation_entities,omitempty"` // Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation + OpenPeriod int `json:"open_period,omitempty"` // Optional. Amount of time in seconds the poll will be active after creation + CloseDate int64 `json:"close_date,omitempty"` // Optional. Point in time (Unix timestamp) when the poll will be automatically closed +} + +// Location Represents a point on the map. +type Location struct { + Longitude float64 `json:"longitude"` // Longitude as defined by sender + Latitude float64 `json:"latitude"` // Latitude as defined by sender + HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` // Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + LivePeriod int `json:"live_period,omitempty"` // Optional. Time relative to the message sending date, during which the location can be updated; in seconds. For active live locations only. + Heading int `json:"heading,omitempty"` // Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only. + ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"` // Optional. The maximum distance for proximity alerts about approaching another chat member, in meters. For sent live locations only. +} + +// Venue Represents a venue. +type Venue struct { + Location Location `json:"location"` // Venue location. Can't be a live location + Title string `json:"title"` // Name of the venue + Address string `json:"address"` // address of the venue + FoursquareID string `json:"foursquare_id,omitempty"` // Optional. Foursquare identifier of the venue + FoursquareType string `json:"foursquare_type,omitempty"` // Optional. Foursquare type of the venue. (For example, “arts_entertainment/default,” “arts_entertainment/aquarium” or “food/ice cream.”) + GooglePlaceID string `json:"google_place_id,omitempty"` // Optional. Google Places identifier of the venue + GooglePlaceType string `json:"google_place_type,omitempty"` // Optional. Google Places a type of the venue. (See supported types.) +} + +// WebAppData Describes data sent from a Web App to the bot. +type WebAppData struct { + Data string `json:"data"` // The data. Be aware that a bad client can send arbitrary data in this field. + ButtonText string `json:"button_text"` // Text of the web_app keyboard button from which the Web App was opened. Be aware that a bad client can send arbitrary data in this field. +} + +// ProximityAlertTriggered Represents the content of a service message, sent whenever a user in the chat triggers a proximity alert set by another user. +type ProximityAlertTriggered struct { + Traveler User `json:"traveler"` // User that triggered the alert + Watcher User `json:"watcher"` // User that set the alert + Distance int `json:"distance"` // The distance between the users +} + +// MessageAutoDeleteTimerChanged Represents a service message about a change in auto-delete timer settings. +type MessageAutoDeleteTimerChanged struct { + MessageAutoDeleteTime int `json:"message_auto_delete_time"` // New auto-delete time for messages in the chat; in seconds +} + +// ChatBoostAdded Represents a service message about a user boosting a chat. +type ChatBoostAdded struct { + BoostCount int `json:"boost_count"` // Number of boosts added by the user +} + +// BackgroundFill Describes the way a background is filled based on the selected colors. Currently, it can be one of +type BackgroundFill struct { + BackgroundFillSolid + BackgroundFillGradient + BackgroundFillFreeformGradient +} + +// BackgroundFillSolid Filled using the selected color. +type BackgroundFillSolid struct { + Type string `json:"type"` // Type of the background fill, always “solid” + Color int `json:"color"` // The color of the background fill in the RGB24 format +} + +// BackgroundFillGradient Automatically filled based on the selected colors. +type BackgroundFillGradient struct { + Type string `json:"type"` // Type of the background fill, always “gradient” + TopColor int `json:"top_color"` // Top color of the gradient in the RGB24 format + BottomColor int `json:"bottom_color"` // Bottom color of the gradient in the RGB24 format + RotationAngle int `json:"rotation_angle"` // Clockwise rotation angle of the background fill in degrees; 0-359 +} + +// BackgroundFillFreeformGradient Automatically filled based on the selected colors. +type BackgroundFillFreeformGradient struct { + Type string `json:"type"` // Type of the background fill, always “freeform_gradient” + Colors []int `json:"colors"` // A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format +} + +// BackgroundType Describes the type of a background. Currently, it can be one of +type BackgroundType struct { + BackgroundTypeFill + BackgroundTypeWallpaper + BackgroundTypePattern + BackgroundTypeChatTheme +} + +// BackgroundTypeFill Automatically filled based on the selected colors. +type BackgroundTypeFill struct { + Type string `json:"type"` // Type of the background, always “fill” + Fill BackgroundFill `json:"fill"` // The background fill + DarkThemeDimming int `json:"dark_theme_dimming"` // Dimming of the background in dark themes, as a percentage; 0-100 +} + +// BackgroundTypeWallpaper Wallpaper in the JPEG format. +type BackgroundTypeWallpaper struct { + Type string `json:"type"` // Type of the background, always “wallpaper” + Document Document `json:"document"` // Document with the wallpaper + DarkThemeDimming int `json:"dark_theme_dimming"` // Dimming of the background in dark themes, as a percentage; 0-100 + IsBlurred bool `json:"is_blurred"` // Optional. True, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with radius 12 + IsMoving bool `json:"is_moving"` // Optional. True, if the background moves slightly when the device is tilted +} + +// BackgroundTypePattern PNG or TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user. +type BackgroundTypePattern struct { + Type string `json:"type"` // Type of the background, always “pattern” + Document Document `json:"document"` // Document with the pattern + Fill BackgroundFill `json:"fill"` // The background fill that is combined with the pattern + Intensity int `json:"intensity"` // Intensity of the pattern when it is shown above the filled background; 0-100 + IsInverted bool `json:"is_inverted"` // Optional. True, if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only + IsMoving bool `json:"is_moving"` // Optional. True, if the background moves slightly when the device is tilted +} + +// BackgroundTypeChatTheme Taken directly from a built-in chat theme. +type BackgroundTypeChatTheme struct { + Type string `json:"type"` // Type of the background, always “chat_theme” + ThemeName string `json:"theme_name"` // Name of the chat theme, which is usually an emoji +} + +// ChatBackground Represents a chat background. +type ChatBackground struct { + Type BackgroundType `json:"type"` // Number of boosts added by the user +} + +// ForumTopicCreated Represents a service message about a new forum topic created in the chat. +type ForumTopicCreated struct { + Name string `json:"name"` // Name of the topic + IconColor int `json:"icon_color"` // Color of the topic icon in RGB format + IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"` // Optional. Unique identifier of the custom emoji shown as the topic icon +} + +// ForumTopicClosed Represents a service message about a forum topic closed in the chat. Currently, it holds no information. +type ForumTopicClosed struct { +} + +// ForumTopicEdited Represents a service message about an edited forum topic. +type ForumTopicEdited struct { + Name string `json:"name,omitempty"` // Optional. New name of the topic, if it was edited + IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"` // Optional. New identifier of the custom emoji shown as the topic icon if it was edited; an empty string if the icon was removed +} + +// ForumTopicReopened Represents a service message about a forum topic reopened in the chat. Currently, it holds no information. +type ForumTopicReopened struct { +} + +// GeneralForumTopicHidden Represents a service message about a General forum topic hidden in the chat. Currently, it holds no information +type GeneralForumTopicHidden struct { +} + +// GeneralForumTopicUnhidden Represents a service message about a General forum topic unhidden in the chat. Currently, it holds no information. +type GeneralForumTopicUnhidden struct { +} + +// SharedUser Contains information about a user that was shared with the bot using a KeyboardButtonRequestUser button. +type SharedUser struct { + UserId int64 `json:"user_id"` // Identifier of the shared user. 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 64-bit integers or double-precision float types are safe for storing these identifiers. The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means. + FirstName string `json:"first_name,omitempty"` // Optional. First name of the user, if the name was requested by the bot + LastName string `json:"last_name,omitempty"` // Optional. Last name of the user, if the name was requested by the bot + Username string `json:"username,omitempty"` // Optional. Username of the user, if the username was requested by the bot + Photo []*PhotoSize `json:"photo,omitempty"` // Optional. Available sizes of the chat photo, if the photo was requested by the bot +} + +// UsersShared Contains information about the users whose identifiers were shared with the bot using a KeyboardButtonRequestUsers button. +type UsersShared struct { + RequestID int `json:"request_id"` // Identifier of the request + Users []*SharedUser `json:"users"` // Information about users shared with the bot. +} + +// ChatShared Contains information about the chat whose identifier was shared with the bot using a KeyboardButtonRequestChat button. +type ChatShared struct { + RequestID int `json:"request_id"` // Identifier of the request + ChatID int64 `json:"chat_id"` // Identifier of the shared chat. 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 is safe for storing this identifier. The bot may not have access to the chat and could be unable to use this identifier, unless the chat is already known to the bot by some other means. + Title string `json:"title,omitempty"` // Optional. Title of the chat, if the title was requested by the bot. + Username string `json:"username,omitempty"` // Optional. Username of the chat, if the username was requested by the bot and available. + Photo []*PhotoSize `json:"photo,omitempty"` // Optional. Available sizes of the chat photo, if the photo was requested by the bot +} + +// WriteAccessAllowed 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 { + FromRequest bool `json:"from_request,omitempty"` // Optional. True, if the access was granted after the user accepted an explicit request from a Web App sent by the method requestWriteAccess + WebAppName string `json:"web_app_name,omitempty"` // Optional. Name of the Web App which was launched from a link + FromAttachmentMenu bool `json:"from_attachment_menu,omitempty"` // Optional. True, if the access was granted when the bot was added to the attachment or side menu +} + +// VideoChatScheduled Represents a service message about a video chat scheduled in the chat. +type VideoChatScheduled struct { + StartDate int64 `json:"start_date"` // Point in time (Unix timestamp) when the video chat is supposed to be started by a chat administrator +} + +// VideoChatStarted Represents a service message about a video chat started in the chat. Currently, it holds no information. +type VideoChatStarted struct{} + +// VideoChatEnded Represents a service message about a video chat ended in the chat. +type VideoChatEnded struct { + Duration int `json:"duration"` // Video chat duration in seconds +} + +// VideoChatParticipantsInvited Represents a service message about new members invited to a video chat. +type VideoChatParticipantsInvited struct { + Users []User `json:"users"` // New members that were invited to the video chat +} + +// GiveawayCreated Represents a service message about the creation of a scheduled giveaway. Currently holds no information. +type GiveawayCreated struct { +} + +// Giveaway Represents a message about a scheduled giveaway. +type Giveaway struct { + Chats []Chat `json:"chats"` // The list of chats which the user must join to participate in the giveaway + WinnersSelectionDate int64 `json:"winners_selection_date"` // Point in time (Unix timestamp) when winners of the giveaway will be selected + WinnerCount int `json:"winner_count"` // The number of users which are supposed to be selected as winners of the giveaway + OnlyNewMembers bool `json:"only_new_members,omitempty"` // Optional. True, if only users who join the chats after the giveaway started should be eligible to win + HasPublicWinners bool `json:"has_public_winners,omitempty"` // Optional. True, if the list of giveaway winners will be visible to everyone + PrizeDescription string `json:"prize_description,omitempty"` // Optional. Description of additional giveaway prize + CountryCodes []string `json:"country_codes,omitempty"` // Optional. A list of two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which eligible users for the giveaway must come. If empty, then all users can participate in the giveaway. Users with a phone number that was bought on Fragment can always participate in giveaways. + PremiumSubscriptionMonthCount int `json:"premium_subscription_month_count,omitempty"` // Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for +} + +// GiveawayWinners Represents a message about the completion of a giveaway with public winners. +type GiveawayWinners struct { + Chat Chat `json:"chats"` // The chat that created the giveaway + GiveawayMessageId int `json:"giveaway_message_id"` // Identifier of the messsage with the giveaway in the chat + WinnersSelectionDate int64 `json:"winners_selection_date"` // Point in time (Unix timestamp) when winners of the giveaway were selected + WinnerCount int `json:"winner_count"` // Total number of winners in the giveaway + Winners []User `json:"winners"` // List of up to 100 winners of the giveaway + AdditionalChatCount int `json:"additional_chat_count,omitempty"` // Optional. The number of other chats the user had to join in order to be eligible for the giveaway + PremiumSubscriptionMonthCount int `json:"premium_subscription_month_count,omitempty"` // Optional. The number of months the Telegram Premium subscription won from the giveaway will be active for + UnclaimedPrizeCount int `json:"unclaimed_prize_count,omitempty"` // Optional. Number of undistributed prizes + OnlyNewMembers bool `json:"only_new_members,omitempty"` // Optional. True, if only users who had joined the chats after the giveaway started were eligible to win + WasRefunded bool `json:"was_refunded,omitempty"` // Optional. True, if the giveaway was canceled because the payment for it was refunded + PrizeDescription string `json:"prize_description,omitempty"` // Optional. Description of additional giveaway prize +} + +// GiveawayCompleted Represents a service message about the completion of a giveaway without public winners. +type GiveawayCompleted struct { + WinnerCount int `json:"winner_count"` // Number of winners in the giveaway + UnclaimedPrizeCount int `json:"unclaimed_prize_count,omitempty"` // Optional. Number of undistributed prizes + GiveawayMessage *Message `json:"giveaway_message,omitempty"` // Optional. Message with the giveaway that was completed, if it wasn't deleted +} + +// LinkPreviewOptions Describes the options used for link preview generation. +type LinkPreviewOptions struct { + IsDisabled bool `json:"is_disabled,omitempty"` // Optional. True, if the link preview is disabled + Url string `json:"url,omitempty"` // Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used + PreferSmallMedia bool `json:"prefer_small_media,omitempty"` // Optional. True, if the media in the link preview is suppposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview + PreferLargeMedia bool `json:"prefer_large_media,omitempty"` // Optional. True, if the media in the link preview is suppposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview + ShowAboveText bool `json:"show_above_text,omitempty"` // Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text +} + +// UserProfilePhotos represent a user's profile pictures. +type UserProfilePhotos struct { + TotalCount int `json:"total_count"` // Total number of profile pictures the target user has + Photos [][]PhotoSize `json:"photos"` // Requested profile pictures (in up to 4 sizes each) +} + +// File Represents a file ready to be downloaded. +// The file can be downloaded via the link https://api.telegram.org/file/bot/. It is guaranteed +// that the link will be valid for at least 1 hour. +// When the link expires, a new one can be requested by calling getFile. +// Note: The maximum file size to download is 20 MB +type File struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes. It can be bigger than 2^31, and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type is safe for storing this value. + FilePath string `json:"file_path,omitempty"` // Optional. File a path. Use https://api.telegram.org/file/bot/ to get the file. +} + +// WebAppInfo Describes a Web App. +type WebAppInfo struct { + URL string `json:"url"` // An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps +} + +// ReplyKeyboardMarkup Represents a custom keyboard with reply options (see Introduction to bots for details and examples). +type ReplyKeyboardMarkup struct { + Keyboard [][]KeyboardButton `json:"keyboard"` // Array of button rows, each represented by an Array of KeyboardButton objects + IsPersistent bool `json:"is_persistent,omitempty"` // Optional. Requests clients to always show the keyboard when the regular keyboard is hidden. Defaults to false, in which case the custom keyboard can be hidden and opened with a keyboard icon. + ResizeKeyboard bool `json:"resize_keyboard,omitempty"` // Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard. + OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` // Optional. Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to false. + InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"` // Optional. The placeholder to be shown in the input field when the keyboard is active; 1-64 characters + Selective bool `json:"selective,omitempty"` // Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. Example: A user requests to change the bot's language, bot replies to the request with a keyboard to select the new language. Other users in the group don't see the keyboard. +} + +// KeyboardButton Represents one button of the reply keyboard. +// For simple text buttons, String can be used instead of this object to specify the text of the button. +// Optional fields web_app, request_contact, request_location, and request_poll are mutually exclusive. +// Note: request_contact and request_location options will only work in Telegram versions released after 9 April 2016. +// Older clients will display unsupported message. +// Note: request_poll option will only work in Telegram versions released after 23 January 2020. +// Older clients will display unsupported message. +// Note: web_app option will only work in Telegram versions released after 16 April 2022. +// Older clients will display an unsupported message. +type KeyboardButton struct { + Text string `json:"text"` // Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed + RequestUsers *KeyboardButtonRequestUsers `json:"request_users,omitempty"` // Optional. If specified, pressing the button will open a list of suitable users. Tapping on any user will send their identifier to the bot in an “users_shared” service message. Available in private chats only. + RequestChat *KeyboardButtonRequestChat `json:"request_chat,omitempty"` // Optional. If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. Available in private chats only. + RequestContact bool `json:"request_contact,omitempty"` // Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only. + RequestLocation bool `json:"request_location,omitempty"` // Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only. + RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"` // Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only. + WebApp *WebAppInfo `json:"web_app,omitempty"` // Optional. If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private chats only. +} + +// KeyboardButtonRequestUsers Defines the criteria used to request suitable users. +// The identifiers of the selected users will be shared with the bot when the corresponding button is pressed. +type KeyboardButtonRequestUsers struct { + RequestId int `json:"request_id"` // Signed 32-bit identifier of the request that will be received back in the UsersShared object. Must be unique within the message. + UserIsBot bool `json:"user_is_bot,omitempty"` // Optional. Pass True to request bots, pass False to request regular users. If not specified, no additional restrictions are applied. + UserIsPremium bool `json:"user_is_premium,omitempty"` // Optional. Pass True to request premium users, pass False to request non-premium users. If not specified, no additional restrictions are applied. + MaxQuantity int `json:"max_quantity,omitempty"` // Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + RequestName bool `json:"request_name,omitempty"` // Optional. Pass True to request the users' first and last name + RequestUsername bool `json:"request_username,omitempty"` // Optional. Pass True to request the users' username + RequestPhoto bool `json:"request_photo,omitempty"` // Optional. Pass True to request the users' photo +} + +// KeyboardButtonRequestChat Defines the criteria used to request a suitable chat. +// The identifier of the selected chat will be shared with the bot when the corresponding button is pressed. +type KeyboardButtonRequestChat struct { + RequestID int `json:"request_id"` // Signed 32-bit identifier of the request, which will be received back in the ChatShared object. Must be unique within the message + ChatIsChannel bool `json:"chat_is_channel"` // Pass True to request a channel chat, pass False to request a group or a supergroup chat. + ChatIsForum bool `json:"chat_is_forum,omitempty"` // Optional. Pass True to request a forum supergroup, pass False to request a non-forum chat. If not specified, no additional restrictions are applied. + ChatHasUsername bool `json:"chat_has_username,omitempty"` // Optional. Pass True to request a supergroup or a channel with a username, pass False to request a chat without a username. If not specified, no additional restrictions are applied. + ChatIsCreated bool `json:"chat_is_created,omitempty"` // Optional. Pass True to request a chat owned by the user. Otherwise, no additional restrictions are applied. + UserAdministratorRights *ChatAdministratorRights `json:"user_administrator_rights,omitempty"` // Optional. A JSON-serialized object lists the required administrator rights of the user in the chat. The rights must be a superset of bot_administrator_rights. If not specified, no additional restrictions are applied. + BotAdministratorRights *ChatAdministratorRights `json:"bot_administrator_rights,omitempty"` // Optional. A JSON-serialized object listing the required administrator rights of the bot in the chat. The rights must be a subset of user_administrator_rights. If not specified, no additional restrictions are applied. + BotIsMember bool `json:"bot_is_member,omitempty"` // Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + RequestTitle bool `json:"request_title,omitempty"` // Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + RequestUsername bool `json:"request_username,omitempty"` // Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + RequestPhoto bool `json:"request_photo,omitempty"` // Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. +} + +// KeyboardButtonPollType Represents a type of poll, which is allowed to be created and sent when the corresponding button is pressed. +type KeyboardButtonPollType struct { + Type string `json:"type"` // Optional. If quiz is passed, the user will be allowed to create only polls in the quiz mode. If regular is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type. +} + +// ReplyKeyboardRemove Upon receiving a message with this object, +// Telegram clients will remove the current custom keyboard and display the default letter-keyboard. +// By default, custom keyboards are displayed until a new keyboard is sent by a bot. +// An exception is made for one-time keyboards that are hidden immediately after the user presses a button +// (see ReplyKeyboardMarkup). +type ReplyKeyboardRemove struct { + RemoveKeyboard bool `json:"remove_keyboard"` // Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup) + Selective bool `json:"selective,omitempty"` // Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. Example: A user votes in a poll, bot returns a confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet. +} + +// InlineKeyboardMarkup Represents an inline keyboard that appears right next to +// the message it belongs to. Note: This will only work in Telegram versions +// released after 9 April 2016. Older clients will display an unsupported message. +type InlineKeyboardMarkup struct { + InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"` // Array of button rows, each represented by an Array of InlineKeyboardButton objects +} + +// InlineKeyboardButton Represents one button of an inline keyboard. You must use exactly one of the optional fields. +type InlineKeyboardButton struct { + Text string `json:"text"` // Label text on the button + URL string `json:"url,omitempty"` // Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?id= can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings. + CallbackData string `json:"callback_data,omitempty"` // Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot. + WebApp *WebAppInfo `json:"web_app,omitempty"` // Optional. An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget. + LoginURL *LoginURL `json:"login_url,omitempty"` // Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes + SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Maybe empty, in which case just the bot's username will be inserted. Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm… actions - in this case, the user will be automatically returned to the chat they switched from, skipping the chat selection screen. + SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // Optional. If set, pressing the button will insert the bot's username and the specified inline query in the current chat's input field. Maybe empty, in which case only the bot's username will be inserted. This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options. + SwitchInlineQueryChosenChat *SwitchInlineQueryChosenChat `json:"switch_inline_query_chosen_chat,omitempty"` // Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field. + CallbackGame *CallbackGame `json:"callback_game,omitempty"` // Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row. + Pay bool `json:"pay,omitempty"` // Optional. Specify True, to send a Pay button. NOTE: This type of button must always be the first button in the first row and can only be used in invoice messages. +} + +// LoginURL Represents a parameter of the inline keyboard button used to automatically authorize a user. +// Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram. +// All the user needs to do is tap/click a button and confirm that they want to log in: +// Telegram apps support these buttons as of version 5.7. +// Sample bot: @discuss-bot +type LoginURL struct { + URL string `json:"url"` // An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in Receiving authorization data. NOTE: You must always check the hash of the received data to verify the authentication and the integrity of the data as described in Checking authorization. + ForwardText string `json:"forward_text,omitempty"` // Optional. New text of the button in forwarded messages. + BotUsername string `json:"bot_username,omitempty"` // Optional. Username of a bot, which will be used for user authorization. See Setting up a bot for more details. If not specified, the current bot's username will be assumed. The hurl's domain must be the same as the domain linked with the bot. See Linking your domain to the bot for more details. + RequestWriteAccess bool `json:"request_write_access,omitempty"` // Optional. Pass True to request the permission for your bot to send messages to the user. +} + +// SwitchInlineQueryChosenChat Represents an inline button that switches the current user to inline mode in a chosen chat, +// with an optional default inline query. +type SwitchInlineQueryChosenChat struct { + Query string `json:"query,omitempty"` // Optional. The default inline query to be inserted in the input field. If left empty, only the bot's username will be inserted + AllowUserChats bool `json:"allow_user_chats,omitempty"` // Optional. True, if private chats with users can be chosen + AllowBotChats bool `json:"allow_bot_chats,omitempty"` // Optional. True, if private chats with bots can be chosen + AllowGroupChats bool `json:"allow_group_chats,omitempty"` // Optional. True, if group and supergroup chats can be chosen + AllowChannelChats bool `json:"allow_channel_chats,omitempty"` // Optional. True, if channel chats can be chosen +} + +// CallbackQuery Represents an incoming callback query from a callback button in an inline keyboard. +// If the button that originated the query was attached to a message sent by the bot, the field message will be present. +// If the button was attached to a message sent via the bot (in inline mode), +// the field inline_message_id will be present. +// Exactly one of the field data or game_short_name will be present. +// NOTE: +// After the user presses a callback button, +// Telegram clients will display a progress bar until you call answerCallbackQuery. +// It is, therefore, necessary to react by calling answerCallbackQuery even if no notification to the user is needed +// (e.g., without specifying any of the optional parameters). +type CallbackQuery struct { + ID string `json:"id"` // Unique identifier for this query + From User `json:"from"` // Sender + Message *Message `json:"message,omitempty"` // Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old + InlineMessageID string `json:"inline_message_id,omitempty"` // Optional. Identifier of the message sent via the bot in inline mode, that originated the query. + ChatInstance string `json:"chat_instance"` // Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games. + Data string `json:"data,omitempty"` // Optional. Data associated with the callback button. Be aware that the message originated the query can contain no callback buttons with this data. + GameShortName string `json:"game_short_name,omitempty"` // Optional. Short name of a Game to be returned, serves as the unique identifier for the game +} + +// ForceReply Upon receiving a message with this object, +// Telegram clients will display a reply interface to the user +// (act as if the user has selected the bot's message and tapped 'Reply'). +// This can be extremely useful +// if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode. +// Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). +// There could be two ways to create a new poll: +// +// Explain the user how to send a command with parameters (e.g. /new poll question answer1 answer2). +// Maybe appealing for hardcore users but lacks modern day polish. +// Guide the user through a step-by-step process. +// 'Please send me your question', 'Cool, now let's add the first answer option', 'Great. +// Keep adding answer options, then send /done when you're ready'. +// The last option is definitely more attractive. +// And if you use ForceReply in your bot's questions, +// it will receive the user's answers even if it only receives replies, +// commands and mentions - without any extra work for the user. +type ForceReply struct { + ForceReply bool `json:"force_reply"` // Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply' + InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"` // Optional. The placeholder to be shown in the input field when the reply is active; 1-64 characters + Selective bool `json:"selective,omitempty"` // Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. +} + +// ChatPhoto Represents a chat photo. +type ChatPhoto struct { + SmallFileID string `json:"small_file_id"` // File identifier of a 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. + SmallFileUniqueID string `json:"small_file_unique_id"` // Unique file identifier of a 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. + BigFileID string `json:"big_file_id"` // File identifier of a 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. + BigFileUniqueID string `json:"big_file_unique_id"` // Unique file identifier of a 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. +} + +// ChatInviteLink Represents an invitation link for a chat. +type ChatInviteLink struct { + InviteLink string `json:"invite_link"` // The invite link. If the link was created by another chat administrator, then the second part of the link will be replaced with “…”. + Creator User `json:"creator"` // Creator of the link + CreatesJoinRequest bool `json:"creates_join_request"` // True, if users joining the chat via the link need to be approved by chat administrators + IsPrimary bool `json:"is_primary"` // True, if the link is primary + IsRevoked bool `json:"is_revoked"` // True, if the link is revoked + Name string `json:"name,omitempty"` // Optional. Invite link name + ExpireDate int64 `json:"expire_date,omitempty"` // Optional. Point in time (Unix timestamp) when the link will expire or has been expired + MemberLimit int `json:"member_limit,omitempty"` // Optional. The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 + PendingJoinRequestCount int `json:"pending_join_request_count,omitempty"` // Optional. Number of pending join requests created using this link +} + +// ChatAdministratorRights Represents the rights of an administrator in a chat. +type ChatAdministratorRights struct { + IsAnonymous bool `json:"is_anonymous"` // True, if the user's presence in the chat is hidden + CanManageChat bool `json:"can_manage_chat"` // True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege + CanDeleteMessages bool `json:"can_delete_messages"` // True, if the administrator can delete messages of other users + CanManageVideoChats bool `json:"can_manage_video_chats"` // True, if the administrator can manage video chats + CanRestrictMembers bool `json:"can_restrict_members"` // True, if the administrator can restrict, ban or unban chat members + CanPromoteMembers bool `json:"can_promote_members"` // True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user) + CanChangeInfo bool `json:"can_change_info"` // True, if the user is allowed to change the chat title, photo and other settings + CanInviteUsers bool `json:"can_invite_users"` // True, if the user is allowed to invite new users to the chat + CanPostMessages bool `json:"can_post_messages,omitempty"` // Optional. True, if the administrator can post in the channel; channels only + CanEditMessages bool `json:"can_edit_messages,omitempty"` // Optional. True, if the administrator can edit messages of other users and can pin messages; channels only + CanPinMessages bool `json:"can_pin_messages,omitempty"` // Optional. True, if the user is allowed to pin messages, groups and supergroups only + CanPostStories bool `json:"can_post_stories,omitempty"` // Optional. True, if the administrator can post stories in the channel; channels only + CanEditStories bool `json:"can_edit_stories,omitempty"` // Optional. True, if the administrator can edit stories posted by other users; channels only + CanDeleteStories bool `json:"can_delete_stories,omitempty"` // Optional. True, if the administrator can delete stories posted by other users; channels only + CanManageTopics bool `json:"can_manage_topics,omitempty"` // Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only +} + +// ChatMemberUpdated Represents changes in the status of a chat member. +type ChatMemberUpdated struct { + Chat Chat `json:"chat"` // the user belongs to + From User `json:"from"` // Performer of the action, which resulted in the change + Date int `json:"date"` // the change was done in Unix time + OldChatMember ChatMember `json:"old_chat_member"` // Previous information about the chat member + NewChatMember ChatMember `json:"new_chat_member"` // New information about the chat member + InviteLink *ChatInviteLink `json:"invite_link,omitempty"` // Optional. Chat invite link, which was used by the user to join the chat; for joining by invite link events only. + ViaJoinRequest bool `json:"via_join_request,omitempty"` // Optional. True, if the user joined the chat after sending a direct join request without using an invite link and being approved by an administrator + ViaChatFolderInviteLink bool `json:"via_chat_folder_invite_link,omitempty"` // Optional. True, if the user joined the chat via a chat folder invite link +} + +// ChatMember Contains information about one member of a chat. Currently, the following six types of chat members are supported: +type ChatMember struct { + User *User `json:"user"` // User information about the user + Status string `json:"status"` // The member's status in the chat. Can be “creator”,“administrator,” “member,” “restricted,” “left” or “kicked” + CustomTitle string `json:"custom_title,omitempty"` // Optional. owner and administrators only. Custom title for this user + IsAnonymous bool `json:"is_anonymous,omitempty"` // Optional. Owner and administrators only. True, if the user's presence in the chat is hidden + UntilDate int64 `json:"until_date,omitempty"` // Optional. Restricted and kicked only. Date when restrictions will be lifted for this user; unix time. + CanBeEdited bool `json:"can_be_edited,omitempty"` // Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user. + CanManageChat bool `json:"can_manage_chat,omitempty"` // Optional. Administrators only. True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege. + CanPostMessages bool `json:"can_post_messages,omitempty"` // Optional. administrators only. True, if the administrator can post in the channel; channels only. + CanEditMessages bool `json:"can_edit_messages,omitempty"` // Optional. administrators only. True, if the administrator can edit messages of other users and can pin messages; channels only. + CanDeleteMessages bool `json:"can_delete_messages,omitempty"` // Optional. administrators only. True, if the administrator can delete messages of other users. + CanPostStories bool `json:"can_post_stories,omitempty"` // Optional. True, if the administrator can post stories in the channel; channels only + CanEditStories bool `json:"can_edit_stories,omitempty"` // Optional. True, if the administrator can edit stories posted by other users; channels only + CanDeleteStories bool `json:"can_delete_stories,omitempty"` // Optional. True, if the administrator can delete stories posted by other users; channels only + CanManageVideoChats bool `json:"can_manage_video_chats,omitempty"` // Optional. administrators only. True, if the administrator can manage video chats. + CanRestrictMembers bool `json:"can_restrict_members,omitempty"` // Optional. administrators only. True, if the administrator can restrict, ban or unban chat members. + CanPromoteMembers bool `json:"can_promote_members,omitempty"` // Optional. administrators only. True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user). + CanChangeInfo bool `json:"can_change_info,omitempty"` // Optional. administrators and restricted only. True, if the user is allowed to change the chat title, photo and other settings. + CanInviteUsers bool `json:"can_invite_users,omitempty"` // Optional. administrators and restricted only. True, if the user is allowed to invite new users to the chat. + CanPinMessages bool `json:"can_pin_messages,omitempty"` // Optional. administrators and restricted only. True, if the user is allowed to pin messages, groups and supergroups only + IsMember bool `json:"is_member,omitempty"` // Optional. restricted only. True, if the user is a member of the chat at the moment of the request + CanSendMessages bool `json:"can_send_messages,omitempty"` // Optional. restricted only. True, if the user is allowed to send text messages, contacts, invoices, locations and venues + CanSendAudios bool `json:"can_send_audios,omitempty"` // Optional. restricted only. True, if the user is allowed to send audios + CanSendDocuments bool `json:"can_send_documents,omitempty"` // Optional. restricted only. True, if the user is allowed to send documents + CanSendPhotos bool `json:"can_send_photos,omitempty"` // Optional. restricted only. True, if the user is allowed to send photos + CanSendVideos bool `json:"can_send_videos,omitempty"` // Optional. restricted only. True, if the user is allowed to send videos + CanSendVideoNotes bool `json:"can_send_video_notes,omitempty"` // Optional. restricted only. True, if the user is allowed to send video notes + CanSendVoiceNotes bool `json:"can_send_voice_notes,omitempty"` // Optional. Restricted only. True, if the user is allowed to send voice notes + CanSendPolls bool `json:"can_send_polls,omitempty"` // Optional. restricted only. True, if the user is allowed to send polls + CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // Optional. restricted only. True, if the user is allowed to send audio, documents, photos, videos, video notes and voice notes. + CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` // Optional. Restricted only. True, if the user is allowed to add web page previews to their messages. + CanManageTopics bool `json:"can_manage_topics,omitempty"` // Optional. administrators and restricted only. true, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only +} + +// ChatJoinRequest Represents a join request sent to a chat. +type ChatJoinRequest struct { + Chat Chat `json:"chat"` // to which the request was sent + From User `json:"from"` // that sent the join request + UserChatId int64 `json:"user_chat_id"` // Identifier of a private chat with the user who sent the join request. 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 is safe for storing this identifier. The bot can use this identifier for 24 hours to send messages until the join request is processed, assuming no other administrator contacted the user. + Date int64 `json:"date"` // the request was sent in Unix time + Bio string `json:"bio,omitempty"` // Optional. Bio of the user. + InviteLink *ChatInviteLink `json:"invite_link,omitempty"` // Optional. Chat invite link that was used by the user to send the join request +} + +// ChatPermissions Describes actions that a non-administrator user is allowed to take in a chat. +type ChatPermissions struct { + CanSendMessages bool `json:"can_send_messages,omitempty"` // Optional. True, if the user is allowed to send text messages, contacts, locations and venues + CanSendAudios bool `json:"can_send_audios,omitempty"` // Optional. True, if the user is allowed to send audios + CanSendDocuments bool `json:"can_send_documents,omitempty"` // Optional. True, if the user is allowed to send documents + CanSendPhotos bool `json:"can_send_photos,omitempty"` // Optional. True, if the user is allowed to send photos + CanSendVideos bool `json:"can_send_videos,omitempty"` // Optional. True, if the user is allowed to send videos + CanSendVideoNotes bool `json:"can_send_video_notes,omitempty"` // Optional. True, if the user is allowed to send video notes + CanSendVoiceNotes bool `json:"can_send_voice_notes,omitempty"` // Optional. True, if the user is allowed to send voice notes + CanSendPolls bool `json:"can_send_polls,omitempty"` // Optional. True, if the user is allowed to send polls, it implies can_send_messages + CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, it implies can_send_media_messages + CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` // Optional. True, if the user is allowed to add web page previews to their messages, it implies can_send_media_messages + CanChangeInfo bool `json:"can_change_info,omitempty"` // Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups + CanInviteUsers bool `json:"can_invite_users,omitempty"` // Optional. True, if the user is allowed to invite new users to the chat + CanPinMessages bool `json:"can_pin_messages,omitempty"` // Optional. True, if the user is allowed to pin messages. Ignored in public supergroups + CanManageTopics bool `json:"can_manage_topics,omitempty"` // Optional. True, if the user is allowed to create forum topics. If omitted, defaults to the value of can_pin_messages +} + +// Birthdate // +type Birthdate struct { + Day int `json:"day"` // Day of the user's birth; 1-31 + Month int `json:"month"` // Month of the user's birth; 1-12 + Year int `json:"year,omitempty"` // Optional. Year of the user's birth +} + +// BusinessIntro // +type BusinessIntro struct { + Title string `json:"title,omitempty"` // Optional. Title text of the business intro + Message string `json:"message,omitempty"` // Optional. Message text of the business intro + Sticker *Sticker `json:"sticker,omitempty"` // Optional. Sticker of the business intro +} + +// BusinessLocation // +type BusinessLocation struct { + Address string `json:"address"` // Address of the business + Location *Location `json:"location,omitempty"` // Optional. Location of the business +} + +// BusinessOpeningHoursInterval // +type BusinessOpeningHoursInterval struct { + 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"` // The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60 +} + +// BusinessOpeningHours // +type BusinessOpeningHours struct { + TimeZoneName string `json:"time_zone_name"` // Unique name of the time zone for which the opening hours are defined + OpeningHours []*BusinessOpeningHoursInterval `json:"opening_hours"` // List of time intervals describing business opening hours +} + +// ChatLocation Represents a location to which a chat is connected. +type ChatLocation struct { + Location Location `json:"location"` // The location to which the supergroup is connected. Can't be a live location. + Address string `json:"address"` // Location address; 1-64 characters, as defined by the chat owner +} + +// ReactionType Describes the type of a reaction. Currently, it can be one of +type ReactionType struct { + ReactionTypeEmoji ReactionTypeEmoji + ReactionTypeCustomEmoji ReactionTypeCustomEmoji +} + +// ReactionTypeEmoji Reaction is based on an emoji. +type ReactionTypeEmoji struct { + Type string `json:"type"` // Type of the reaction, always “emoji” + Emoji string `json:"emoji"` // Reaction emoji. Currently, it can be one of "👍", "👎", "❤", "🔥", "🥰", "👏", "😁", "🤔", "🤯", "😱", "🤬", "😢", "🎉", "🤩", "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱", "🥴", "😍", "🐳", "❤‍🔥", "🌚", "🌭", "💯", "🤣", "⚡", "🍌", "🏆", "💔", "🤨", "😐", "🍓", "🍾", "💋", "🖕", "😈", "😴", "😭", "🤓", "👻", "👨‍💻", "👀", "🎃", "🙈", "😇", "😨", "🤝", "✍", "🤗", "🫡", "🎅", "🎄", "☃", "💅", "🤪", "🗿", "🆒", "💘", "🙉", "🦄", "😘", "💊", "🙊", "😎", "👾", "🤷‍♂", "🤷", "🤷‍♀", "😡" +} + +// ReactionTypeCustomEmoji Reaction is based on a custom emoji. +type ReactionTypeCustomEmoji struct { + Type string `json:"type"` // Type of the reaction, always “custom_emoji” + CustomEmoji string `json:"custom_emoji"` // Custom emoji identifier +} + +// ReactionCount Represents a reaction added to a message along with the number of times it was added. +type ReactionCount struct { + Type ReactionType `json:"type"` // Type of the reaction + TotalCount int `json:"total_count"` // Number of times the reaction was added +} + +// MessageReactionUpdated Represents a change of a reaction on a message performed by a user. +type MessageReactionUpdated struct { + Chat Chat `json:"chat"` // The chat containing the message the user reacted to + MessageId int `json:"message_id"` // Unique identifier of the message inside the chat + User *User `json:"user,omitempty"` // Optional. The user that changed the reaction, if the user isn't anonymous + ActorChat *Chat `json:"actor_chat,omitempty"` // Optional. The chat on behalf of which the reaction was changed, if the user is anonymous + Date int64 `json:"date"` // Date of the change in Unix time + OldReaction []ReactionType `json:"old_reaction"` // Previous list of reaction types that were set by the user + NewReaction []ReactionType `json:"new_reaction"` // New list of reaction types that have been set by the user +} + +// MessageReactionCountUpdated Represents reaction changes on a message with anonymous reactions. +type MessageReactionCountUpdated struct { + Chat Chat `json:"chat"` // The chat containing the message + MessageId int `json:"message_id"` // Unique message identifier inside the chat + Date int64 `json:"date"` // Date of the change in Unix time + Reactions []ReactionCount `json:"reactions"` // List of reactions that are present on the message +} + +// ForumTopic Represents a forum topic. +type ForumTopic struct { + MessageThreadID int64 `json:"message_thread_id"` // Unique identifier of the forum topic + Name string `json:"name"` // Name of the topic + IconColor int `json:"icon_color"` // Color of the topic icon in RGB format + IconCustomEmojiID string `json:"icon_custom_emoji_id,omitempty"` // Optional. Unique identifier of the custom emoji shown as the topic icon +} + +// BotCommand Represents a bot command. +type BotCommand struct { + Command string `json:"command"` // Text of the command; 1-32 characters. Can contain only lowercase English letters, digits and underscores. + Description string `json:"description"` // Description of the command; 1-256 characters. +} + +// BotCommandScope Represents the scope to which bot commands are applied. Currently, the following seven scopes are supported. +type BotCommandScope struct { + Type string `json:"type"` + ChatID int64 `json:"chat_id"` + UserID int64 `json:"user_id"` +} + +// BotCommandScopeDefault Represents the default scope of bot commands. +// Default commands are used if no commands with a narrower scope are specified for the user. +type BotCommandScopeDefault struct { + Type string `json:"type"` // Scope type must be default +} + +// BotCommandScopeAllPrivateChats Represents the scope of bot commands, covering all private chats. +type BotCommandScopeAllPrivateChats struct { + Type string `json:"type"` // Scope type, must be all_private_chats +} + +// BotCommandScopeAllGroupChats Represents the scope of bot commands, covering all group and supergroup chats. +type BotCommandScopeAllGroupChats struct { + Type string `json:"type"` // Scope type, must be all_group_chats +} + +// BotCommandScopeAllChatAdministrators Represents the scope of bot commands, covering all group and supergroup chat administrators. +type BotCommandScopeAllChatAdministrators struct { + Type string `json:"type"` // Scope type, must be all_chat_administrators +} + +// BotCommandScopeChat Represents the scope of bot commands, covering a specific chat. +type BotCommandScopeChat struct { + Type string `json:"type"` // Scope type must be chat + ChatID string `json:"chat_id"` // Unique identifier for the target chat or username of the target supergroup (in the format @supergroup username) +} + +// BotCommandScopeChatAdministrators Represents the scope of bot commands, covering all administrators of a specific group or supergroup chat. +type BotCommandScopeChatAdministrators struct { + Type string `json:"type"` // Scope type, must be chat_administrators + ChatID string `json:"chat_id"` // Unique identifier for the target chat or username of the target supergroup (in the format @supergroup username) +} + +// BotCommandScopeChatMember Represents the scope of bot commands, covering a specific member of a group or supergroup chat. +type BotCommandScopeChatMember struct { + Type string `json:"type"` // Scope type, must be chat_member + ChatID string `json:"chat_id"` // Unique identifier for the target chat or username of the target supergroup (in the format @supergroup username) + UserID int64 `json:"user_id"` // Unique identifier of the target user +} + +// BotName represents the bot's name. +type BotName struct { + Name string `json:"name"` // The bot's name +} + +// BotDescription represents the bot's description. +type BotDescription struct { + Description string `json:"description"` // The bot's description +} + +// BotShortDescription represents the bot's short description. +type BotShortDescription struct { + ShortDescription string `json:"short_description"` // The bot's short description +} + +// MenuButton describes the bot's menu button in a private chat. +// If a menu button other than MenuButtonDefault is set for a private chat, then it is applied in the chat. +// Otherwise, the default menu button is applied. +// By default, the menu button opens the list of bot commands. +type MenuButton struct { + Type string `json:"type"` // Type of the button must be commands + Text string `json:"text"` // Text on the button + WebApp *WebAppInfo `json:"web_app"` // Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. +} + +// MenuButtons describes the bot's menu button in a private chat. +// If a menu button other than MenuButtonDefault is set for a private chat, then it is applied in the chat. +// Otherwise, the default menu button is applied. +// By default, the menu button opens the list of bot commands. +type MenuButtons struct { + MenuButtonCommands MenuButtonCommands + MenuButtonWebApp MenuButtonWebApp + MenuButtonDefault MenuButtonDefault +} + +// MenuButtonCommands Represents a menu button, which opens the bot's list of commands. +type MenuButtonCommands struct { + Type string `json:"type"` // Type of the button must be commands +} + +// MenuButtonWebApp Represents a menu button, which launches a Web App. +type MenuButtonWebApp struct { + Type string `json:"type"` // The Type of the button, must be web_app + Text string `json:"text"` // Text on the button + WebApp *WebAppInfo `json:"web_app"` // Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. +} + +// MenuButtonDefault Describes that no specific value for the menu button was set. +type MenuButtonDefault struct { + Type string `json:"type"` // Type of the button must be default +} + +// ChatBoostSource Describes the source of a chat boost. It can be one of +type ChatBoostSource struct { + ChatBoostSourcePremium + ChatBoostSourceGiftCode + ChatBoostSourceGiveaway +} + +// ChatBoostSourcePremium Obtained by subscribing to Telegram Premium or by gifting a Telegram Premium subscription to another user. +type ChatBoostSourcePremium struct { + Source string `json:"source"` // Source of the boost, always “premium” + User User `json:"user"` // User that boosted the chat +} + +// ChatBoostSourceGiftCode Obtained by the creation of Telegram Premium gift codes to boost a chat. Each such code boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription. +type ChatBoostSourceGiftCode struct { + Source string `json:"source"` // Source of the boost, always “gift_code” + User User `json:"user"` // User for which the gift code was created +} + +// ChatBoostSourceGiveaway Obtained by the creation of a Telegram Premium giveaway. This boosts the chat 4 times for the duration of the corresponding Telegram Premium subscription. +type ChatBoostSourceGiveaway struct { + Source string `json:"source"` // Source of the boost, always “giveaway” + GiveawayMessageId int `json:"giveaway_message_id"` // Identifier of a message in the chat with the giveaway; the message could have been deleted already. May be 0 if the message isn't sent yet. + User *User `json:"user,omitempty"` // Optional. User that won the prize in the giveaway if any + IsUnclaimed bool `json:"is_unclaimed,omitempty"` // Optional. True, if the giveaway was completed, but there was no user to win the prize +} + +// ChatBoost Represents a boost added to a chat or changed. +type ChatBoost struct { + BoostID string `json:"boost_id"` // Unique identifier of the boost + AddDate int64 `json:"add_date"` // Point in time (Unix timestamp) when the chat was boosted + ExpirationDate int64 `json:"expiration_date"` // Point in time (Unix timestamp) when the boost will automatically expire, unless the booster's Telegram Premium subscription is prolonged + Source ChatBoostSource `json:"source"` // Source of the added boost +} + +// ChatBoostUpdated Represents a boost added to a chat or changed. +type ChatBoostUpdated struct { + Chat Chat `json:"chat"` // Chat which was boosted + Boost ChatBoost `json:"boost"` // Infomation about the chat boost +} + +// ChatBoostRemoved Represents a boost removed from a chat. +type ChatBoostRemoved struct { + Chat Chat `json:"chat"` // Chat which was boosted + BoostId string `json:"boost_id"` // Unique identifier of the boost + RemoveDate int64 `json:"remove_date"` // Point in time (Unix timestamp) when the boost was removed + Source ChatBoostSource `json:"source"` // Source of the removed boost +} + +// UserChatBoosts Represents a boost removed from a chat. +type UserChatBoosts struct { + Boosts []ChatBoost `json:"boosts"` // The list of boosts added to the chat by the user +} + +// BusinessConnection Describes the connection of the bot with a business account. +type BusinessConnection struct { + ID string `json:"id"` // Unique identifier of the business connection + User User `json:"user"` // Business account user that created the business connection + UserChatId int64 `json:"user_chat_id"` // 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. + Date int64 `json:"date"` // Date the connection was established in Unix time + CanReply bool `json:"can_reply"` // True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours + IsEnabled bool `json:"is_enabled"` // True, if the connection is active +} + +// BusinessMessagesDeleted Received when messages are deleted from a connected business account. +type BusinessMessagesDeleted struct { + BusinessConnectionId string `json:"business_connection_id"` // Unique identifier of the business connection + Chat Chat `json:"chat"` // Information about a chat in the business account. The bot may not have access to the chat or the corresponding user. + MessageIds []int `json:"message_ids"` // A JSON-serialized list of identifiers of deleted messages in the chat of the business account +} + +// ResponseParameters are various errors that can be returned in APIResponse. +type ResponseParameters struct { + MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // Optional. The group has been migrated to a supergroup with the specified identifier. 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 signed 64-bit integer or double-precision float type is safe for storing this identifier. + RetryAfter int `json:"retry_after,omitempty"` // Optional. In case of exceeding flood control, the number of seconds left to wait before the request can be repeated +} + +// InputMedia Represents the content of a media message to be sent. It should be one of +type InputMedia struct { + InputMediaAnimation InputMediaAnimation + InputMediaDocument InputMediaDocument + InputMediaAudio InputMediaAudio + InputMediaPhoto InputMediaPhoto + InputMediaVideo InputMediaVideo +} + +// InputMediaPhoto Represents a photo to be sent. +type InputMediaPhoto struct { + Type string `json:"type"` // Type of the result must be photoed + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + Caption string `json:"caption,omitempty"` // Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the photo caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + HasSpoiler bool `json:"has_spoiler,omitempty"` // Optional. Pass True if the photo needs to be covered with a spoiler animation +} + +// InputMediaVideo Represents a video to be sent. +type InputMediaVideo struct { + Type string `json:"type"` // Type of the result must be video + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + Thumbnail RequestFileData `json:"thumb,thumbnail,omitempty"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . + Caption string `json:"caption,omitempty"` // Optional. Caption of the video to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the video caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + Width int `json:"width,omitempty"` // Optional. Video width + Height int `json:"height,omitempty"` // Optional. Video height + Duration int `json:"duration,omitempty"` // Optional. Video duration in seconds + SupportsStreaming bool `json:"supports_streaming,omitempty"` // Optional. Pass True, if the uploaded video is suitable for streaming + HasSpoiler bool `json:"has_spoiler,omitempty"` // Optional. Pass True if the video needs to be covered with a spoiler animation +} + +// InputMediaAnimation Represents an animation file (GIF or H.264/MPEG-4 AVC video without a sound) to be sent. +type InputMediaAnimation struct { + Type string `json:"type"` // The Type of the result must be animation + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + Thumbnail RequestFileData `json:"thumb,thumbnail,omitempty"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . + Caption string `json:"caption,omitempty"` // Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the animation caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + Width int `json:"width,omitempty"` // Optional. Animation width + Height int `json:"height,omitempty"` // Optional. Animation height + Duration int `json:"duration,omitempty"` // Optional. Animation duration in seconds + HasSpoiler bool `json:"has_spoiler,omitempty"` // Optional. Pass True if the animation needs to be covered with a spoiler animation +} + +// InputMediaAudio Represents an audio file to be treated as music to be sent. +type InputMediaAudio struct { + Type string `json:"type"` // The Type of the result must be audio + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + Thumbnail RequestFileData `json:"thumb,thumbnail,omitempty"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . + Caption string `json:"caption,omitempty"` // Optional. Caption of the audio to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the audio caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + Duration int `json:"duration,omitempty"` // Optional. Duration of the audio in seconds + Performer string `json:"performer,omitempty"` // Optional. Performer of the audio + Title string `json:"title,omitempty"` // Optional. Title of the audio +} + +// InputMediaDocument Represents a general file to be sent. +type InputMediaDocument struct { + Type string `json:"type"` // The Type of the result must be documented + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + Thumbnail RequestFileData `json:"thumb,thumbnail,omitempty"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . + Caption string `json:"caption,omitempty"` // Optional. Caption of the document to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the document caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"` // Optional. Disables automatic server-side content type detection for files uploaded using multipart/form-data. Always True, if the document is sent as part of an album. +} + +// InputPaidMedia Describes the paid media to be sent. Currently, it can be one of +type InputPaidMedia struct { + InputPaidMediaPhoto InputPaidMediaPhoto + InputPaidMediaVideo InputPaidMediaVideo +} + +// InputPaidMediaPhoto The paid media to send is a photo. +type InputPaidMediaPhoto struct { + Type string `json:"type"` // Type of the media, must be photo + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. +} + +// InputPaidMediaVideo The paid media to send is a video. +type InputPaidMediaVideo struct { + Type string `json:"type"` // Type of the result must be photoed + Media RequestFileData `json:"media"` // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://” to upload a new one using multipart/form-data under name. + Thumbnail RequestFileData `json:"thumb,thumbnail,omitempty"` // Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . + Width int `json:"width,omitempty"` // Optional. Video width + Height int `json:"height,omitempty"` // Optional. Video height + Duration int `json:"duration,omitempty"` // Optional. Video duration in seconds + SupportsStreaming bool `json:"supports_streaming,omitempty"` // Optional. Pass True, if the uploaded video is suitable for streaming +} + +// Sticker Represents a sticker. +type Sticker struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + Type string `json:"type"` // Type of the sticker, currently one of “regular,” “masks,” “custom_emoji.” The type of the sticker is independent of its format, which is determined by the fields is_animated and is_video. + Width int `json:"width"` // Sticker width + Height int `json:"height"` // Sticker height + IsAnimated bool `json:"is_animated"` // True, if the sticker is animated + IsVideo bool `json:"is_video"` // True, if the sticker is a video sticker + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Sticker thumbnail in the .WEBP or .JPG format + Emoji string `json:"emoji,omitempty"` // Optional. Emoji associated with the sticker + SetName string `json:"set_name,omitempty"` // Optional. Name of the sticker set to which the sticker belongs + PremiumAnimation *File `json:"premium_animation,omitempty"` // Optional. Premium animation for the sticker, if the sticker is premium + MaskPosition *MaskPosition `json:"mask_position,omitempty"` // Optional. For mask stickers, the position where the mask should be placed + CustomEmojiID string `json:"custom_emoji_id,omitempty"` // Optional. For custom emoji stickers, unique identifier of the custom emoji + NeedsRepainting bool `json:"needs_repainting,omitempty"` // Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places + FileSize int64 `json:"file_size,omitempty"` // Optional. File size in bytes +} + +// StickerSet Represents a sticker set. +type StickerSet struct { + Name string `json:"name"` // Sticker set name + Title string `json:"title"` // Sticker set title + StickerType string `json:"sticker_type"` // Type of stickers in the set, currently one of “regular,” “masks,” “custom_emoji” + Stickers []Sticker `json:"stickers"` // List of all set stickers + Thumbnail *PhotoSize `json:"thumb,thumbnail,omitempty"` // Optional. Sticker set thumbnail in the .WEBP, .TGS, or .WEBM format +} + +// MaskPosition Describes the position on faces where a mask should be placed by default. by default. +type MaskPosition struct { + Point string `json:"point"` // The part of the face relative to which the mask should be placed. One of “foreheads,” “eyes,” “mouth,” or “chin.” + XShift float64 `json:"x_shift"` // Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position. + YShift float64 `json:"y_shift"` // Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position. + Scale float64 `json:"scale"` // Mask scaling coefficient. For example, 2.0 means double size. +} + +// InputSticker Describes a sticker to be added to a sticker set. +type InputSticker struct { + Sticker RequestFileData `json:"sticker"` // The added sticker. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated and video stickers can't be uploaded via HTTP URL. + Format string `json:"format"` // Format of the added sticker, must be one of “static” for a .WEBP or .PNG image, “animated” for a .TGS animation, “video” for a WEBM video + EmojiList []string `json:"emoji_list"` // List of 1-20 emoji associated with the sticker + MaskPosition *MaskPosition `json:"mask_position"` // Optional. Position where the mask should be placed on faces. For “mask” stickers only. + Keywords []string `json:"keywords"` // Optional. List of 0-20 search keywords for the sticker with total length of up to 64 characters. For “regular” and “custom_emoji” stickers only. +} + +// InlineQuery Represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results. +type InlineQuery struct { + ID string `json:"id"` // Unique identifier for this query + From User `json:"from"` // Sender + Query string `json:"query"` // Text of the query (up to 256 characters) + Offset string `json:"offset"` // the bot can control the offset of the results to be returned. + ChatType string `json:"chat_type,omitempty"` // Optional. Type of the chat from which the inline query was sent. Can be either “sender” for a private chat with the inline query sender, “private,” “group,” “supergroup,” or “channel.” The chat type should always be known for requests sent from official clients and most third-party clients, unless the request was sent from a secret chat + Location *Location `json:"location,omitempty"` // Optional. Sender location, only for bots that request user location +} + +// InlineQueryResultsButton Represents a button to be shown above inline query results. You must use exactly one of the optional fields. +type InlineQueryResultsButton struct { + Text string `json:"text"` // Label text on the button + WebApp *WebAppInfo `json:"web_app,omitempty"` // 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 web_app_switch_inline_query inside the Web App. + StartParameter *string `json:"start_parameter,omitempty"` // 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. Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before shows any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an OAuth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities. +} + +// InlineQueryResult Represents one result of an inline query. Telegram clients currently support results of the following 20 types +// Note: All URLs passed in inline query results will be available to end users and therefore must be assumed to be public. +type InlineQueryResult struct { + InlineQueryResultArticle InlineQueryResultArticle + InlineQueryResultPhoto InlineQueryResultPhoto + InlineQueryResultGif InlineQueryResultGIF + InlineQueryResultMpeg4Gif InlineQueryResultMPEG4GIF + InlineQueryResultVideo InlineQueryResultVideo + InlineQueryResultAudio InlineQueryResultAudio + InlineQueryResultVoice InlineQueryResultVoice + InlineQueryResultDocument InlineQueryResultDocument + InlineQueryResultLocation InlineQueryResultLocation + InlineQueryResultVenue InlineQueryResultVenue + InlineQueryResultContact InlineQueryResultContact + InlineQueryResultGame InlineQueryResultGame + InlineQueryResultCachedPhoto InlineQueryResultCachedPhoto + InlineQueryResultCachedGif InlineQueryResultCachedGIF + InlineQueryResultCachedMpeg4Gif InlineQueryResultCachedMPEG4GIF + InlineQueryResultCachedSticker InlineQueryResultCachedSticker + InlineQueryResultCachedDocument InlineQueryResultCachedDocument + InlineQueryResultCachedVideo InlineQueryResultCachedVideo + InlineQueryResultCachedVoice InlineQueryResultCachedVoice + InlineQueryResultCachedAudio InlineQueryResultCachedAudio +} + +// InlineQueryResultArticle Represents a link to an article or web page. +type InlineQueryResultArticle struct { + Type string `json:"type"` // the type of the result must be article + ID string `json:"id"` // Unique identifier for this result, 1-64 Bytes + Title string `json:"title"` // title of the result + InputMessageContent any `json:"input_message_content"` // Content of the message to be sent + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + URL string `json:"url,omitempty"` // Optional. URL of the result + HideURL bool `json:"hide_url,omitempty"` // Optional. Pass True, if you don't want the URL to be shown in the message + Description string `json:"description,omitempty"` // Optional. Short description of the result + ThumbnailURL string `json:"thumb_url,thumbnail_url,omitempty"` // Optional. Url of the thumbnail for the result + ThumbnailWidth int `json:"thumb_width,thumbnail_width,omitempty"` // Optional. Thumbnail width + ThumbnailHeight int `json:"thumb_height,thumbnail_height,omitempty"` // Optional. Thumbnail height +} + +// InlineQueryResultPhoto Represents a link to a photo. +// By default, this photo will be sent by the user with optional caption. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. +type InlineQueryResultPhoto struct { + Type string `json:"type"` // type of the result must be photoed + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + URL string `json:"photo_url"` // A valid URL of the photo. Photo must be in JPEG format. Photo size must not exceed 5MB + ThumbnailURL string `json:"thumb_url,thumbnail_url"` // url of the thumbnail for the photo + Width int `json:"photo_width,omitempty"` // Optional. Width of the photo + Height int `json:"photo_height,omitempty"` // Optional. Height of the photo + Title string `json:"title"` // title of the result + Description string `json:"description,omitempty"` // Optional. Short description of the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the photo caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the photo +} + +// InlineQueryResultGIF Represents a link to an animated GIF file. +// By default, this animated GIF file will be sent by the user with optional caption. +// Alternatively, +// you can use input_message_content to send a message with the specified content instead of the animation. +type InlineQueryResultGIF struct { + Type string `json:"type"` // the type of the result must be gif + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + URL string `json:"gif_url"` // A valid URL for the GIF file. File size must not exceed 1MB + Width int `json:"gif_width,omitempty"` // Optional. Width of the GIF + Height int `json:"gif_height,omitempty"` // Optional. Height of the GIF + Duration int `json:"gif_duration,omitempty"` // Optional. Duration of the GIF in seconds + ThumbnailURL string `json:"thumb_url,thumbnail_url"` // url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result + ThumbnailMimeType string `json:"thumb_mime_type,thumbnail_mime_type,omitempty"` // Optional. MIME type of the thumbnail must be one of “image/jpeg,” “image/gif,” or “video/mp4.” Defaults to “image/jpeg” + Title string `json:"title,omitempty"` // Optional. Title for the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the GIF file to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the GIF animation +} + +// InlineQueryResultMPEG4GIF Represents a link to a video animation (H.264/MPEG-4 AVC video without a sound). +// By default, this animated MPEG-4 file will be sent by the user with optional caption. +// Alternatively, +// you can use input_message_content to send a message with the specified content instead of the animation. +type InlineQueryResultMPEG4GIF struct { + Type string `json:"type"` // type of the result must be mpeg4_gif + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + URL string `json:"mpeg4_url"` // A valid URL for the MPEG4 file. File size must not exceed 1MB + Width int `json:"mpeg4_width,omitempty"` // Optional. Video width + Height int `json:"mpeg4_height,omitempty"` // Optional. Video height + Duration int `json:"mpeg4_duration,omitempty"` // Optional. Video duration in seconds + ThumbnailURL string `json:"thumb_url,thumbnail_url"` // url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result + ThumbnailMimeType string `json:"thumb_mime_type,thumbnail_mime_type,omitempty"` // Optional. MIME type of the thumbnail must be one of “image/jpeg,” “image/gif,” or “video/mp4.” Defaults to “image/jpeg” + Title string `json:"title,omitempty"` // Optional. Title for the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the video animation +} + +// InlineQueryResultVideo Represents a link to a page containing an embedded video player or a video file. +// By default, this video file will be sent by the user with an optional caption. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the video. +// If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), +// you must replace its content using input_message_content. +type InlineQueryResultVideo struct { + Type string `json:"type"` // type of the result must be video + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + URL string `json:"video_url"` // A valid URL for the embedded video player or video file + MimeType string `json:"mime_type"` // MIME type of the content of the video URL, “text/html” or “video/mp4” + ThumbnailURL string `json:"thumb_url,thumbnail_url"` // url of the thumbnail (JPEG only) for the video + Title string `json:"title"` // title for the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the video to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the video caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + Width int `json:"video_width,omitempty"` // Optional. Video width + Height int `json:"video_height,omitempty"` // Optional. Video height + Duration int `json:"video_duration,omitempty"` // Optional. Video duration in seconds + Description string `json:"description,omitempty"` // Optional. Short description of the result + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video). +} + +// InlineQueryResultAudio Represents a link to an MP3 audio file. +// By default, this audio file will be sent by the user. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultAudio struct { + Type string `json:"type"` // the type of the result must be audio + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + URL string `json:"audio_url"` // A valid URL for the audio file + Title string `json:"title"` // title + Caption string `json:"caption,omitempty"` // Optional. Caption, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the audio caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + Performer string `json:"performer,omitempty"` // Optional. Performer + Duration int `json:"audio_duration,omitempty"` // Optional. Audio duration in seconds + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the audio +} + +// InlineQueryResultVoice Represents a link to a voice recording in an .OGG container encoded with OPUS. +// By default, this voice recording will be sent by the user. +// Alternatively, +// you can use input_message_content to send a message with the specified content instead of the voice message. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultVoice struct { + Type string `json:"type"` // the type of the result must be voice + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + URL string `json:"voice_url"` // A valid URL for the voice recording + Title string `json:"title"` // Recording title + Caption string `json:"caption,omitempty"` // Optional. Caption, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the voice message caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + Duration int `json:"voice_duration,omitempty"` // Optional. Recording duration in seconds + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the voice recording +} + +// InlineQueryResultDocument Represents a link to a file. +// By default, this file will be sent by the user with an optional caption. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the file. +// Currently, only .PDF and .ZIP files can be sent using this method. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultDocument struct { + Type string `json:"type"` // the type of the result must be documented + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + Title string `json:"title"` // title for the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the document to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the document caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + URL string `json:"document_url"` // A valid URL for the file + MimeType string `json:"mime_type"` // MIME type of the content of the file, either “application/pdf” or “application/zip” + Description string `json:"description,omitempty"` // Optional. Short description of the result + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the file + ThumbnailURL string `json:"thumb_url,thumbnail_url,omitempty"` // Optional. URL of the thumbnail (JPEG only) for the file + ThumbnailWidth int `json:"thumb_width,thumbnail_width,omitempty"` // Optional. Thumbnail width + ThumbnailHeight int `json:"thumb_height,thumbnail_height,omitempty"` // Optional. Thumbnail height +} + +// InlineQueryResultLocation Represents a location on a map. +// By default, the location will be sent by the user. +// Alternatively, +// you can use input_message_content to send a message with the specified content instead of the location. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultLocation struct { + Type string `json:"type"` // type of the result must be location + ID string `json:"id"` // Unique identifier for this result, 1-64 Bytes + Latitude float64 `json:"latitude"` // Location latitude in degrees + Longitude float64 `json:"longitude"` // Location longitude in degrees + Title string `json:"title"` // Location title + HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` // Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + LivePeriod int `json:"live_period,omitempty"` // Optional. The Period in seconds for which the location can be updated should be between 60 and 86400. + Heading int `json:"heading,omitempty"` // Optional. For live locations, the direction in which the user is moving in degrees. It Must be between 1 and 360 if specified. + ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"` // Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. It Must be between 1 and 100000 if specified. + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the location + ThumbnailURL string `json:"thumb_url,thumbnail_url,omitempty"` // Optional. Url of the thumbnail for the result + ThumbnailWidth int `json:"thumb_width,thumbnail_width,omitempty"` // Optional. Thumbnail width + ThumbnailHeight int `json:"thumb_height,thumbnail_height,omitempty"` // Optional. Thumbnail height +} + +// InlineQueryResultVenue Represents a venue. +// By default, the venue will be sent by the user. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the venue. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultVenue struct { + Type string `json:"type"` // type of the result must be venue + ID string `json:"id"` // Unique identifier for this result, 1-64 Bytes + Latitude float64 `json:"latitude"` // latitude of the venue location in degrees + Longitude float64 `json:"longitude"` // longitude of the venue location in degrees + Title string `json:"title"` // title of the venue + Address string `json:"address"` // address of the venue + FoursquareID string `json:"foursquare_id,omitempty"` // Optional. Foursquare identifier of the venue if known + FoursquareType string `json:"foursquare_type,omitempty"` // Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default,” “arts_entertainment/aquarium” or “food/ice cream.”) + GooglePlaceID string `json:"google_place_id,omitempty"` // Optional. Google Places identifier of the venue + GooglePlaceType string `json:"google_place_type,omitempty"` // Optional. Google Places a type of the venue. See [supported types](https://developers.google.com/places/web-service/supported_types). + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the venue + ThumbnailURL string `json:"thumb_url,thumbnail_url,omitempty"` // Optional. Url of the thumbnail for the result + ThumbnailWidth int `json:"thumb_width,thumbnail_width,omitempty"` // Optional. Thumbnail width + ThumbnailHeight int `json:"thumb_height,thumbnail_height,omitempty"` // Optional. Thumbnail height +} + +// InlineQueryResultContact Represents a contact with a phone number. +// By default, this contact will be sent by the user. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the contact. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultContact struct { + Type string `json:"type"` // type of the result must be contact + ID string `json:"id"` // Unique identifier for this result, 1-64 Bytes + PhoneNumber string `json:"phone_number"` // contact's phone number + FirstName string `json:"first_name"` // contact's first name + LastName string `json:"last_name,omitempty"` // Optional. Contact's last name + VCard string `json:"vcard,omitempty"` // Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the contact + ThumbnailURL string `json:"thumb_url,thumbnail_url,omitempty"` // Optional. Url of the thumbnail for the result + ThumbnailWidth int `json:"thumb_width,thumbnail_width,omitempty"` // Optional. Thumbnail width + ThumbnailHeight int `json:"thumb_height,thumbnail_height,omitempty"` // Optional. Thumbnail height +} + +// InlineQueryResultGame Represents a Game. +// Note: This will only work in Telegram versions released after October 1, 2016. +// Older clients will not display any inline results if a game result is among them. +type InlineQueryResultGame struct { + Type string `json:"type"` // type of the result must be game + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + GameShortName string `json:"game_short_name"` // Short name of the game + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message +} + +// InlineQueryResultCachedPhoto Represents a link to a photo stored on the Telegram servers. +// By default, this photo will be sent by the user with an optional caption. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the photo. +type InlineQueryResultCachedPhoto struct { + Type string `json:"type"` // type of the result must be photoed + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + PhotoID string `json:"photo_file_id"` // A valid file identifier of the photo + Title string `json:"title,omitempty"` // Optional. Title for the result + Description string `json:"description,omitempty"` // Optional. Short description of the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the photo to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the photo caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the photo +} + +// InlineQueryResultCachedGIF Represents a link to an animated GIF file stored on the Telegram servers. +// By default, this animated GIF file will be sent by the user with an optional caption. +// Alternatively, you can use input_message_content to send a message with specified content instead of the animation. +type InlineQueryResultCachedGIF struct { + Type string `json:"type"` // the type of the result must be gif + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + GifID string `json:"gif_file_id"` // A valid file identifier for the GIF file + Title string `json:"title,omitempty"` // Optional. Title for the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the GIF file to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the GIF animation +} + +// InlineQueryResultCachedMPEG4GIF Represents a link to a video animation +// (H.264/MPEG-4 AVC video without a sound) stored on the Telegram servers. +// By default, this animated MPEG-4 file will be sent by the user with an optional caption. +// Alternatively, +// you can use input_message_content to send a message with the specified content instead of the animation. +type InlineQueryResultCachedMPEG4GIF struct { + Type string `json:"type"` // type of the result must be mpeg4_gif + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + MPEG4FileID string `json:"mpeg4_file_id"` // A valid file identifier for the MPEG4 file + Title string `json:"title,omitempty"` // Optional. Title for the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the video animation +} + +// InlineQueryResultCachedSticker Represents a link to a sticker stored on the Telegram servers. +// By default, this sticker will be sent by the user. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker. +// Note: +// This will only work in Telegram versions +// released after 9 April 2016 for static stickers and after 06 July 2019 for animated stickers. +// Older clients will ignore them. +type InlineQueryResultCachedSticker struct { + Type string `json:"type"` // the type of the result must be stickered + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + StickerID string `json:"sticker_file_id"` // A valid file identifier of the sticker + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the sticker +} + +// InlineQueryResultCachedDocument Represents a link to a file stored on the Telegram servers. +// By default, this file will be sent by the user with an optional caption. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the file. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultCachedDocument struct { + Type string `json:"type"` // the type of the result must be documented + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + Title string `json:"title"` // title for the result + DocumentID string `json:"document_file_id"` // A valid file identifier for the file + Description string `json:"description,omitempty"` // Optional. Short description of the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the document to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the document caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the file +} + +// InlineQueryResultCachedVideo Represents a link to a video file stored on the Telegram servers. +// By default, this video file will be sent by the user with an optional caption. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the video. +type InlineQueryResultCachedVideo struct { + Type string `json:"type"` // type of the result must be video + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + VideoID string `json:"video_file_id"` // A valid file identifier for the video file + Title string `json:"title"` // title for the result + Description string `json:"description,omitempty"` // Optional. Short description of the result + Caption string `json:"caption,omitempty"` // Optional. Caption of the video to be sent, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the video caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"` // Optional. Pass True, if the caption must be shown above the message media + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the video +} + +// InlineQueryResultCachedVoice Represents a link to a voice message stored on the Telegram servers. +// By default, this voice message will be sent by the user. +// Alternatively, +// you can use input_message_content to send a message with the specified content instead of the voice message. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultCachedVoice struct { + Type string `json:"type"` // the type of the result must be voice + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + VoiceID string `json:"voice_file_id"` // A valid file identifier for the voice message + Title string `json:"title"` // Voice message title + Caption string `json:"caption,omitempty"` // Optional. Caption, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the voice message caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the voice message +} + +// InlineQueryResultCachedAudio Represents a link to an MP3 audio file stored on the Telegram servers. +// By default, this audio file will be sent by the user. +// Alternatively, you can use input_message_content to send a message with the specified content instead of the audio. +// Note: This will only work in Telegram versions released after 9 April 2016. +// Older clients will ignore them. +type InlineQueryResultCachedAudio struct { + Type string `json:"type"` // The Type of the result must be audio + ID string `json:"id"` // Unique identifier for this result, 1-64 bytes + AudioID string `json:"audio_file_id"` // A valid file identifier for the audio file + Caption string `json:"caption,omitempty"` // Optional. Caption, 0-1024 characters after entities parsing + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the audio caption. See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details. + CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional. List of special entities that appear in the caption, which can be specified instead of parse_mode + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // Optional. Inline keyboard attached to the message + InputMessageContent any `json:"input_message_content,omitempty"` // Optional. Content of the message to be sent instead of the audio +} + +// InputMessageContent Represents the content of a message to be sent as a result of an inline query. +// Telegram clients currently support the following five types: +type InputMessageContent struct { + InputTextMessageContent InputTextMessageContent + InputLocationMessageContent InputLocationMessageContent + InputVenueMessageContent InputVenueMessageContent + InputContactMessageContent InputContactMessageContent + InputInvoiceMessageContent InputInvoiceMessageContent +} + +type InputTextMessageContent struct { + Text string `json:"message_text"` // text of the message to be sent, 1-4096 characters + ParseMode string `json:"parse_mode,omitempty"` // Optional. Mode for parsing entities in the message text. See formatting options for more details. + Entities []MessageEntity `json:"entities,omitempty"` // Optional. List of special entities that appear in message text, which can be specified instead of parse_mode + LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"` // Optional. Link preview generation options for the message +} + +// InputLocationMessageContent Represents the content of a location message to be sent as the result of an inline query. +type InputLocationMessageContent struct { + Latitude float64 `json:"latitude"` // latitude of the location in degrees + Longitude float64 `json:"longitude"` // longitude of the location in degrees + HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` // Optional. The radius of uncertainty for the location, measured in meters; 0-1500 + LivePeriod int `json:"live_period,omitempty"` // Optional. The Period in seconds for which the location can be updated should be between 60 and 86400. + Heading int `json:"heading,omitempty"` // Optional. For live locations, the direction in which the user is moving in degrees. It Must be between 1 and 360 if specified. + ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"` // Optional. For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. It Must be between 1 and 100000 if specified. +} + +// InputVenueMessageContent Represents the content of a venue message to be sent as the result of an inline query. +type InputVenueMessageContent struct { + Latitude float64 `json:"latitude"` // Latitude of the venue in degrees + Longitude float64 `json:"longitude"` // Longitude of the venue in degrees + Title string `json:"title"` // Name of the venue + Address string `json:"address"` // Address of the venue + FoursquareID string `json:"foursquare_id,omitempty"` // Optional. Foursquare identifier of the venue, if known + FoursquareType string `json:"foursquare_type,omitempty"` // Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default,” “arts_entertainment/aquarium” or “food/ice cream.”) + GooglePlaceID string `json:"google_place_id,omitempty"` // Optional. Google Places identifier of the venue + GooglePlaceType string `json:"google_place_type,omitempty"` // Optional. Google Places a type of the venue. See [supported types](https://developers.google.com/places/web-service/supported_types). +} + +// InputContactMessageContent Represents the content of a contact message to be sent as the result of an inline query. +type InputContactMessageContent struct { + PhoneNumber string `json:"phone_number"` // Contact's phone number + FirstName string `json:"first_name"` // Contact's first name + LastName string `json:"last_name,omitempty"` // Optional. Contact's last name + VCard string `json:"vcard,omitempty"` // Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes +} + +// InputInvoiceMessageContent Represents the content of an invoice message to be sent as the result of an inline query. +type InputInvoiceMessageContent struct { + Title string `json:"title"` // Product name, 1-32 characters + Description string `json:"description"` // Product description, 1-255 characters + Payload string `json:"payload"` // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use it for your internal processes. + ProviderToken string `json:"provider_token,omitempty"` // Payment provider token, obtained via @BotFather + Currency string `json:"currency"` // Three-letter ISO 4217 currency code + Prices []LabeledPrice `json:"prices"` // Price breakdown, a JSON-serialized list of components (e.g., product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + MaxTipAmount int `json:"max_tip_amount,omitempty"` // Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Default to 0 + SuggestedTipAmounts []int `json:"suggested_tip_amounts,omitempty"` // Optional. A JSON-serialized array of suggested amounts of tip in the smallest units of the currency (integer, not float/double). At most four suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. + ProviderData string `json:"provider_data,omitempty"` // Optional. A JSON-serialized object for data about the invoice, which will be shared with the payment provider. The payment provider should provide a detailed description of the required fields. + PhotoURL string `json:"photo_url,omitempty"` // Optional. URL of the product photo for the invoice. It Can be a photo of the goods or a marketing image for a service. + PhotoSize int `json:"photo_size,omitempty"` // Optional. Photo size in bytes + PhotoWidth int `json:"photo_width,omitempty"` // Optional. Photo width + PhotoHeight int `json:"photo_height,omitempty"` // Optional. Photo height + NeedName bool `json:"need_name,omitempty"` // Optional. Pass True, if you require the user's full name to complete the order + NeedPhoneNumber bool `json:"need_phone_number,omitempty"` // Optional. Pass True, if you require the user's phone number to complete the order + NeedEmail bool `json:"need_email,omitempty"` // Optional. Pass True, if you require the user's email address to complete the order + NeedShippingAddress bool `json:"need_shipping_address,omitempty"` // Optional. Pass True, if you require the user's shipping address to complete the order + SendPhoneNumberToProvider bool `json:"send_phone_number_to_provider,omitempty"` // Optional. Pass True, if the user's phone number should be sent to the provider + SendEmailToProvider bool `json:"send_email_to_provider,omitempty"` // Optional. Pass True, if the user's email address should be sent to the provider + IsFlexible bool `json:"is_flexible,omitempty"` // Optional. Pass True, if the final price depends on the shipping method +} + +// ChosenInlineResult Represents a result of an inline query that was chosen by the user and sent to their chat partner. +// Note: It is necessary to enable inline feedback via @BotFather in order to receive these objects in updates. +type ChosenInlineResult struct { + ResultID string `json:"result_id"` // The unique identifier for the result that was chosen + From User `json:"from"` // The user that chose the result + Location *Location `json:"location,omitempty"` // Optional. Sender location, only for bots that require user location + InlineMessageID string `json:"inline_message_id,omitempty"` // Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. It Will be also received in callback queries and can be used to edit the message. + Query string `json:"query"` // The query that was used to obtain the result +} + +// SentWebAppMessage Describes an inline message sent by a Web App on behalf of a user. +type SentWebAppMessage struct { + InlineMessageID string `json:"inline_message_id"` // Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. +} + +// LabeledPrice Represents a portion of the price for goods or services. +type LabeledPrice struct { + Label string `json:"label"` // Portion label + Amount int `json:"amount"` // Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). +} + +// Invoice Contains basic information about an invoice +type Invoice struct { + Title string `json:"title"` // Product name + Description string `json:"description"` // Product description + StartParameter string `json:"start_parameter"` // Unique bot deep-linking parameter that can be used to generate this invoice + Currency string `json:"currency"` // Three-letter ISO 4217 [currency](https://core.telegram.org/bots/payments#supported-currencies) code + TotalAmount int `json:"total_amount"` // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in [currencies.json](https://core.telegram.org/bots/payments/currencies.json), it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). +} + +// ShippingAddress Represents a shipping address. +type ShippingAddress struct { + CountryCode string `json:"country_code"` // Two-letter ISO 3166-1 alpha-2 country code + State string `json:"state"` // State, if applicable + City string `json:"city"` // City + StreetLine1 string `json:"street_line1"` // First line for the address + StreetLine2 string `json:"street_line2"` // Second line for the address + PostCode string `json:"post_code"` // Address post code +} + +// OrderInfo Represents information about an order. +type OrderInfo struct { + Name string `json:"name,omitempty"` // Optional. Username + PhoneNumber string `json:"phone_number,omitempty"` // Optional. User's phone number + Email string `json:"email,omitempty"` // Optional. User email + ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` // Optional. User shipping address +} + +// ShippingOption Represents one shipping option. +type ShippingOption struct { + ID string `json:"id"` // Shipping option identifier + Title string `json:"title"` // Option title + Prices []LabeledPrice `json:"prices"` // List of price portions +} + +// SuccessfulPayment Contains basic information about a successful payment. +type SuccessfulPayment struct { + Currency string `json:"currency"` // Three-letter ISO 4217 currency code + TotalAmount int `json:"total_amount"` // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). + InvoicePayload string `json:"invoice_payload"` // Bot specified invoice payload + ShippingOptionID string `json:"shipping_option_id,omitempty"` // Optional. Identifier of the shipping option chosen by the user + OrderInfo *OrderInfo `json:"order_info,omitempty"` // Optional. Order information provided by the user + TelegramPaymentChargeID string `json:"telegram_payment_charge_id"` // Telegram payment identifier + ProviderPaymentChargeID string `json:"provider_payment_charge_id"` // Provider payment identifier +} + +// RefundedPayment Contains basic information about a refunded payment. +type RefundedPayment struct { + Currency string `json:"currency"` // Three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars. Currently, always “XTR” + TotalAmount int `json:"total_amount"` // Total refunded price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45, total_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). + InvoicePayload string `json:"invoice_payload"` // Bot-specified invoice payload + TelegramPaymentChargeId string `json:"telegram_payment_charge_id"` // Telegram payment identifier + ProviderPaymentChargeId string `json:"provider_payment_charge_id"` // Optional. Provider payment identifier +} + +// ShippingQuery Contains information about an incoming shipping query. +type ShippingQuery struct { + ID string `json:"id"` // Unique query identifier + From User `json:"from"` // User who sent the query + InvoicePayload string `json:"invoice_payload"` // Bot specified invoice payload + ShippingAddress ShippingAddress `json:"shipping_address"` // User specified shipping address +} + +// PreCheckoutQuery Contains a list of Telegram Star transactions. +type PreCheckoutQuery struct { + Id string `json:"id"` // Unique query identifier + From User `json:"from"` // User who sent the query + Currency string `json:"currency"` // Three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars + TotalAmount int `json:"total_amount"` // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). + InvoicePayload string `json:"invoice_payload"` // Bot specified invoice payload + ShippingOptionId string `json:"shipping_option_id,omitempty"` // Optional. Identifier of the shipping option chosen by the user + OrderInfo *OrderInfo `json:"order_info,omitempty"` // Optional. Order information provided by the user +} + +// RevenueWithdrawalState Describes the state of a revenue withdrawal operation. Currently, it can be one of +type RevenueWithdrawalState struct { + RevenueWithdrawalStatePending + RevenueWithdrawalStateSucceeded + RevenueWithdrawalStateFailed +} + +// RevenueWithdrawalStatePending The withdrawal is in progress. +type RevenueWithdrawalStatePending struct { + Type string `json:"type"` // Type of the state, always “pending” +} + +// RevenueWithdrawalStateSucceeded The withdrawal succeeded. +type RevenueWithdrawalStateSucceeded struct { + Type string `json:"type"` // Type of the state, always “succeeded” + Date int64 `json:"date"` // Date the withdrawal was completed in Unix time + Url string `json:"url"` // An HTTPS URL that can be used to see transaction details +} + +// RevenueWithdrawalStateFailed The withdrawal failed and the transaction was refunded. +type RevenueWithdrawalStateFailed struct { + Type string `json:"type"` // Type of the state, always “failed” +} + +// TransactionPartner Describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of. +type TransactionPartner struct { + TransactionPartnerUser + TransactionPartnerFragment + TransactionPartnerTelegramAds + TransactionPartnerOther +} + +// TransactionPartnerUser Describes a transaction with a user. +type TransactionPartnerUser struct { + Type string `json:"type"` // Type of the transaction partner, always “user” + User User `json:"user"` // Information about the user + InvoicePayload string `json:"invoice_payload"` // Optional. Bot-specified invoice payload +} + +// TransactionPartnerFragment Describes a withdrawal transaction with Fragment. +type TransactionPartnerFragment struct { + Type string `json:"type"` // Type of the transaction partner, always “fragment” + WithdrawalState *RevenueWithdrawalState `json:"withdrawal_state,omitempty"` // Optional. State of the transaction if the transaction is outgoing +} + +// TransactionPartnerTelegramAds Describes a withdrawal transaction to the Telegram Ads platform. +type TransactionPartnerTelegramAds struct { + Type string `json:"type"` // Type of the transaction partner, always “telegram_ads” +} + +// TransactionPartnerOther Describes a transaction with an unknown source or recipient. +type TransactionPartnerOther struct { + Type string `json:"type"` // Type of the transaction partner, always “other” +} + +// StarTransaction Describes a Telegram Star transaction. +type StarTransaction struct { + ID string `json:"id"` // Unique identifier of the transaction. Coincides with the identifer of the original transaction for refund transactions. Coincides with SuccessfulPayment.telegram_payment_charge_id for successful incoming payments from users. + Amount int `json:"amount"` // Number of Telegram Stars transferred by the transaction + Date int `json:"date"` // Date the transaction was created in Unix time + Source *TransactionPartner `json:"source"` // Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal). Only for incoming transactions + Receiver *TransactionPartner `json:"receiver"` // Optional. Receiver of an outgoing transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for outgoing transactions +} + +// StarTransactions Describes Telegram Passport data shared with the bot by the user. +type StarTransactions struct { + Transactions []StarTransaction `json:"transactions"` // The list of transactions +} + +// PassportData Describes Telegram Passport data shared with the bot by the user. +type PassportData struct { + Data []EncryptedPassportElement `json:"data"` // Array with information about documents and other Telegram Passport elements that was shared with the bot + Credentials EncryptedCredentials `json:"credentials"` // Encrypted credentials required to decrypt the data +} + +// PassportFile Represents a file uploaded to Telegram Passport. +// Currently, all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB. +type PassportFile struct { + FileID string `json:"file_id"` // Identifier for this file, which can be used to download or reuse the file + FileUniqueID string `json:"file_unique_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. + FileSize int `json:"file_size"` // File size in bytes + FileDate int64 `json:"file_date"` // Unix time when the file was uploaded +} + +// EncryptedPassportElement Describes documents or other Telegram Passport elements shared with the bot by the user. +type EncryptedPassportElement struct { + Type string `json:"type"` // Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”. + Data string `json:"data,omitempty"` // Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for “personal_details,” “passport,” “driver_license,” “identity_card,” “internal_passport” and “address” types. Can be decrypted and verified using the accompanying [EncryptedCredentials](https://core.telegram.org/bots/api#encryptedcredentials). + PhoneNumber string `json:"phone_number,omitempty"` // Optional. User's verified phone number, available only for “phone_number” type + Email string `json:"email,omitempty"` // Optional. User's verified email address, available only for “email” type + Files []*PassportFile `json:"files,omitempty"` // Optional. Array of encrypted files with documents provided by the user, available for “utility_bill,” “bank_statement,” “rental_agreement,” “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying [EncryptedCredentials](https://core.telegram.org/bots/api#encryptedcredentials). + FrontSide *PassportFile `json:"front_side,omitempty"` // Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport,” “driver_license,” “identity_card” and “internal_passport.” The file can be decrypted and verified using the accompanying [EncryptedCredentials](https://core.telegram.org/bots/api#encryptedcredentials). + ReverseSide *PassportFile `json:"reverse_side,omitempty"` // Optional. Encrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card.” The file can be decrypted and verified using the accompanying [EncryptedCredentials](https://core.telegram.org/bots/api#encryptedcredentials). + Selfie *PassportFile `json:"selfie,omitempty"` // Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for “passport,” “driver_license,” “identity_card” and “internal_passport.” The file can be decrypted and verified using the accompanying [EncryptedCredentials](https://core.telegram.org/bots/api#encryptedcredentials). + Translation []*PassportFile `json:"translation,omitempty"` // Optional. Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport,” “driver_license,” “identity_card,” “internal_passport,” “utility_bill,” “bank_statement,” “rental_agreement,” “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying [EncryptedCredentials](https://core.telegram.org/bots/api#encryptedcredentials). + Hash string `json:"hash"` // Base64-encoded element hash for using in [PassportElementErrorUnspecified](https://core.telegram.org/bots/api#passportelementerrorunspecified) +} + +// EncryptedCredentials Describes data required for decrypting and authenticating EncryptedPassportElement. +// See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes. +type EncryptedCredentials struct { + Data string `json:"data"` // Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for [EncryptedPassportElement](https://core.telegram.org/bots/api#encryptedpassportelement) decryption and authentication + Hash string `json:"hash"` // Base64-encoded data hash for data authentication + Secret string `json:"secret"` // Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption +} + +// PassportElementError Represents an error in the Telegram Passport element which was submitted that should be resolved by the user. +// It should be one of: +type PassportElementError struct { + PassportElementErrorDataField PassportElementErrorDataField + PassportElementErrorFrontSide PassportElementErrorFrontSide + PassportElementErrorReverseSide PassportElementErrorReverseSide + PassportElementErrorSelfie PassportElementErrorSelfie + PassportElementErrorFile PassportElementErrorFile + PassportElementErrorFiles PassportElementErrorFiles + PassportElementErrorTranslationFile PassportElementErrorTranslationFile + PassportElementErrorTranslationFiles PassportElementErrorTranslationFiles + PassportElementErrorUnspecified PassportElementErrorUnspecified +} + +// PassportElementErrorDataField Represents an issue in one of the data fields that was provided by the user. +// The error is considered resolved when the field's value changes. +type PassportElementErrorDataField struct { + Source string `json:"source"` // Error source, must be data + Type string `json:"type"` // The section of the user's Telegram Passport, which has the error, one of “personal_details,” “passport,” “driver_license,” “identity_card,” “internal_passport,” “address” + FieldName string `json:"field_name"` // Name of the data field which has the error + DataHash string `json:"data_hash"` // Base64-encoded data hash + Message string `json:"message"` // Error message +} + +// PassportElementErrorFrontSide Represents an issue with the front side of a document. +// The error is considered resolved when the file with the front side of the document changes. +type PassportElementErrorFrontSide struct { + Source string `json:"source"` // Error source must be front_side + Type string `json:"type"` // The section of the user's Telegram Passport which has the issue, one of “passports,” “driver_license,” “identity_card,” “internal_passport” + FileHash string `json:"file_hash"` // Base64-encoded hash of the file with the front side of the document + Message string `json:"message"` // Error message +} + +// PassportElementErrorReverseSide Represents an issue with the reverse side of a document. +// The error is considered resolved when the file with the reverse side of the document changes. +type PassportElementErrorReverseSide struct { + Source string `json:"source"` // Error source, must be reverse_side + Type string `json:"type"` // The section of the user's Telegram Passport which has the issue, one of “driver_license,” “identity_card” + FileHash string `json:"file_hash"` // Base64-encoded hash of the file with the reverse side of the document + Message string `json:"message"` // Error message +} + +// PassportElementErrorSelfie Represents an issue with the selfie with a document. +// The error is considered resolved when the file with the selfie changes. +type PassportElementErrorSelfie struct { + Source string `json:"source"` // Error source, must be selfie + Type string `json:"type"` // The section of the user's Telegram Passport which has the issue, one of “passports,” “driver_license,” “identity_card,” “internal_passport” + FileHash string `json:"file_hash"` // Base64-encoded hash of the file with the selfie + Message string `json:"message"` // Error message +} + +// PassportElementErrorFile Represents an issue with a document scan. +// The error is considered resolved when the file with the document scan changes. +type PassportElementErrorFile struct { + Source string `json:"source"` // Error source must be filed + Type string `json:"type"` // The section of the user's Telegram Passport which has the issue, one of “utility_bill,” “bank_statement,” “rental_agreement,” “passport_registration,” “temporary_registration” + FileHash string `json:"file_hash"` // Base64-encoded file hash + Message string `json:"message"` // Error message +} + +// PassportElementErrorFiles Represents an issue with a list of scans. +// The error is considered resolved when the list of files containing the scan changes. +type PassportElementErrorFiles struct { + Source string `json:"source"` // Error source, must be files + Type string `json:"type"` // The section of the user's Telegram Passport which has the issue, one of “utility_bill,” “bank_statement,” “rental_agreement,” “passport_registration,” “temporary_registration” + FileHashes []string `json:"file_hashes"` // List of base64-encoded file hashes + Message string `json:"message"` // Error message +} + +// PassportElementErrorTranslationFile Represents an issue with one of the files +// that constitute the translation of a document. +// The error is considered resolved when the file changes. +type PassportElementErrorTranslationFile struct { + Source string `json:"source"` // Error source, must be translation_file + Type string `json:"type"` // Type of element of the user's Telegram Passport which has the issue, one of “passports,” “driver_license,” “identity_card,” “internal_passport,” “utility_bill,” “bank_statement,” “rental_agreement,” “passport_registration,” “temporary_registration” + FileHash []string `json:"file_hash"` // Base64-encoded file hash + Message string `json:"message"` // Error message +} + +// PassportElementErrorTranslationFiles Represents an issue with the translated version of a document. +// The error is considered resolved when a file with the document translation changes. +type PassportElementErrorTranslationFiles struct { + Source string `json:"source"` // Error source, must be translation_files + Type string `json:"type"` // Type of element of the user's Telegram Passport which has the issue, one of “passports,” “driver_license,” “identity_card,” “internal_passport,” “utility_bill,” “bank_statement,” “rental_agreement,” “passport_registration,” “temporary_registration” + FileHashes []string `json:"file_hashes"` // List of base64-encoded file hashes + Message string `json:"message"` // Error message +} + +// PassportElementErrorUnspecified Represents an issue in an unspecified place. +// The error is considered resolved when new data is added. +type PassportElementErrorUnspecified struct { + Source string `json:"source"` // Error source must be unspecified + Type string `json:"type"` // Type of element of the user's Telegram Passport which has the issue + FileHash string `json:"file_hash"` // Base64-encoded element hash + Message string `json:"message"` // Error message +} + +// Game Represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers. +type Game struct { + Title string `json:"title"` // Title of the game + Description string `json:"description"` // Description of the game + Photo []PhotoSize `json:"photo"` // Photo that will be displayed in the game message in chats. + Text string `json:"text,omitempty"` // Optional. Brief description of the game or high scores included in the game message. It Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. + TextEntities []*MessageEntity `json:"text_entities,omitempty"` // Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + Animation *Animation `json:"animation,omitempty"` // Optional. Animation that will be displayed in the game message in chats. Upload via BotFather +} + +// CallbackGame A placeholder currently holds no information. Use BotFather to set up your game. +type CallbackGame struct{} + +// GameHighScore Represents one row of the high scores table for a game +type GameHighScore struct { + Position int `json:"position"` // Position in high-score table for the game + User User `json:"user"` // User + Score int `json:"score"` // Score +} diff --git a/types/utils.go b/types/utils.go new file mode 100644 index 0000000..036f466 --- /dev/null +++ b/types/utils.go @@ -0,0 +1,74 @@ +package types + +import ( + "io" +) + +// Error is an error containing extra information returned by the Telegram API. +type Error struct { + Code int + Message string + ResponseParameters +} + +// Chattable is any config type that can be sent. +type Chattable interface { + Params() (Params, error) + EndPoint() string +} + +// Fileable is any config type that can be sent that includes a file. +type Fileable interface { + Chattable + Files() []RequestFile +} + +// RequestFile represents a file associated with a field name. +type RequestFile struct { + // The file field name. + Name string + // The file name. + FileName string + // The file data to include. + Data RequestFileData +} + +// RequestFileData represents the data to be used for a file. +type RequestFileData interface { + // NeedsUpload shows if the file needs to be uploaded. + NeedsUpload() bool + + // UploadData gets the file name and an `io.Reader` for the file to be uploaded. This + // must only be called when the file needs to be uploaded. + UploadData() (string, io.Reader, error) + // SendData gets the file data to send when a file does not need to be uploaded. This + // must only be called when the file does not need to be uploaded. + SendData() string +} + +// FileBytes contains information about a set of bytes to upload as a File. +type FileBytes struct { + Name string + Bytes []byte +} + +// FileReader contains information about a reader to upload as a File. +type FileReader struct { + Name string + Reader io.Reader +} + +// FilePath is a path to a local file. +type FilePath string + +// FileURL is a URL to use as a file for a request. +type FileURL string + +// FileID is an ID of a file already uploaded to Telegram. +type FileID string + +// FileAttach is an internal file type used for processed media groups. +type FileAttach string + +// Params represents a set of parameters that gets passed to a request. +type Params map[string]string