├── go.sum ├── .gitignore ├── go.mod ├── .travis.yml ├── LICENSE ├── README.md ├── games.go ├── available-methods_test.go ├── making-requests.go ├── updating-messages.go ├── getting-updates.go ├── getting-updates_test.go ├── payments.go ├── telegram-passport.go ├── supported-currencies.go ├── stickers.go ├── telegram.go ├── inline-mode.go ├── parameters.go ├── available-methods.go └── available-types.go /go.sum: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | coverage.txt 2 | .idea/ 3 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/nasermirzaei89/telegram 2 | 3 | go 1.13 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.13.15 5 | - 1.14.15 6 | - 1.15.8 7 | - tip 8 | 9 | script: 10 | - go build 11 | - go test -race -coverprofile=coverage.txt -covermode=atomic 12 | 13 | after_success: 14 | - bash <(curl -s https://codecov.io/bash) 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Naser Mirzaei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Telegram Bot API 2 | 3 | [Telegram Bot API](https://core.telegram.org/bots/api) [Golang](https://golang.org) implementation 4 | 5 | [![Build Status](https://travis-ci.org/nasermirzaei89/telegram.svg?branch=master)](https://travis-ci.org/nasermirzaei89/telegram) 6 | [![Go Report Card](https://goreportcard.com/badge/github.com/nasermirzaei89/telegram)](https://goreportcard.com/report/github.com/nasermirzaei89/telegram) 7 | [![GolangCI](https://golangci.com/badges/github.com/nasermirzaei89/telegram.svg)](https://golangci.com/r/github.com/nasermirzaei89/telegram) 8 | [![Codecov](https://codecov.io/gh/nasermirzaei89/telegram/branch/master/graph/badge.svg)](https://codecov.io/gh/nasermirzaei89/telegram) 9 | [![GoDoc](https://godoc.org/github.com/nasermirzaei89/telegram?status.svg)](https://godoc.org/github.com/nasermirzaei89/telegram) 10 | [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://raw.githubusercontent.com/nasermirzaei89/telegram/master/LICENSE) 11 | 12 | ## Status 13 | 14 | Bot API 6.0 (https://core.telegram.org/bots/api-changelog#april-16-2022) 15 | 16 | ## Install 17 | 18 | ```sh 19 | go get github.com/nasermirzaei89/telegram 20 | ``` 21 | 22 | ## Example 23 | 24 | ```go 25 | package main 26 | 27 | import ( 28 | "context" 29 | "github.com/nasermirzaei89/telegram" 30 | "log" 31 | "os" 32 | ) 33 | 34 | func main() { 35 | bot := telegram.New(os.Getenv("TOKEN")) 36 | 37 | res, err := bot.GetUpdates(context.Background()) 38 | if err != nil { 39 | log.Fatalln(err) 40 | } 41 | 42 | if res.IsOK() { 43 | log.Printf("%+v", res.GetUpdates()) 44 | } else { 45 | log.Printf("%d: %s", res.GetErrorCode(), res.GetDescription()) 46 | } 47 | } 48 | ``` 49 | 50 | ## License 51 | 52 | MIT License 53 | 54 | ## Contributing 55 | 56 | You can submit a [new issue](https://github.com/nasermirzaei89/telegram/issues/new) in GitHub [issues](https://github.com/nasermirzaei89/telegram/issues). 57 | Or you can [create a fork](https://help.github.com/articles/fork-a-repo), hack on your fork and when you're done create a [pull request](https://help.github.com/articles/fork-a-repo#pull-requests), so that the code contribution can get merged into the main package. 58 | -------------------------------------------------------------------------------- /games.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // SendGameResponse interface 6 | type SendGameResponse interface { 7 | Response 8 | GetMessage() *Message 9 | } 10 | 11 | type sendGameResponse struct { 12 | response 13 | Result *Message `json:"result,omitempty"` 14 | } 15 | 16 | func (r *sendGameResponse) GetMessage() *Message { 17 | return r.Result 18 | } 19 | 20 | func (b *bot) SendGame(ctx context.Context, options ...MethodOption) (SendGameResponse, error) { 21 | var res sendGameResponse 22 | 23 | err := b.doRequest(ctx, "sendGame", &res, options...) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return &res, nil 29 | } 30 | 31 | // Game struct 32 | type Game struct { 33 | Title string `json:"title"` 34 | Description string `json:"description"` 35 | Photo []PhotoSize `json:"photo"` 36 | Text *string `json:"text,omitempty"` 37 | TextEntities []MessageEntity `json:"text_entities,omitempty"` 38 | Animation *Animation `json:"animation,omitempty"` 39 | } 40 | 41 | // CallbackGame interface 42 | type CallbackGame interface{} 43 | 44 | // SetGameScoreResponse interface 45 | type SetGameScoreResponse interface { 46 | Response 47 | GetEditedMessage() *Message 48 | } 49 | 50 | type setGameScoreResponse struct { 51 | response 52 | Result *Message `json:"result,omitempty"` 53 | } 54 | 55 | func (r *setGameScoreResponse) GetEditedMessage() *Message { 56 | return r.Result 57 | } 58 | 59 | func (b *bot) SetGameScore(ctx context.Context, options ...MethodOption) (SetGameScoreResponse, error) { 60 | var res setGameScoreResponse 61 | 62 | err := b.doRequest(ctx, "setGameScore", &res, options...) 63 | if err != nil { 64 | return nil, err 65 | } 66 | 67 | return &res, nil 68 | } 69 | 70 | // GetGameHighScoresResponse interface 71 | type GetGameHighScoresResponse interface { 72 | Response 73 | GetGameHighScores() []GameHighScore 74 | } 75 | 76 | type getGameHighScoresResponse struct { 77 | response 78 | Result []GameHighScore `json:"result,omitempty"` 79 | } 80 | 81 | func (r *getGameHighScoresResponse) GetGameHighScores() []GameHighScore { 82 | return r.Result 83 | } 84 | 85 | func (b *bot) GetGameHighScores(ctx context.Context, options ...MethodOption) (GetGameHighScoresResponse, error) { 86 | var res getGameHighScoresResponse 87 | 88 | err := b.doRequest(ctx, "getGameHighScores", &res, options...) 89 | if err != nil { 90 | return nil, err 91 | } 92 | 93 | return &res, nil 94 | } 95 | 96 | // GameHighScore struct 97 | type GameHighScore struct { 98 | Position int `json:"position"` 99 | User User `json:"user"` 100 | Score int `json:"score"` 101 | } 102 | -------------------------------------------------------------------------------- /available-methods_test.go: -------------------------------------------------------------------------------- 1 | package telegram_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | "net/http/httptest" 8 | "testing" 9 | 10 | "github.com/nasermirzaei89/telegram" 11 | ) 12 | 13 | const ( 14 | testToken = "someToken" 15 | invalidToken = "invalidToken" 16 | ) 17 | 18 | func TestGetMe(t *testing.T) { 19 | ctx := context.Background() 20 | 21 | response := []byte(`{"ok":true,"result":{"id":1,"is_bot":true,"first_name":"Test Bot","username":"TestBot"}}`) 22 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 23 | u := fmt.Sprintf("/bot%s/getMe", testToken) 24 | if r.URL.String() != u { 25 | w.WriteHeader(http.StatusUnauthorized) 26 | _, _ = w.Write([]byte(`{"ok":false,"error_code":401,"description":"Unauthorized"}`)) 27 | 28 | return 29 | } 30 | 31 | w.WriteHeader(http.StatusOK) 32 | _, _ = w.Write(response) 33 | })) 34 | 35 | defer server.Close() 36 | 37 | // success 38 | bot := telegram.New(testToken, telegram.SetBaseURL(server.URL)) 39 | 40 | res, err := bot.GetMe(ctx) 41 | if err != nil { 42 | t.Errorf("error on get me: %s", err.Error()) 43 | 44 | return 45 | } 46 | 47 | if !res.IsOK() { 48 | t.Error("result should be ok but is not") 49 | 50 | return 51 | } 52 | 53 | if res.GetErrorCode() != 0 { 54 | t.Errorf("result error code should be zero but is %d", res.GetErrorCode()) 55 | 56 | return 57 | } 58 | 59 | usr := res.GetUser() 60 | 61 | if usr == nil { 62 | t.Error("result user should not be nil but is") 63 | 64 | return 65 | } 66 | 67 | if usr.ID != 1 { 68 | t.Errorf("result user id should be 1 but is %d", usr.ID) 69 | } 70 | 71 | if !usr.IsBot { 72 | t.Errorf("result user should be bot but is not") 73 | } 74 | 75 | expectedFirstName := "Test Bot" 76 | if usr.FirstName != expectedFirstName { 77 | t.Errorf("result user first name should be '%s' but is '%s'", expectedFirstName, usr.FirstName) 78 | } 79 | 80 | if usr.LastName != nil { 81 | t.Errorf("result user should not have last name but has") 82 | } 83 | 84 | if usr.Username == nil { 85 | t.Errorf("result user username should not be nil but is") 86 | 87 | return 88 | } 89 | 90 | if expectedUsername := "TestBot"; *usr.Username != expectedUsername { 91 | t.Errorf("result user username should be '%s' but is '%s'", expectedUsername, *usr.Username) 92 | } 93 | 94 | // fail 95 | bot = telegram.New(invalidToken, telegram.SetBaseURL(server.URL)) 96 | 97 | res, err = bot.GetMe(ctx) 98 | if err != nil { 99 | t.Errorf("error on get me: %s", err.Error()) 100 | 101 | return 102 | } 103 | 104 | if res.IsOK() { 105 | t.Error("result should not be ok but is") 106 | 107 | return 108 | } 109 | 110 | if res.GetUser() != nil { 111 | t.Error("result user should be nil but is not") 112 | } 113 | 114 | if res.GetErrorCode() != http.StatusUnauthorized { 115 | t.Errorf("result error code should be %d but is %d", http.StatusUnauthorized, res.GetErrorCode()) 116 | 117 | return 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /making-requests.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "io/ioutil" 10 | "mime/multipart" 11 | "net/http" 12 | ) 13 | 14 | // Response general interface 15 | type Response interface { 16 | IsOK() bool 17 | GetErrorCode() int 18 | GetDescription() string 19 | GetParameters() *ResponseParameters 20 | } 21 | 22 | type response struct { 23 | OK bool `json:"ok"` 24 | Description *string `json:"description,omitempty"` 25 | ErrorCode *int `json:"error_code,omitempty"` 26 | Parameters *ResponseParameters `json:"parameters,omitempty"` 27 | } 28 | 29 | func (r *response) IsOK() bool { 30 | return r.OK 31 | } 32 | 33 | func (r *response) GetErrorCode() int { 34 | if r.ErrorCode != nil { 35 | return *r.ErrorCode 36 | } 37 | 38 | return 0 39 | } 40 | 41 | func (r *response) GetDescription() string { 42 | if r.Description != nil { 43 | return *r.Description 44 | } 45 | 46 | return "" 47 | } 48 | 49 | func (r *response) GetParameters() *ResponseParameters { 50 | return r.Parameters 51 | } 52 | 53 | type request struct { 54 | params map[string]interface{} 55 | } 56 | 57 | func (b *bot) doRequest(ctx context.Context, methodName string, res interface{}, options ...MethodOption) error { 58 | r := request{ 59 | params: map[string]interface{}{}, 60 | } 61 | 62 | for i := range options { 63 | options[i](&r) 64 | } 65 | 66 | body := &bytes.Buffer{} 67 | writer := multipart.NewWriter(body) 68 | 69 | for k, v := range r.params { 70 | switch t := v.(type) { 71 | case io.Reader: 72 | w, err := writer.CreateFormFile(k, k) 73 | if err != nil { 74 | return fmt.Errorf("error on create field from file: %w", err) 75 | } 76 | 77 | b, err := ioutil.ReadAll(t) 78 | if err != nil { 79 | return fmt.Errorf("error on read: %w", err) 80 | } 81 | 82 | _, err = w.Write(b) 83 | if err != nil { 84 | return fmt.Errorf("error on write data: %w", err) 85 | } 86 | case string: 87 | err := writer.WriteField(k, t) 88 | if err != nil { 89 | return fmt.Errorf("error on write field: %w", err) 90 | } 91 | default: 92 | b, err := json.Marshal(v) 93 | if err != nil { 94 | return fmt.Errorf("error on marshal json: %w", err) 95 | } 96 | 97 | err = writer.WriteField(k, string(b)) 98 | if err != nil { 99 | return fmt.Errorf("error on write field: %w", err) 100 | } 101 | } 102 | } 103 | 104 | err := writer.Close() 105 | if err != nil { 106 | return fmt.Errorf("error on close writer: %w", err) 107 | } 108 | 109 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, fmt.Sprintf("%s/bot%s/%s", b.baseURL, b.token, methodName), body) 110 | if err != nil { 111 | return fmt.Errorf("error on new http request: %w", err) 112 | } 113 | 114 | // don't send content type on empty body 115 | if len(r.params) > 0 { 116 | req.Header.Set("Content-Type", writer.FormDataContentType()) 117 | } 118 | 119 | client := new(http.Client) 120 | 121 | resp, err := client.Do(req) 122 | if err != nil { 123 | return fmt.Errorf("error on do http request: %w", err) 124 | } 125 | 126 | defer func() { _ = resp.Body.Close() }() 127 | 128 | err = json.NewDecoder(resp.Body).Decode(res) 129 | if err != nil { 130 | return fmt.Errorf("error decode json response: %w", err) 131 | } 132 | 133 | return nil 134 | } 135 | -------------------------------------------------------------------------------- /updating-messages.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // EditMessageTextResponse interface 6 | type EditMessageTextResponse interface { 7 | Response 8 | GetEditedMessage() *Message 9 | } 10 | 11 | type editMessageTextResponse struct { 12 | response 13 | Result *Message `json:"result,omitempty"` 14 | } 15 | 16 | func (r *editMessageTextResponse) GetEditedMessage() *Message { 17 | return r.Result 18 | } 19 | 20 | func (b *bot) EditMessageText(ctx context.Context, options ...MethodOption) (EditMessageTextResponse, error) { 21 | var res editMessageTextResponse 22 | 23 | err := b.doRequest(ctx, "editMessageText", &res, options...) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return &res, nil 29 | } 30 | 31 | // EditMessageCaptionResponse interface 32 | type EditMessageCaptionResponse interface { 33 | Response 34 | GetEditedMessage() *Message 35 | } 36 | 37 | type editMessageCaptionResponse struct { 38 | response 39 | Result *Message `json:"result,omitempty"` 40 | } 41 | 42 | func (r *editMessageCaptionResponse) GetEditedMessage() *Message { 43 | return r.Result 44 | } 45 | 46 | func (b *bot) EditMessageCaption(ctx context.Context, options ...MethodOption) (EditMessageCaptionResponse, error) { 47 | var res editMessageCaptionResponse 48 | 49 | err := b.doRequest(ctx, "editMessageCaption", &res, options...) 50 | if err != nil { 51 | return nil, err 52 | } 53 | 54 | return &res, nil 55 | } 56 | 57 | // EditMessageMediaResponse interface 58 | type EditMessageMediaResponse interface { 59 | Response 60 | GetEditedMessage() *Message 61 | } 62 | 63 | type editMessageMediaResponse struct { 64 | response 65 | Result *Message `json:"result,omitempty"` 66 | } 67 | 68 | func (r *editMessageMediaResponse) GetEditedMessage() *Message { 69 | return r.Result 70 | } 71 | 72 | func (b *bot) EditMessageMedia(ctx context.Context, options ...MethodOption) (EditMessageMediaResponse, error) { 73 | var res editMessageMediaResponse 74 | 75 | err := b.doRequest(ctx, "editMessageMedia", &res, options...) 76 | if err != nil { 77 | return nil, err 78 | } 79 | 80 | return &res, nil 81 | } 82 | 83 | // EditMessageReplyMarkupResponse interface 84 | type EditMessageReplyMarkupResponse interface { 85 | Response 86 | GetEditedMessage() *Message 87 | } 88 | 89 | type editMessageReplyMarkupResponse struct { 90 | response 91 | Result *Message `json:"result,omitempty"` 92 | } 93 | 94 | func (r *editMessageReplyMarkupResponse) GetEditedMessage() *Message { 95 | return r.Result 96 | } 97 | 98 | func (b *bot) EditMessageReplyMarkup(ctx context.Context, options ...MethodOption) (EditMessageReplyMarkupResponse, error) { 99 | var res editMessageReplyMarkupResponse 100 | 101 | err := b.doRequest(ctx, "editMessageReplyMarkup", &res, options...) 102 | if err != nil { 103 | return nil, err 104 | } 105 | 106 | return &res, nil 107 | } 108 | 109 | // StopPollResponse interface 110 | type StopPollResponse interface { 111 | Response 112 | GetStoppedPoll() *Poll 113 | } 114 | 115 | type stopPollResponse struct { 116 | response 117 | Result *Poll `json:"result,omitempty"` 118 | } 119 | 120 | func (r *stopPollResponse) GetStoppedPoll() *Poll { 121 | return r.Result 122 | } 123 | 124 | func (b *bot) StopPoll(ctx context.Context, options ...MethodOption) (StopPollResponse, error) { 125 | var res stopPollResponse 126 | 127 | err := b.doRequest(ctx, "stopPoll", &res, options...) 128 | if err != nil { 129 | return nil, err 130 | } 131 | 132 | return &res, nil 133 | } 134 | 135 | // DeleteMessageResponse interface 136 | type DeleteMessageResponse interface { 137 | Response 138 | } 139 | 140 | type deleteMessageResponse struct { 141 | response 142 | } 143 | 144 | func (b *bot) DeleteMessage(ctx context.Context, options ...MethodOption) (DeleteMessageResponse, error) { 145 | var res deleteMessageResponse 146 | 147 | err := b.doRequest(ctx, "deleteMessage", &res, options...) 148 | if err != nil { 149 | return nil, err 150 | } 151 | 152 | return &res, nil 153 | } 154 | -------------------------------------------------------------------------------- /getting-updates.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // Update struct. 6 | type Update struct { 7 | UpdateID int `json:"update_id"` 8 | Message *Message `json:"message,omitempty"` 9 | EditedMessage *Message `json:"edited_message,omitempty"` 10 | ChannelPost *Message `json:"channel_post,omitempty"` 11 | EditedChannelPost *Message `json:"edited_channel_post,omitempty"` 12 | InlineQuery *InlineQuery `json:"inline_query,omitempty"` 13 | ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"` 14 | CallbackQuery *CallbackQuery `json:"callback_query,omitempty"` 15 | ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"` 16 | PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"` 17 | Poll *Poll `json:"poll,omitempty"` 18 | PollAnswer *PollAnswer `json:"poll_answer"` 19 | MyChatMember *ChatMemberUpdated `json:"my_chat_member,omitempty"` 20 | ChatMember *ChatMemberUpdated `json:"chat_member,omitempty"` 21 | ChatJoinRequest *ChatJoinRequest `json:"chat_join_request,omitempty"` 22 | } 23 | 24 | // GetUpdatesResponse interface. 25 | type GetUpdatesResponse interface { 26 | Response 27 | GetUpdates() []Update 28 | } 29 | 30 | type getUpdatesResponse struct { 31 | response 32 | Result []Update `json:"result,omitempty"` 33 | } 34 | 35 | func (r *getUpdatesResponse) GetUpdates() []Update { 36 | return r.Result 37 | } 38 | 39 | func (b *bot) GetUpdates(ctx context.Context, options ...MethodOption) (GetUpdatesResponse, error) { 40 | var res getUpdatesResponse 41 | 42 | err := b.doRequest(ctx, "getUpdates", &res, options...) 43 | if err != nil { 44 | return nil, err 45 | } 46 | 47 | return &res, nil 48 | } 49 | 50 | // SetWebhookResponse interface. 51 | type SetWebhookResponse interface { 52 | Response 53 | } 54 | 55 | type setWebhookResponse struct { 56 | response 57 | } 58 | 59 | func (b *bot) SetWebhook(ctx context.Context, options ...MethodOption) (SetWebhookResponse, error) { 60 | var res setWebhookResponse 61 | 62 | err := b.doRequest(ctx, "setWebhook", &res, options...) 63 | if err != nil { 64 | return nil, err 65 | } 66 | 67 | return &res, nil 68 | } 69 | 70 | // DeleteWebhookResponse interface. 71 | type DeleteWebhookResponse interface { 72 | Response 73 | } 74 | 75 | type deleteWebhookResponse struct { 76 | response 77 | } 78 | 79 | func (b *bot) DeleteWebhook(ctx context.Context) (DeleteWebhookResponse, error) { 80 | var res deleteWebhookResponse 81 | 82 | err := b.doRequest(ctx, "deleteWebhook", &res) 83 | if err != nil { 84 | return nil, err 85 | } 86 | 87 | return &res, nil 88 | } 89 | 90 | // GetWebhookInfoResponse interface. 91 | type GetWebhookInfoResponse interface { 92 | Response 93 | GetWebhookInfo() *WebhookInfo 94 | } 95 | 96 | type getWebhookInfoResponse struct { 97 | response 98 | Result *WebhookInfo `json:"result,omitempty"` 99 | } 100 | 101 | func (r *getWebhookInfoResponse) GetWebhookInfo() *WebhookInfo { 102 | return r.Result 103 | } 104 | 105 | func (b *bot) GetWebhookInfo(ctx context.Context) (GetWebhookInfoResponse, error) { 106 | var res getWebhookInfoResponse 107 | 108 | err := b.doRequest(ctx, "getWebhookInfo", &res) 109 | if err != nil { 110 | return nil, err 111 | } 112 | 113 | return &res, nil 114 | } 115 | 116 | // WebhookInfo struct. 117 | type WebhookInfo struct { 118 | URL string `json:"url"` 119 | HasCustomCertificate bool `json:"has_custom_certificate"` 120 | PendingUpdateCount int `json:"pending_update_count"` 121 | IPAddress *string `json:"ip_address,omitempty"` 122 | LastErrorDate *int `json:"last_error_date,omitempty"` 123 | LastErrorMessage *string `json:"last_error_message,omitempty"` 124 | LastSynchronizationError *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 125 | MaxConnections *int `json:"max_connections,omitempty"` 126 | AllowedUpdates []string `json:"allowed_updates,omitempty"` 127 | } 128 | -------------------------------------------------------------------------------- /getting-updates_test.go: -------------------------------------------------------------------------------- 1 | package telegram_test 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | "net/http/httptest" 8 | "testing" 9 | 10 | "github.com/nasermirzaei89/telegram" 11 | ) 12 | 13 | func TestGetUpdates(t *testing.T) { 14 | ctx := context.Background() 15 | 16 | response := []byte(`{ 17 | "ok": true, 18 | "result": [ 19 | { 20 | "update_id": 109399605, 21 | "message": { 22 | "message_id": 1234, 23 | "from": { 24 | "id": 123456789, 25 | "is_bot": false, 26 | "first_name": "John", 27 | "last_name": "Doe", 28 | "username": "johndoe", 29 | "language_code": "en" 30 | }, 31 | "chat": { 32 | "id": 123456789, 33 | "first_name": "John", 34 | "last_name": "Doe", 35 | "username": "johndoe", 36 | "type": "private" 37 | }, 38 | "date": 1234567890, 39 | "text": "Test" 40 | } 41 | } 42 | ] 43 | }`) 44 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 45 | u := fmt.Sprintf("/bot%s/getUpdates", testToken) 46 | if r.URL.String() != u { 47 | w.WriteHeader(http.StatusUnauthorized) 48 | _, _ = w.Write([]byte(`{"ok":false,"error_code":401,"description":"Unauthorized"}`)) 49 | 50 | return 51 | } 52 | 53 | w.WriteHeader(http.StatusOK) 54 | _, _ = w.Write(response) 55 | })) 56 | 57 | defer server.Close() 58 | 59 | // success 60 | bot := telegram.New(testToken, telegram.SetBaseURL(server.URL)) 61 | 62 | res, err := bot.GetUpdates(ctx) 63 | if err != nil { 64 | t.Errorf("error on get updates: %s", err.Error()) 65 | 66 | return 67 | } 68 | 69 | if !res.IsOK() { 70 | t.Error("result should be ok but is not") 71 | 72 | return 73 | } 74 | 75 | if res.GetErrorCode() != 0 { 76 | t.Errorf("result error code should be zero but is %d", res.GetErrorCode()) 77 | 78 | return 79 | } 80 | 81 | updates := res.GetUpdates() 82 | 83 | if updates == nil { 84 | t.Error("result updates should be array but are nil") 85 | 86 | return 87 | } 88 | 89 | for _, u := range updates { 90 | if u.UpdateID == 0 { 91 | t.Error("update is should not be zero but is") 92 | } 93 | } 94 | 95 | // fail 96 | bot = telegram.New(invalidToken, telegram.SetBaseURL(server.URL)) 97 | 98 | res, err = bot.GetUpdates(ctx) 99 | if err != nil { 100 | t.Errorf("error on get updates: %s", err.Error()) 101 | 102 | return 103 | } 104 | 105 | if res.IsOK() { 106 | t.Error("result should not be ok but is") 107 | 108 | return 109 | } 110 | 111 | if res.GetErrorCode() != http.StatusUnauthorized { 112 | t.Errorf("result error code should be %d but is %d", http.StatusUnauthorized, res.GetErrorCode()) 113 | 114 | return 115 | } 116 | } 117 | 118 | func TestSetWebhook(t *testing.T) { 119 | ctx := context.Background() 120 | 121 | response := []byte(`{"ok":true,"result":true,"description":"Webhook was set"}`) 122 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 123 | u := fmt.Sprintf("/bot%s/setWebhook", testToken) 124 | if r.URL.String() != u { 125 | w.WriteHeader(http.StatusUnauthorized) 126 | _, _ = w.Write([]byte(`{"ok":false,"error_code":401,"description":"Unauthorized"}`)) 127 | 128 | return 129 | } 130 | 131 | w.WriteHeader(http.StatusOK) 132 | _, _ = w.Write(response) 133 | })) 134 | 135 | defer server.Close() 136 | 137 | // success 138 | bot := telegram.New(testToken, telegram.SetBaseURL(server.URL)) 139 | 140 | res, err := bot.SetWebhook( 141 | ctx, 142 | telegram.SetURL("https://example.com/telegram/webhook"), 143 | telegram.SetMaxConnections(40), 144 | telegram.SetAllowedUpdates("message"), 145 | ) 146 | if err != nil { 147 | t.Errorf("error on set web hook: %s", err.Error()) 148 | 149 | return 150 | } 151 | 152 | if !res.IsOK() { 153 | t.Error("result should be ok but is not") 154 | 155 | return 156 | } 157 | 158 | if res.GetErrorCode() != 0 { 159 | t.Errorf("result error code should be zero but is %d", res.GetErrorCode()) 160 | 161 | return 162 | } 163 | 164 | expectedDesc := "Webhook was set" 165 | if desc := res.GetDescription(); desc != expectedDesc { 166 | t.Errorf("result description should be '%s' but is '%s'", expectedDesc, desc) 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /payments.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // SendInvoiceResponse interface 6 | type SendInvoiceResponse interface { 7 | Response 8 | GetMessage() *Message 9 | } 10 | 11 | type sendInvoiceResponse struct { 12 | response 13 | Result *Message `json:"result,omitempty"` 14 | } 15 | 16 | func (r *sendInvoiceResponse) GetMessage() *Message { 17 | return r.Result 18 | } 19 | 20 | func (b *bot) SendInvoice(ctx context.Context, options ...MethodOption) (SendInvoiceResponse, error) { 21 | var res sendInvoiceResponse 22 | 23 | err := b.doRequest(ctx, "sendInvoice", &res, options...) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return &res, nil 29 | } 30 | 31 | // AnswerShippingQueryResponse interface 32 | type AnswerShippingQueryResponse interface { 33 | Response 34 | } 35 | 36 | type answerShippingQueryResponse struct { 37 | response 38 | } 39 | 40 | func (b *bot) AnswerShippingQuery(ctx context.Context, options ...MethodOption) (AnswerShippingQueryResponse, error) { 41 | var res answerShippingQueryResponse 42 | 43 | err := b.doRequest(ctx, "answerShippingQuery", &res, options...) 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | return &res, nil 49 | } 50 | 51 | // AnswerPreCheckoutQueryResponse interface 52 | type AnswerPreCheckoutQueryResponse interface { 53 | Response 54 | } 55 | 56 | type answerPreCheckoutQueryResponse struct { 57 | response 58 | } 59 | 60 | func (b *bot) AnswerPreCheckoutQuery(ctx context.Context, options ...MethodOption) (AnswerPreCheckoutQueryResponse, error) { 61 | var res answerPreCheckoutQueryResponse 62 | 63 | err := b.doRequest(ctx, "answerPreCheckoutQuery", &res, options...) 64 | if err != nil { 65 | return nil, err 66 | } 67 | 68 | return &res, nil 69 | } 70 | 71 | // LabeledPrice struct 72 | type LabeledPrice struct { 73 | Label string `json:"label"` 74 | Amount int `json:"amount"` 75 | } 76 | 77 | // Invoice struct 78 | type Invoice struct { 79 | Title string `json:"title"` 80 | Description string `json:"description"` 81 | StartParameter string `json:"start_parameter"` 82 | Currency string `json:"currency"` 83 | TotalAmount int `json:"total_amount"` 84 | } 85 | 86 | // ShippingAddress struct 87 | type ShippingAddress struct { 88 | CountryCode string `json:"country_code"` 89 | State string `json:"state"` 90 | City string `json:"city"` 91 | StreetLine1 string `json:"street_line_1"` 92 | StreetLine2 string `json:"street_line_2"` 93 | PostCode string `json:"post_code"` 94 | } 95 | 96 | // OrderInfo struct 97 | type OrderInfo struct { 98 | Name string `json:"name"` 99 | PhoneNumber *string `json:"phone_number,omitempty"` 100 | Email *string `json:"email,omitempty"` 101 | ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` 102 | } 103 | 104 | // ShippingOption struct 105 | type ShippingOption struct { 106 | ID string `json:"id"` 107 | Title string `json:"title"` 108 | Prices []LabeledPrice `json:"prices"` 109 | } 110 | 111 | // SuccessfulPayment struct 112 | type SuccessfulPayment struct { 113 | Currency string `json:"currency"` 114 | TotalAmount int `json:"total_amount"` 115 | InvoicePayload string `json:"invoice_payload"` 116 | ShippingOptionID *string `json:"shipping_option_id,omitempty"` 117 | OrderInfo *OrderInfo `json:"order_info,omitempty"` 118 | TelegramPaymentChargeID string `json:"telegram_payment_charge_id"` 119 | ProviderPaymentChargeID string 120 | } 121 | 122 | // ShippingQuery struct 123 | type ShippingQuery struct { 124 | ID string `json:"id"` 125 | From User `json:"from"` 126 | InvoicePayload string `json:"invoice_payload"` 127 | ShippingAddress ShippingAddress `json:"shipping_address"` 128 | } 129 | 130 | // PreCheckoutQuery struct 131 | type PreCheckoutQuery struct { 132 | ID string `json:"id"` 133 | From User `json:"from"` 134 | Currency string `json:"currency"` 135 | TotalAmount int `json:"total_amount"` 136 | InvoicePayload string `json:"invoice_payload"` 137 | ShippingOptionID *string `json:"shipping_option_id"` 138 | OrderInfo *OrderInfo `json:"order_info"` 139 | } 140 | -------------------------------------------------------------------------------- /telegram-passport.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // PassportData struct 6 | type PassportData struct { 7 | Data []EncryptedPassportElement `json:"data"` 8 | Credentials EncryptedCredentials `json:"credentials"` 9 | } 10 | 11 | // PassportFile struct 12 | type PassportFile struct { 13 | FileID string `json:"file_id"` 14 | FileUniqueID string `json:"file_unique_id"` 15 | FileSize int `json:"file_size"` 16 | FileDate int `json:"file_date"` 17 | } 18 | 19 | // EncryptedPassportElement struct 20 | type EncryptedPassportElement struct { 21 | Type string `json:"type"` 22 | Data *string `json:"data,omitempty"` 23 | PhoneNumber *string `json:"phone_number,omitempty"` 24 | Email *string `json:"email,omitempty"` 25 | Files []PassportFile `json:"files,omitempty"` 26 | FrontSide *PassportFile `json:"front_side,omitempty"` 27 | ReverseSide *PassportFile `json:"reverse_side,omitempty"` 28 | Selfie *PassportFile `json:"selfie,omitempty"` 29 | Translation []PassportFile `json:"translation,omitempty"` 30 | Hash string `json:"hash"` 31 | } 32 | 33 | // EncryptedCredentials struct 34 | type EncryptedCredentials struct { 35 | Data string `json:"data"` 36 | Hash string `json:"hash"` 37 | Secret string `json:"secret"` 38 | } 39 | 40 | // SetPassportDataErrorsResponse interface 41 | type SetPassportDataErrorsResponse interface { 42 | Response 43 | } 44 | 45 | type setPassportDataErrorsResponse struct { 46 | response 47 | } 48 | 49 | func (b *bot) SetPassportDataErrors(ctx context.Context, options ...MethodOption) (SetPassportDataErrorsResponse, error) { 50 | var res setPassportDataErrorsResponse 51 | 52 | err := b.doRequest(ctx, "setPassportDataErrors", &res, options...) 53 | if err != nil { 54 | return nil, err 55 | } 56 | 57 | return &res, nil 58 | } 59 | 60 | // PassportElementError interface 61 | type PassportElementError interface{} 62 | 63 | // PassportElementErrorDataField struct 64 | type PassportElementErrorDataField struct { 65 | Source string `json:"source"` 66 | Type string `json:"type"` 67 | FieldName string `json:"field_name"` 68 | DataHash string `json:"data_hash"` 69 | Message string `json:"message"` 70 | } 71 | 72 | // PassportElementErrorFrontSide struct 73 | type PassportElementErrorFrontSide struct { 74 | Source string `json:"source"` 75 | Type string `json:"type"` 76 | FileHash string `json:"file_hash"` 77 | Message string `json:"message"` 78 | } 79 | 80 | // PassportElementErrorReverseSide struct 81 | type PassportElementErrorReverseSide struct { 82 | Source string `json:"source"` 83 | Type string `json:"type"` 84 | FileHash string `json:"file_hash"` 85 | Message string `json:"message"` 86 | } 87 | 88 | // PassportElementErrorSelfie struct 89 | type PassportElementErrorSelfie struct { 90 | Source string `json:"source"` 91 | Type string `json:"type"` 92 | FileHash string `json:"file_hash"` 93 | Message string `json:"message"` 94 | } 95 | 96 | // PassportElementErrorFile struct 97 | type PassportElementErrorFile struct { 98 | Source string `json:"source"` 99 | Type string `json:"type"` 100 | FileHash string `json:"file_hash"` 101 | Message string `json:"message"` 102 | } 103 | 104 | // PassportElementErrorFiles struct 105 | type PassportElementErrorFiles struct { 106 | Source string `json:"source"` 107 | Type string `json:"type"` 108 | FileHashes []string `json:"file_hashes"` 109 | Message string `json:"message"` 110 | } 111 | 112 | // PassportElementErrorTranslationFile struct 113 | type PassportElementErrorTranslationFile struct { 114 | Source string `json:"source"` 115 | Type string `json:"type"` 116 | FileHash string `json:"file_hash"` 117 | Message string `json:"message"` 118 | } 119 | 120 | // PassportElementErrorTranslationFiles struct 121 | type PassportElementErrorTranslationFiles struct { 122 | Source string `json:"source"` 123 | Type string `json:"type"` 124 | FileHashes []string `json:"file_hashes"` 125 | Message string `json:"message"` 126 | } 127 | 128 | // PassportElementErrorUnspecified struct 129 | type PassportElementErrorUnspecified struct { 130 | Source string `json:"source"` 131 | Type string `json:"type"` 132 | ElementHash string `json:"element_hash"` 133 | Message string `json:"message"` 134 | } 135 | -------------------------------------------------------------------------------- /supported-currencies.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | type Currency string 4 | 5 | const ( 6 | UnitedArabEmiratesDirham Currency = "AED" 7 | AfghanAfghani Currency = "AFN" 8 | AlbanianLek Currency = "ALL" 9 | ArmenianDram Currency = "AMD" 10 | ArgentinePeso Currency = "ARS" 11 | AustralianDollar Currency = "AUD" 12 | AzerbaijaniManat Currency = "AZN" 13 | BosniaAndHerzegovinaConvertibleMark Currency = "BAM" 14 | BangladeshiTaka Currency = "BDT" 15 | BulgarianLev Currency = "BGN" 16 | BruneiDollar Currency = "BND" 17 | BolivianBoliviano Currency = "BOB" 18 | BrazilianReal Currency = "BRL" 19 | CanadianDollar Currency = "CAD" 20 | SwissFranc Currency = "CHF" 21 | ChileanPeso Currency = "CLP" 22 | ChineseRenminbiYuan Currency = "CNY" 23 | ColombianPeso Currency = "COP" 24 | CostaRicanColon Currency = "CRC" 25 | CzechKoruna Currency = "CZK" 26 | DanishKrone Currency = "DKK" 27 | DominicanPeso Currency = "DOP" 28 | AlgerianDinar Currency = "DZD" 29 | EgyptianPound Currency = "EGP" 30 | Euro Currency = "EUR" 31 | BritishPound Currency = "GBP" 32 | GeorgianLari Currency = "GEL" 33 | GuatemalanQuetzal Currency = "GTQ" 34 | HongKongDollar Currency = "HKD" 35 | HonduranLempira Currency = "HNL" 36 | CroatianKuna Currency = "HRK" 37 | HungarianForint Currency = "HUF" 38 | IndonesianRupiah Currency = "IDR" 39 | IsraeliNewSheqel Currency = "ILS" 40 | IndianRupee Currency = "INR" 41 | IcelandicKrona Currency = "ISK" 42 | JamaicanDollar Currency = "JMD" 43 | JapaneseYen Currency = "JPY" 44 | KenyanShilling Currency = "KES" 45 | KyrgyzstaniSom Currency = "KGS" 46 | SouthKoreanWon Currency = "KRW" 47 | KazakhstaniTenge Currency = "KZT" 48 | LebanesePound Currency = "LBP" 49 | SriLankanRupee Currency = "LKR" 50 | MoroccanDirham Currency = "MAD" 51 | MoldovanLeu Currency = "MDL" 52 | MongolianTogrog Currency = "MNT" 53 | MauritianRupee Currency = "MUR" 54 | MaldivianRufiyaa Currency = "MVR" 55 | MexicanPeso Currency = "MXN" 56 | MalaysianRinggit Currency = "MYR" 57 | MozambicanMetical Currency = "MZN" 58 | NigerianNaira Currency = "NGN" 59 | NicaraguanCordoba Currency = "NIO" 60 | NorwegianKrone Currency = "NOK" 61 | NepaleseRupee Currency = "NPR" 62 | NewZealandDollar Currency = "NZD" 63 | PanamanianBalboa Currency = "PAB" 64 | PeruvianNuevoSol Currency = "PEN" 65 | PhilippinePeso Currency = "PHP" 66 | PakistaniRupee Currency = "PKR" 67 | PolishZloty Currency = "PLN" 68 | ParaguayanGuarani Currency = "PYG" 69 | QatariRiyal Currency = "QAR" 70 | RomanianLeu Currency = "RON" 71 | SerbianDinar Currency = "RSD" 72 | RussianRuble Currency = "RUB" 73 | SaudiRiyal Currency = "SAR" 74 | SwedishKrona Currency = "SEK" 75 | SingaporeDollar Currency = "SGD" 76 | ThaiBaht Currency = "THB" 77 | TajikistaniSomoni Currency = "TJS" 78 | TurkishLira Currency = "TRY" 79 | TrinidadAndTobagoDollar Currency = "TTD" 80 | NewTaiwanDollar Currency = "TWD" 81 | TanzanianShilling Currency = "TZS" 82 | UkrainianHryvnia Currency = "UAH" 83 | UgandanShilling Currency = "UGX" 84 | UnitedStatesDollar Currency = "USD" 85 | UruguayanPeso Currency = "UYU" 86 | UzbekistaniSom Currency = "UZS" 87 | VietnameseDong Currency = "VND" 88 | YemeniRial Currency = "YER" 89 | SouthAfricanRand Currency = "ZAR" 90 | ) 91 | -------------------------------------------------------------------------------- /stickers.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // Sticker struct 6 | type Sticker struct { 7 | FileID string `json:"file_id"` 8 | FileUniqueID string `json:"file_unique_id"` 9 | Width int `json:"width"` 10 | Height int `json:"height"` 11 | IsAnimated bool `json:"is_animated"` 12 | IsVideo bool `json:"is_video"` 13 | Thumb *PhotoSize `json:"thumb,omitempty"` 14 | Emoji *string `json:"emoji,omitempty"` 15 | SetName *string `json:"set_name,omitempty"` 16 | MaskPosition *MaskPosition `json:"mask_position,omitempty"` 17 | FileSize *int `json:"file_size,omitempty"` 18 | } 19 | 20 | // StickerSet struct 21 | type StickerSet struct { 22 | Name string `json:"name"` 23 | Title string `json:"title"` 24 | IsAnimated bool `json:"is_animated"` 25 | IsVideo bool `json:"is_video"` 26 | ContainsMasks bool `json:"contains_masks"` 27 | Stickers []Sticker `json:"stickers"` 28 | Thumb *PhotoSize `json:"thumb,omitempty"` 29 | } 30 | 31 | // MaskPosition struct 32 | type MaskPosition struct { 33 | Point string `json:"point"` 34 | XShift float32 `json:"x_shift"` 35 | YShift float32 `json:"y_shift"` 36 | Scale float32 `json:"scale"` 37 | } 38 | 39 | // SendStickerResponse interface 40 | type SendStickerResponse interface { 41 | Response 42 | GetMessage() *Message 43 | } 44 | 45 | type sendStickerResponse struct { 46 | response 47 | Result *Message `json:"result,omitempty"` 48 | } 49 | 50 | func (r *sendStickerResponse) GetMessage() *Message { 51 | return r.Result 52 | } 53 | 54 | func (b *bot) SendSticker(ctx context.Context, options ...MethodOption) (SendStickerResponse, error) { 55 | var res sendStickerResponse 56 | 57 | err := b.doRequest(ctx, "sendSticker", &res, options...) 58 | if err != nil { 59 | return nil, err 60 | } 61 | 62 | return &res, nil 63 | } 64 | 65 | // GetStickerSetResponse interface 66 | type GetStickerSetResponse interface { 67 | Response 68 | GetStickerSet() *StickerSet 69 | } 70 | 71 | type getStickerSetResponse struct { 72 | response 73 | Result *StickerSet `json:"result,omitempty"` 74 | } 75 | 76 | func (r *getStickerSetResponse) GetStickerSet() *StickerSet { 77 | return r.Result 78 | } 79 | 80 | func (b *bot) GetStickerSet(ctx context.Context, options ...MethodOption) (GetStickerSetResponse, error) { 81 | var res getStickerSetResponse 82 | 83 | err := b.doRequest(ctx, "getStickerSet", &res, options...) 84 | if err != nil { 85 | return nil, err 86 | } 87 | 88 | return &res, nil 89 | } 90 | 91 | // UploadStickerFileResponse interface 92 | type UploadStickerFileResponse interface { 93 | Response 94 | GetUploadedFile() *File 95 | } 96 | 97 | type uploadStickerFileResponse struct { 98 | response 99 | Result *File `json:"result,omitempty"` 100 | } 101 | 102 | func (r *uploadStickerFileResponse) GetUploadedFile() *File { 103 | return r.Result 104 | } 105 | 106 | func (b *bot) UploadStickerFile(ctx context.Context, options ...MethodOption) (UploadStickerFileResponse, error) { 107 | var res uploadStickerFileResponse 108 | 109 | err := b.doRequest(ctx, "uploadStickerFile", &res, options...) 110 | if err != nil { 111 | return nil, err 112 | } 113 | 114 | return &res, nil 115 | } 116 | 117 | // CreateNewStickerSetResponse interface 118 | type CreateNewStickerSetResponse interface { 119 | Response 120 | } 121 | 122 | type createNewStickerSetResponse struct { 123 | response 124 | } 125 | 126 | func (b *bot) CreateNewStickerSet(ctx context.Context, options ...MethodOption) (CreateNewStickerSetResponse, error) { 127 | var res createNewStickerSetResponse 128 | 129 | err := b.doRequest(ctx, "createNewStickerSet", &res, options...) 130 | if err != nil { 131 | return nil, err 132 | } 133 | 134 | return &res, nil 135 | } 136 | 137 | // AddStickerToSetResponse interface 138 | type AddStickerToSetResponse interface { 139 | Response 140 | } 141 | 142 | type addStickerToSetResponse struct { 143 | response 144 | } 145 | 146 | func (b *bot) AddStickerToSet(ctx context.Context, options ...MethodOption) (AddStickerToSetResponse, error) { 147 | var res addStickerToSetResponse 148 | 149 | err := b.doRequest(ctx, "addStickerToSet", &res, options...) 150 | if err != nil { 151 | return nil, err 152 | } 153 | 154 | return &res, nil 155 | } 156 | 157 | // SetStickerPositionInSetResponse interface 158 | type SetStickerPositionInSetResponse interface { 159 | Response 160 | } 161 | 162 | type setStickerPositionInSetResponse struct { 163 | response 164 | } 165 | 166 | func (b *bot) SetStickerPositionInSet(ctx context.Context, options ...MethodOption) (SetStickerPositionInSetResponse, error) { 167 | var res setStickerPositionInSetResponse 168 | 169 | err := b.doRequest(ctx, "setStickerPositionInSet", &res, options...) 170 | if err != nil { 171 | return nil, err 172 | } 173 | 174 | return &res, nil 175 | } 176 | 177 | // DeleteStickerFromSetResponse interface 178 | type DeleteStickerFromSetResponse interface { 179 | Response 180 | } 181 | 182 | type deleteStickerFromSetResponse struct { 183 | response 184 | } 185 | 186 | func (b *bot) DeleteStickerFromSet(ctx context.Context, options ...MethodOption) (DeleteStickerFromSetResponse, error) { 187 | var res deleteStickerFromSetResponse 188 | 189 | err := b.doRequest(ctx, "deleteStickerFromSet", &res, options...) 190 | if err != nil { 191 | return nil, err 192 | } 193 | 194 | return &res, nil 195 | } 196 | 197 | // SetStickerSetThumbResponse interface 198 | type SetStickerSetThumbResponse interface { 199 | Response 200 | } 201 | 202 | type setStickerSetThumbResponse struct { 203 | response 204 | } 205 | 206 | func (b *bot) SetStickerSetThumb(ctx context.Context, options ...MethodOption) (SetStickerSetThumbResponse, error) { 207 | var res setStickerSetThumbResponse 208 | 209 | err := b.doRequest(ctx, "setStickerSetThumb", &res, options...) 210 | if err != nil { 211 | return nil, err 212 | } 213 | 214 | return &res, nil 215 | } 216 | -------------------------------------------------------------------------------- /telegram.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // Bot interface 6 | type Bot interface { 7 | GetToken() string 8 | 9 | // getting updates 10 | 11 | GetUpdates(ctx context.Context, options ...MethodOption) (res GetUpdatesResponse, err error) 12 | SetWebhook(ctx context.Context, options ...MethodOption) (res SetWebhookResponse, err error) 13 | DeleteWebhook(ctx context.Context) (res DeleteWebhookResponse, err error) 14 | GetWebhookInfo(ctx context.Context) (res GetWebhookInfoResponse, err error) 15 | 16 | // available methods 17 | 18 | GetMe(ctx context.Context) (res GetMeResponse, err error) 19 | LogOut(ctx context.Context) (res LogOutResponse, err error) 20 | Close(ctx context.Context) (res CloseResponse, err error) 21 | SendMessage(ctx context.Context, options ...MethodOption) (res SendMessageResponse, err error) 22 | ForwardMessage(ctx context.Context, options ...MethodOption) (res ForwardMessageResponse, err error) 23 | CopyMessage(ctx context.Context, options ...MethodOption) (CopyMessageResponse, error) 24 | SendPhoto(ctx context.Context, options ...MethodOption) (res SendPhotoResponse, err error) 25 | SendAudio(ctx context.Context, options ...MethodOption) (res SendAudioResponse, err error) 26 | SendDocument(ctx context.Context, options ...MethodOption) (res SendDocumentResponse, err error) 27 | SendVideo(ctx context.Context, options ...MethodOption) (res SendVideoResponse, err error) 28 | SendAnimation(ctx context.Context, options ...MethodOption) (res SendAnimationResponse, err error) 29 | SendVoice(ctx context.Context, options ...MethodOption) (res SendVoiceResponse, err error) 30 | SendVideoNote(ctx context.Context, options ...MethodOption) (res SendVideoNoteResponse, err error) 31 | SendMediaGroup(ctx context.Context, options ...MethodOption) (res SendMediaGroupResponse, err error) 32 | SendLocation(ctx context.Context, options ...MethodOption) (res SendLocationResponse, err error) 33 | EditMessageLiveLocation(ctx context.Context, options ...MethodOption) (res EditMessageLiveLocationResponse, err error) 34 | StopMessageLiveLocation(ctx context.Context, options ...MethodOption) (res StopMessageLiveLocationResponse, err error) 35 | SendVenue(ctx context.Context, options ...MethodOption) (res SendVenueResponse, err error) 36 | SendContact(ctx context.Context, options ...MethodOption) (res SendContactResponse, err error) 37 | SendPoll(ctx context.Context, options ...MethodOption) (res SendPollResponse, err error) 38 | SendDice(ctx context.Context, options ...MethodOption) (res SendDiceResponse, err error) 39 | SendChatAction(ctx context.Context, options ...MethodOption) (res SendChatActionResponse, err error) 40 | GetUserProfilePhotos(ctx context.Context, options ...MethodOption) (res GetUserProfilePhotosResponse, err error) 41 | GetFile(ctx context.Context, options ...MethodOption) (res GetFileResponse, err error) 42 | BanChatMember(ctx context.Context, options ...MethodOption) (res BanChatMemberResponse, err error) 43 | UnbanChatMember(ctx context.Context, options ...MethodOption) (res UnbanChatMemberResponse, err error) 44 | RestrictChatMember(ctx context.Context, options ...MethodOption) (res RestrictChatMemberResponse, err error) 45 | PromoteChatMember(ctx context.Context, options ...MethodOption) (res PromoteChatMemberResponse, err error) 46 | SetChatAdministratorCustomTitle(ctx context.Context, options ...MethodOption) (res SetChatAdministratorCustomTitleResponse, err error) 47 | BanChatSenderChat(ctx context.Context, options ...MethodOption) (res BanChatSenderChatResponse, err error) 48 | UnbanChatSenderChat(ctx context.Context, options ...MethodOption) (res UnbanChatSenderChatResponse, err error) 49 | ExportChatInviteLink(ctx context.Context, options ...MethodOption) (res ExportChatInviteLinkResponse, err error) 50 | CreateChatInviteLink(ctx context.Context, options ...MethodOption) (CreateChatInviteLinkResponse, error) 51 | EditChatInviteLink(ctx context.Context, options ...MethodOption) (EditChatInviteLinkResponse, error) 52 | RevokeChatInviteLink(ctx context.Context, options ...MethodOption) (RevokeChatInviteLinkResponse, error) 53 | ApproveChatJoinRequest(ctx context.Context, options ...MethodOption) (ApproveChatJoinRequestResponse, error) 54 | DeclineChatJoinRequest(ctx context.Context, options ...MethodOption) (DeclineChatJoinRequestResponse, error) 55 | SetChatPermissions(ctx context.Context, options ...MethodOption) (res SetChatPermissionsResponse, err error) 56 | SetChatPhoto(ctx context.Context, options ...MethodOption) (res SetChatPhotoResponse, err error) 57 | DeleteChatPhoto(ctx context.Context, options ...MethodOption) (res DeleteChatPhotoResponse, err error) 58 | SetChatTitle(ctx context.Context, options ...MethodOption) (res SetChatTitleResponse, err error) 59 | SetChatDescription(ctx context.Context, options ...MethodOption) (res SetChatDescriptionResponse, err error) 60 | PinChatMessage(ctx context.Context, options ...MethodOption) (res PinChatMessageResponse, err error) 61 | UnpinChatMessage(ctx context.Context, options ...MethodOption) (res UnpinChatMessageResponse, err error) 62 | UnpinAllChatMessages(ctx context.Context, options ...MethodOption) (UnpinAllChatMessagesResponse, error) 63 | LeaveChat(ctx context.Context, options ...MethodOption) (res LeaveChatResponse, err error) 64 | GetChat(ctx context.Context, options ...MethodOption) (res GetChatResponse, err error) 65 | GetChatAdministrators(ctx context.Context, options ...MethodOption) (res GetChatAdministratorsResponse, err error) 66 | GetChatMemberCount(ctx context.Context, options ...MethodOption) (res GetChatMemberCountResponse, err error) 67 | GetChatMember(ctx context.Context, options ...MethodOption) (res GetChatMemberResponse, err error) 68 | SetChatStickerSet(ctx context.Context, options ...MethodOption) (res SetChatStickerSetResponse, err error) 69 | DeleteChatStickerSet(ctx context.Context, options ...MethodOption) (res DeleteChatStickerSetResponse, err error) 70 | AnswerCallbackQuery(ctx context.Context, options ...MethodOption) (res AnswerCallbackQueryResponse, err error) 71 | SetMyCommands(ctx context.Context, options ...MethodOption) (res SetMyCommandsResponse, err error) 72 | DeleteMyCommands(ctx context.Context, options ...MethodOption) (res DeleteMyCommandsResponse, err error) 73 | GetMyCommands(ctx context.Context) (res GetMyCommandsResponse, err error) 74 | 75 | // updating messages 76 | 77 | EditMessageText(ctx context.Context, options ...MethodOption) (res EditMessageTextResponse, err error) 78 | EditMessageCaption(ctx context.Context, options ...MethodOption) (res EditMessageCaptionResponse, err error) 79 | EditMessageMedia(ctx context.Context, options ...MethodOption) (res EditMessageMediaResponse, err error) 80 | EditMessageReplyMarkup(ctx context.Context, options ...MethodOption) (res EditMessageReplyMarkupResponse, err error) 81 | StopPoll(ctx context.Context, options ...MethodOption) (res StopPollResponse, err error) 82 | DeleteMessage(ctx context.Context, options ...MethodOption) (res DeleteMessageResponse, err error) 83 | 84 | // stickers 85 | 86 | SendSticker(ctx context.Context, options ...MethodOption) (res SendStickerResponse, err error) 87 | GetStickerSet(ctx context.Context, options ...MethodOption) (res GetStickerSetResponse, err error) 88 | UploadStickerFile(ctx context.Context, options ...MethodOption) (res UploadStickerFileResponse, err error) 89 | CreateNewStickerSet(ctx context.Context, options ...MethodOption) (res CreateNewStickerSetResponse, err error) 90 | AddStickerToSet(ctx context.Context, options ...MethodOption) (res AddStickerToSetResponse, err error) 91 | SetStickerPositionInSet(ctx context.Context, options ...MethodOption) (res SetStickerPositionInSetResponse, err error) 92 | DeleteStickerFromSet(ctx context.Context, options ...MethodOption) (res DeleteStickerFromSetResponse, err error) 93 | SetStickerSetThumb(ctx context.Context, options ...MethodOption) (res SetStickerSetThumbResponse, err error) 94 | 95 | // inline mode 96 | 97 | AnswerInlineQuery(ctx context.Context, options ...MethodOption) (res AnswerInlineQueryResponse, err error) 98 | 99 | // payments 100 | 101 | SendInvoice(ctx context.Context, options ...MethodOption) (res SendInvoiceResponse, err error) 102 | AnswerShippingQuery(ctx context.Context, options ...MethodOption) (res AnswerShippingQueryResponse, err error) 103 | AnswerPreCheckoutQuery(ctx context.Context, options ...MethodOption) (res AnswerPreCheckoutQueryResponse, err error) 104 | 105 | // telegram passport 106 | 107 | SetPassportDataErrors(ctx context.Context, options ...MethodOption) (res SetPassportDataErrorsResponse, err error) 108 | 109 | // games 110 | 111 | SendGame(ctx context.Context, options ...MethodOption) (res SendGameResponse, err error) 112 | SetGameScore(ctx context.Context, options ...MethodOption) (res SetGameScoreResponse, err error) 113 | GetGameHighScores(ctx context.Context, options ...MethodOption) (res GetGameHighScoresResponse, err error) 114 | } 115 | 116 | // BotOption type 117 | type BotOption func(*bot) 118 | 119 | type bot struct { 120 | token string 121 | baseURL string 122 | } 123 | 124 | // New return a telegram bot instance 125 | func New(token string, options ...BotOption) Bot { 126 | b := bot{ 127 | token: token, 128 | baseURL: "https://api.telegram.org", 129 | } 130 | 131 | for i := range options { 132 | options[i](&b) 133 | } 134 | 135 | return &b 136 | } 137 | 138 | func (b *bot) GetToken() string { 139 | return b.token 140 | } 141 | 142 | // SetBaseURL method 143 | func SetBaseURL(v string) BotOption { 144 | return func(b *bot) { 145 | b.baseURL = v 146 | } 147 | } 148 | 149 | func (b *bot) GetBaseURL() string { 150 | return b.baseURL 151 | } 152 | -------------------------------------------------------------------------------- /inline-mode.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | type ChatType string 6 | 7 | const ( 8 | ChatTypeSender ChatType = "sender" 9 | ChatTypePrivate ChatType = "private" 10 | ChatTypeGroup ChatType = "group" 11 | ChatTypeSupergroup ChatType = "supergroup" 12 | ChatTypeChannel ChatType = "channel" 13 | ) 14 | 15 | // InlineQuery struct 16 | type InlineQuery struct { 17 | ID string `json:"id"` 18 | From User `json:"from"` 19 | Query string `json:"query"` 20 | Offset string `json:"offset"` 21 | ChatType *ChatType `json:"chat_type,omitempty"` 22 | Location *Location `json:"location,omitempty"` 23 | } 24 | 25 | // AnswerInlineQueryResponse interface 26 | type AnswerInlineQueryResponse interface { 27 | Response 28 | } 29 | 30 | type answerInlineQueryResponse struct { 31 | response 32 | } 33 | 34 | func (b *bot) AnswerInlineQuery(ctx context.Context, options ...MethodOption) (AnswerInlineQueryResponse, error) { 35 | var res answerInlineQueryResponse 36 | 37 | err := b.doRequest(ctx, "answerInlineQuery", &res, options...) 38 | if err != nil { 39 | return nil, err 40 | } 41 | 42 | return &res, nil 43 | } 44 | 45 | // InlineQueryResult interface 46 | type InlineQueryResult interface{} 47 | 48 | type InlineQueryResultType string 49 | 50 | const ( 51 | InlineQueryResultTypeArticle = "article" 52 | InlineQueryResultTypePhoto = "photo" 53 | InlineQueryResultTypeGif = "gif" 54 | InlineQueryResultTypeMpeg4Gif = "mpeg4_gif" 55 | InlineQueryResultTypeVideo = "video" 56 | InlineQueryResultTypeAudio = "audio" 57 | InlineQueryResultTypeVoice = "voice" 58 | InlineQueryResultTypeDocument = "document" 59 | InlineQueryResultTypeLocation = "location" 60 | InlineQueryResultTypeVenue = "venue" 61 | InlineQueryResultTypeContact = "contact" 62 | InlineQueryResultTypeGame = "game" 63 | InlineQueryResultTypeSticker = "sticker" 64 | ) 65 | 66 | // InlineQueryResultArticle struct 67 | type InlineQueryResultArticle struct { 68 | Type InlineQueryResultType `json:"type"` 69 | ID string `json:"id"` 70 | Title string `json:"title"` 71 | InputMessageContent InputMessageContent `json:"input_message_content"` 72 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 73 | URL *string `json:"url,omitempty"` 74 | HideURL *bool `json:"hide_url,omitempty"` 75 | Description *string `json:"description,omitempty"` 76 | ThumbURL *string `json:"thumb_url,omitempty"` 77 | ThumbWidth *int `json:"thumb_width,omitempty"` 78 | ThumbHeight *int `json:"thumb_height,omitempty"` 79 | } 80 | 81 | // InlineQueryResultPhoto struct 82 | type InlineQueryResultPhoto struct { 83 | Type InlineQueryResultType `json:"type"` 84 | ID string `json:"id"` 85 | PhotoURL string `json:"photo_url"` 86 | ThumbURL string `json:"thumb_url"` 87 | PhotoWidth *int `json:"photo_width,omitempty"` 88 | PhotoHeight *int `json:"photo_height,omitempty"` 89 | Title *string `json:"title,omitempty"` 90 | Description *string `json:"description,omitempty"` 91 | Caption *string `json:"caption,omitempty"` 92 | ParseMode *string `json:"parse_mode,omitempty"` 93 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 94 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 95 | } 96 | 97 | // InlineQueryResultGif struct 98 | type InlineQueryResultGif struct { 99 | Type InlineQueryResultType `json:"type"` 100 | ID string `json:"id"` 101 | GifURL string `json:"gif_url"` 102 | GifWidth *int `json:"gif_width,omitempty"` 103 | GifHeight *int `json:"gif_height,omitempty"` 104 | GifDuration *int `json:"gif_duration,omitempty"` 105 | ThumbURL string `json:"thumb_url"` 106 | ThumbMimeType string `json:"thumb_mime_type,omitempty"` 107 | Title *string `json:"title,omitempty"` 108 | Caption *string `json:"caption,omitempty"` 109 | ParseMode *string `json:"parse_mode,omitempty"` 110 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 111 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 112 | } 113 | 114 | // InlineQueryResultMpeg4Gif struct 115 | type InlineQueryResultMpeg4Gif struct { 116 | Type InlineQueryResultType `json:"type"` 117 | ID string `json:"id"` 118 | Mpeg4URL string `json:"mpeg4_url"` 119 | Mpeg4Width *int `json:"mpeg4_width,omitempty"` 120 | Mpeg4Height *int `json:"mpeg4_height,omitempty"` 121 | Mpeg4Duration *int `json:"mpeg4_duration,omitempty"` 122 | ThumbURL string `json:"thumb_url"` 123 | ThumbMimeType string `json:"thumb_mime_type,omitempty"` 124 | Title *string `json:"title,omitempty"` 125 | Caption *string `json:"caption,omitempty"` 126 | ParseMode *string `json:"parse_mode,omitempty"` 127 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 128 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 129 | } 130 | 131 | // InlineQueryResultVideo struct 132 | type InlineQueryResultVideo struct { 133 | Type InlineQueryResultType `json:"type"` 134 | ID string `json:"id"` 135 | VideoURL string `json:"video_url"` 136 | MimeType string `json:"mime_type"` 137 | ThumbURL string `json:"thumb_url"` 138 | Title string `json:"title"` 139 | Caption *string `json:"caption,omitempty"` 140 | ParseMode *string `json:"parse_mode,omitempty"` 141 | VideoWidth *int `json:"video_width,omitempty"` 142 | VideoHeight *int `json:"video_height,omitempty"` 143 | VideoDuration *int `json:"video_duration,omitempty"` 144 | Description *string `json:"description,omitempty"` 145 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 146 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 147 | } 148 | 149 | // InlineQueryResultAudio struct 150 | type InlineQueryResultAudio struct { 151 | Type InlineQueryResultType `json:"type"` 152 | ID string `json:"id"` 153 | AudioURL string `json:"audio_url"` 154 | Title string `json:"title"` 155 | Caption *string `json:"caption,omitempty"` 156 | ParseMode *string `json:"parse_mode,omitempty"` 157 | Performer *string `json:"performer,omitempty"` 158 | AudioDuration *int `json:"audio_duration,omitempty"` 159 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 160 | InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` 161 | } 162 | 163 | // InlineQueryResultVoice struct 164 | type InlineQueryResultVoice struct { 165 | Type InlineQueryResultType `json:"type"` 166 | ID string `json:"id"` 167 | VoiceURL string `json:"voice_url"` 168 | Title string `json:"title"` 169 | Caption *string `json:"caption,omitempty"` 170 | ParseMode *string `json:"parse_mode,omitempty"` 171 | VoiceDuration *string `json:"voice_duration,omitempty"` 172 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 173 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 174 | } 175 | 176 | // InlineQueryResultDocument struct 177 | type InlineQueryResultDocument struct { 178 | Type InlineQueryResultType `json:"type"` 179 | ID string `json:"id"` 180 | Title string `json:"title"` 181 | Caption *string `json:"caption,omitempty"` 182 | ParseMode *string `json:"parse_mode,omitempty"` 183 | DocumentURL string `json:"document_url"` 184 | MimeType string `json:"mime_type"` 185 | Description *string `json:"description,omitempty"` 186 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 187 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 188 | ThumbURL *string `json:"thumb_url,omitempty"` 189 | ThumbWidth *int `json:"thumb_width,omitempty"` 190 | ThumbHeight *int `json:"thumb_height,omitempty"` 191 | } 192 | 193 | // InlineQueryResultLocation struct 194 | type InlineQueryResultLocation struct { 195 | Type InlineQueryResultType `json:"type"` 196 | ID string `json:"id"` 197 | Latitude float64 `json:"latitude"` 198 | Longitude float64 `json:"longitude"` 199 | Title string `json:"title"` 200 | HorizontalAccuracy *float32 `json:"horizontal_accuracy,omitempty"` 201 | LivePeriod *int `json:"live_period,omitempty"` 202 | Heading *int `json:"heading,omitempty"` 203 | ProximityAlertRadius *int `json:"proximity_alert_radius,omitempty"` 204 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 205 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 206 | ThumbURL *string `json:"thumb_url,omitempty"` 207 | ThumbWidth *int `json:"thumb_width,omitempty"` 208 | ThumbHeight *int `json:"thumb_height,omitempty"` 209 | } 210 | 211 | // InlineQueryResultVenue struct 212 | type InlineQueryResultVenue struct { 213 | Type InlineQueryResultType `json:"type"` 214 | ID string `json:"id"` 215 | Latitude float64 `json:"latitude"` 216 | Longitude float64 `json:"longitude"` 217 | Title string `json:"title"` 218 | Address string `json:"address"` 219 | FoursquareID *string `json:"foursquare_id,omitempty"` 220 | FoursquareType *string `json:"foursquare_type,omitempty"` 221 | GooglePlaceID *string `json:"google_place_id,omitempty"` 222 | GooglePlaceType *string `json:"google_place_type,omitempty"` 223 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 224 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 225 | ThumbURL *string `json:"thumb_url,omitempty"` 226 | ThumbWidth *int `json:"thumb_width,omitempty"` 227 | ThumbHeight *int `json:"thumb_height,omitempty"` 228 | } 229 | 230 | // InlineQueryResultContact struct 231 | type InlineQueryResultContact struct { 232 | Type InlineQueryResultType `json:"type"` 233 | ID string `json:"id"` 234 | PhoneNumber string `json:"phone_number"` 235 | FirstName string `json:"first_name"` 236 | LastName *string `json:"last_name,omitempty"` 237 | VCard *string `json:"vcard,omitempty"` 238 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 239 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 240 | ThumbURL *string `json:"thumb_url,omitempty"` 241 | ThumbWidth *int `json:"thumb_width,omitempty"` 242 | ThumbHeight *int `json:"thumb_height,omitempty"` 243 | } 244 | 245 | // InlineQueryResultGame struct 246 | type InlineQueryResultGame struct { 247 | Type InlineQueryResultType `json:"type"` 248 | ID string `json:"id"` 249 | GameShortName string `json:"game_short_name"` 250 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 251 | } 252 | 253 | // InlineQueryResultCachedPhoto struct 254 | type InlineQueryResultCachedPhoto struct { 255 | Type InlineQueryResultType `json:"type"` 256 | ID string `json:"id"` 257 | PhotoFileID string `json:"photo_file_id"` 258 | Title *string `json:"title,omitempty"` 259 | Description *string `json:"description,omitempty"` 260 | Caption *string `json:"caption,omitempty"` 261 | ParseMode *string `json:"parse_mode,omitempty"` 262 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 263 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 264 | } 265 | 266 | // InlineQueryResultCachedGif struct 267 | type InlineQueryResultCachedGif struct { 268 | Type InlineQueryResultType `json:"type"` 269 | ID string `json:"id"` 270 | GifFileID string `json:"gif_file_id"` 271 | Title *string `json:"title,omitempty"` 272 | Caption *string `json:"caption,omitempty"` 273 | ParseMode *string `json:"parse_mode,omitempty"` 274 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 275 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 276 | } 277 | 278 | // InlineQueryResultCachedMpeg4Gif struct 279 | type InlineQueryResultCachedMpeg4Gif struct { 280 | Type InlineQueryResultType `json:"type"` 281 | ID string `json:"id"` 282 | Mpeg4FileID string `json:"mpeg4_file_id"` 283 | Title *string `json:"title,omitempty"` 284 | Caption *string `json:"caption,omitempty"` 285 | ParseMode *string `json:"parse_mode,omitempty"` 286 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 287 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 288 | } 289 | 290 | // InlineQueryResultCachedSticker struct 291 | type InlineQueryResultCachedSticker struct { 292 | Type InlineQueryResultType `json:"type"` 293 | ID string `json:"id"` 294 | StickerFileID string `json:"sticker_file_id"` 295 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 296 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 297 | } 298 | 299 | // InlineQueryResultCachedDocument struct 300 | type InlineQueryResultCachedDocument struct { 301 | Type InlineQueryResultType `json:"type"` 302 | ID string `json:"id"` 303 | Title string `json:"title"` 304 | DocumentFileID string `json:"document_file_id"` 305 | Description *string `json:"description,omitempty"` 306 | Caption *string `json:"caption,omitempty"` 307 | ParseMode *string `json:"parse_mode,omitempty"` 308 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 309 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 310 | } 311 | 312 | // InlineQueryResultCachedVideo struct 313 | type InlineQueryResultCachedVideo struct { 314 | Type InlineQueryResultType `json:"type"` 315 | ID string `json:"id"` 316 | VideoFileID string `json:"video_file_id"` 317 | Title string `json:"title"` 318 | Description *string `json:"description,omitempty"` 319 | Caption *string `json:"caption,omitempty"` 320 | ParseMode *string `json:"parse_mode,omitempty"` 321 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 322 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 323 | } 324 | 325 | // InlineQueryResultCachedVoice struct 326 | type InlineQueryResultCachedVoice struct { 327 | Type InlineQueryResultType `json:"type"` 328 | ID string `json:"id"` 329 | VoiceFileID string `json:"voice_file_id"` 330 | Title string `json:"title"` 331 | Caption *string `json:"caption,omitempty"` 332 | ParseMode *string `json:"parse_mode,omitempty"` 333 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 334 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 335 | } 336 | 337 | // InlineQueryResultCachedAudio struct 338 | type InlineQueryResultCachedAudio struct { 339 | Type InlineQueryResultType `json:"type"` 340 | ID string `json:"id"` 341 | AudioFileID string `json:"audio_file_id"` 342 | Caption *string `json:"caption,omitempty"` 343 | ParseMode *string `json:"parse_mode,omitempty"` 344 | CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` 345 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 346 | InputMessageContent *InputMessageContent `json:"input_message_content,omitempty"` 347 | } 348 | 349 | // InputMessageContent interface 350 | type InputMessageContent interface{} 351 | 352 | // InputTextMessageContent struct 353 | type InputTextMessageContent struct { 354 | MessageText string `json:"message_text"` 355 | ParseMode *string `json:"parse_mode,omitempty"` 356 | DisableWebPagePreview *bool `json:"disable_web_page_preview,omitempty"` 357 | } 358 | 359 | // InputLocationMessageContent struct 360 | type InputLocationMessageContent struct { 361 | Latitude float64 `json:"latitude"` 362 | Longitude float64 `json:"longitude"` 363 | HorizontalAccuracy *float32 `json:"horizontal_accuracy,omitempty"` 364 | LivePeriod *int `json:"live_period,omitempty"` 365 | Heading *int `json:"heading,omitempty"` 366 | ProximityAlertRadius *int `json:"proximity_alert_radius,omitempty"` 367 | } 368 | 369 | // InputVenueMessageContent struct 370 | type InputVenueMessageContent struct { 371 | Latitude float64 `json:"latitude"` 372 | Longitude float64 `json:"longitude"` 373 | Title string `json:"title"` 374 | Address string `json:"address"` 375 | FoursquareID *string `json:"foursquare_id,omitempty"` 376 | FoursquareType *string `json:"foursquare_type,omitempty"` 377 | GooglePlaceID *string `json:"google_place_id,omitempty"` 378 | GooglePlaceType *string `json:"google_place_type,omitempty"` 379 | } 380 | 381 | // InputContactMessageContent struct 382 | type InputContactMessageContent struct { 383 | PhoneNumber string `json:"phone_number"` 384 | FirstName string `json:"first_name"` 385 | LastName *string `json:"last_name,omitempty"` 386 | VCard *string `json:"vcard,omitempty"` 387 | } 388 | 389 | // InputInvoiceMessageContent represents the content of an invoice message to be sent as the result of an inline query. 390 | type InputInvoiceMessageContent struct { 391 | Title string `json:"title"` 392 | Description string `json:"description"` 393 | Payload string `json:"payload"` 394 | ProviderToken string `json:"provider_token"` 395 | Currency Currency `json:"currency"` 396 | Prices []LabeledPrice `json:"prices"` 397 | MaxTipAmount *int `json:"max_tip_amount,omitempty"` 398 | SuggestedTipAmounts []int `json:"suggested_tip_amounts,omitempty"` 399 | ProviderData *string `json:"provider_data,omitempty"` 400 | PhotoURL *string `json:"photo_url,omitempty"` 401 | PhotoSize *int `json:"photo_size,omitempty"` 402 | PhotoWidth *int `json:"photo_width,omitempty"` 403 | PhotoHeight *int `json:"photo_height,omitempty"` 404 | NeedName *bool `json:"need_name,omitempty"` 405 | NeedPhoneNumber *bool `json:"need_phone_number,omitempty"` 406 | NeedEmail *bool `json:"need_email,omitempty"` 407 | NeedShippingAddress *bool `json:"need_shipping_address,omitempty"` 408 | SendPhoneNumberToProvider *bool `json:"send_phone_number_to_provider,omitempty"` 409 | SendEmailToProvider *bool `json:"send_email_to_provider,omitempty"` 410 | IsFlexible *bool `json:"is_flexible,omitempty"` 411 | } 412 | 413 | // ChosenInlineResult struct 414 | type ChosenInlineResult struct { 415 | ResultID string `json:"result_id"` 416 | From User `json:"from"` 417 | Location *Location `json:"location,omitempty"` 418 | InlineMessageID *string `json:"inline_message_id,omitempty"` 419 | Query string `json:"query"` 420 | } 421 | 422 | // AnswerWebAppQueryResponse interface. 423 | type AnswerWebAppQueryResponse interface { 424 | Response 425 | GetMessage() *Message 426 | } 427 | 428 | type answerWebAppQueryResponse struct { 429 | response 430 | Result *Message `json:"result,omitempty"` 431 | } 432 | 433 | func (r *answerWebAppQueryResponse) GetMessage() *Message { 434 | return r.Result 435 | } 436 | 437 | func (b *bot) AnswerWebAppQuery(ctx context.Context, options ...MethodOption) (AnswerWebAppQueryResponse, error) { 438 | var res answerWebAppQueryResponse 439 | 440 | err := b.doRequest(ctx, "answerWebAppQuery", &res, options...) 441 | if err != nil { 442 | return nil, err 443 | } 444 | 445 | return &res, nil 446 | } 447 | 448 | // SentWebAppMessage describes an inline message sent by a Web App on behalf of a user. 449 | type SentWebAppMessage struct { 450 | 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. 451 | } 452 | -------------------------------------------------------------------------------- /parameters.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | // MethodOption type 4 | type MethodOption func(*request) 5 | 6 | // SetOffset option function 7 | func SetOffset(v int) MethodOption { 8 | return func(r *request) { 9 | r.params["offset"] = v 10 | } 11 | } 12 | 13 | // SetLimit option function 14 | func SetLimit(v int) MethodOption { 15 | return func(r *request) { 16 | r.params["limit"] = v 17 | } 18 | } 19 | 20 | // SetTimeout option function 21 | func SetTimeout(v int) MethodOption { 22 | return func(r *request) { 23 | r.params["timeout"] = v 24 | } 25 | } 26 | 27 | // SetAllowedUpdates option function 28 | func SetAllowedUpdates(v ...string) MethodOption { 29 | return func(r *request) { 30 | r.params["allowed_updates"] = v 31 | } 32 | } 33 | 34 | // SetURL option function 35 | func SetURL(v string) MethodOption { 36 | return func(r *request) { 37 | r.params["url"] = v 38 | } 39 | } 40 | 41 | // SetCertificate option function 42 | func SetCertificate(v InputFile) MethodOption { 43 | return func(r *request) { 44 | r.params["certificate"] = v 45 | } 46 | } 47 | 48 | // SetIPAddress option function 49 | func SetIPAddress(v string) MethodOption { 50 | return func(r *request) { 51 | r.params["ip_address"] = v 52 | } 53 | } 54 | 55 | // DropPendingUpdates option function 56 | func DropPendingUpdates() MethodOption { 57 | return func(r *request) { 58 | r.params["drop_pending_updates"] = true 59 | } 60 | } 61 | 62 | // OnlyIfBanned option function 63 | func OnlyIfBanned() MethodOption { 64 | return func(r *request) { 65 | r.params["only_if_banned"] = true 66 | } 67 | } 68 | 69 | // DisableContentTypeDetection option function 70 | func DisableContentTypeDetection() MethodOption { 71 | return func(r *request) { 72 | r.params["disable_content_type_detection"] = true 73 | } 74 | } 75 | 76 | // SetMaxConnections option function 77 | func SetMaxConnections(v int) MethodOption { 78 | return func(r *request) { 79 | r.params["max_connections"] = v 80 | } 81 | } 82 | 83 | // SetChatID option function 84 | func SetChatID(v int64) MethodOption { 85 | return func(r *request) { 86 | r.params["chat_id"] = v 87 | } 88 | } 89 | 90 | // SetChatUsername option function 91 | func SetChatUsername(v string) MethodOption { 92 | return func(r *request) { 93 | r.params["chat_id"] = v 94 | } 95 | } 96 | 97 | // SetText option function 98 | func SetText(v string) MethodOption { 99 | return func(r *request) { 100 | r.params["text"] = v 101 | } 102 | } 103 | 104 | // SetParseMode option function 105 | func SetParseMode(v string) MethodOption { 106 | return func(r *request) { 107 | r.params["parse_mode"] = v 108 | } 109 | } 110 | 111 | // DisableWebPagePreview option function 112 | func DisableWebPagePreview() MethodOption { 113 | return func(r *request) { 114 | r.params["disable_web_page_preview"] = true 115 | } 116 | } 117 | 118 | // DisableNotification option function 119 | func DisableNotification() MethodOption { 120 | return func(r *request) { 121 | r.params["disable_notification"] = true 122 | } 123 | } 124 | 125 | // SetReplyToMessageID option function 126 | func SetReplyToMessageID(v int) MethodOption { 127 | return func(r *request) { 128 | r.params["reply_to_message_id"] = v 129 | } 130 | } 131 | 132 | // SetReplyMarkup option function 133 | func SetReplyMarkup(v interface{}) MethodOption { 134 | return func(r *request) { 135 | r.params["reply_markup"] = v 136 | } 137 | } 138 | 139 | // SetFromChatID option function 140 | func SetFromChatID(v int) MethodOption { 141 | return func(r *request) { 142 | r.params["from_chat_id"] = v 143 | } 144 | } 145 | 146 | // SetFromChatUsername option function 147 | func SetFromChatUsername(v string) MethodOption { 148 | return func(r *request) { 149 | r.params["from_chat_id"] = v 150 | } 151 | } 152 | 153 | // SetMessageID option function 154 | func SetMessageID(v int) MethodOption { 155 | return func(r *request) { 156 | r.params["message_id"] = v 157 | } 158 | } 159 | 160 | // SetPhotoFromFileID option function 161 | func SetPhotoFromFileID(v string) MethodOption { 162 | return func(r *request) { 163 | r.params["photo"] = v 164 | } 165 | } 166 | 167 | // SetPhotoFromURL option function 168 | func SetPhotoFromURL(v string) MethodOption { 169 | return func(r *request) { 170 | r.params["photo"] = v 171 | } 172 | } 173 | 174 | // SetPhoto option function 175 | func SetPhoto(v InputFile) MethodOption { 176 | return func(r *request) { 177 | r.params["photo"] = v 178 | } 179 | } 180 | 181 | // SetCaption option function 182 | func SetCaption(v string) MethodOption { 183 | return func(r *request) { 184 | r.params["caption"] = v 185 | } 186 | } 187 | 188 | // SetAudioFromFileID option function 189 | func SetAudioFromFileID(v string) MethodOption { 190 | return func(r *request) { 191 | r.params["audio"] = v 192 | } 193 | } 194 | 195 | // SetAudioFromURL option function 196 | func SetAudioFromURL(v string) MethodOption { 197 | return func(r *request) { 198 | r.params["audio"] = v 199 | } 200 | } 201 | 202 | // SetAudio option function 203 | func SetAudio(v InputFile) MethodOption { 204 | return func(r *request) { 205 | r.params["audio"] = v 206 | } 207 | } 208 | 209 | // SetDuration option function 210 | func SetDuration(v int) MethodOption { 211 | return func(r *request) { 212 | r.params["duration"] = v 213 | } 214 | } 215 | 216 | // SetPerformer option function 217 | func SetPerformer(v string) MethodOption { 218 | return func(r *request) { 219 | r.params["performer"] = v 220 | } 221 | } 222 | 223 | // SetTitle option function 224 | func SetTitle(v string) MethodOption { 225 | return func(r *request) { 226 | r.params["title"] = v 227 | } 228 | } 229 | 230 | // TODO: add Thumb string option 231 | 232 | // SetThumb option function 233 | func SetThumb(v InputFile) MethodOption { 234 | return func(r *request) { 235 | r.params["thumb"] = v 236 | } 237 | } 238 | 239 | // SetDocumentFromFileID option function 240 | func SetDocumentFromFileID(v string) MethodOption { 241 | return func(r *request) { 242 | r.params["document"] = v 243 | } 244 | } 245 | 246 | // SetDocumentFromURL option function 247 | func SetDocumentFromURL(v string) MethodOption { 248 | return func(r *request) { 249 | r.params["document"] = v 250 | } 251 | } 252 | 253 | // SetDocument option function 254 | func SetDocument(v InputFile) MethodOption { 255 | return func(r *request) { 256 | r.params["document"] = v 257 | } 258 | } 259 | 260 | // SetVideoFromFileID option function 261 | func SetVideoFromFileID(v string) MethodOption { 262 | return func(r *request) { 263 | r.params["video"] = v 264 | } 265 | } 266 | 267 | // SetVideoFromURL option function 268 | func SetVideoFromURL(v string) MethodOption { 269 | return func(r *request) { 270 | r.params["video"] = v 271 | } 272 | } 273 | 274 | // SetVideo option function 275 | func SetVideo(v InputFile) MethodOption { 276 | return func(r *request) { 277 | r.params["video"] = v 278 | } 279 | } 280 | 281 | // SetWidth option function 282 | func SetWidth(v string) MethodOption { 283 | return func(r *request) { 284 | r.params["width"] = v 285 | } 286 | } 287 | 288 | // SetHeight option function 289 | func SetHeight(v string) MethodOption { 290 | return func(r *request) { 291 | r.params["height"] = v 292 | } 293 | } 294 | 295 | // SupportsStreaming option function 296 | func SupportsStreaming() MethodOption { 297 | return func(r *request) { 298 | r.params["supports_streaming"] = true 299 | } 300 | } 301 | 302 | // SetAnimationFromFileID option function 303 | func SetAnimationFromFileID(v string) MethodOption { 304 | return func(r *request) { 305 | r.params["animation"] = v 306 | } 307 | } 308 | 309 | // SetAnimationFromURL option function 310 | func SetAnimationFromURL(v string) MethodOption { 311 | return func(r *request) { 312 | r.params["animation"] = v 313 | } 314 | } 315 | 316 | // SetAnimation option function 317 | func SetAnimation(v InputFile) MethodOption { 318 | return func(r *request) { 319 | r.params["animation"] = v 320 | } 321 | } 322 | 323 | // SetVoiceFromFileID option function 324 | func SetVoiceFromFileID(v string) MethodOption { 325 | return func(r *request) { 326 | r.params["voice"] = v 327 | } 328 | } 329 | 330 | // SetVoiceFromURL option function 331 | func SetVoiceFromURL(v string) MethodOption { 332 | return func(r *request) { 333 | r.params["voice"] = v 334 | } 335 | } 336 | 337 | // SetVoice option function 338 | func SetVoice(v InputFile) MethodOption { 339 | return func(r *request) { 340 | r.params["voice"] = v 341 | } 342 | } 343 | 344 | // SetVideoNoteFromFileID option function 345 | func SetVideoNoteFromFileID(v string) MethodOption { 346 | return func(r *request) { 347 | r.params["video_note"] = v 348 | } 349 | } 350 | 351 | // SetVideoNoteFromURL option function 352 | func SetVideoNoteFromURL(v string) MethodOption { 353 | return func(r *request) { 354 | r.params["video_note"] = v 355 | } 356 | } 357 | 358 | // SetVideoNote option function 359 | func SetVideoNote(v InputFile) MethodOption { 360 | return func(r *request) { 361 | r.params["video_note"] = v 362 | } 363 | } 364 | 365 | // SetMedia option function 366 | func SetMedia(v ...InputMedia) MethodOption { 367 | return func(r *request) { 368 | r.params["media"] = v 369 | } 370 | } 371 | 372 | // SetLatitude option function 373 | func SetLatitude(v float32) MethodOption { 374 | return func(r *request) { 375 | r.params["latitude"] = v 376 | } 377 | } 378 | 379 | // SetLongitude option function 380 | func SetLongitude(v float32) MethodOption { 381 | return func(r *request) { 382 | r.params["longitude"] = v 383 | } 384 | } 385 | 386 | // SetHorizontalAccuracy option function 387 | func SetHorizontalAccuracy(v float32) MethodOption { 388 | return func(r *request) { 389 | r.params["horizontal_accuracy"] = v 390 | } 391 | } 392 | 393 | // SetLivePeriod option function 394 | func SetLivePeriod(v int) MethodOption { 395 | return func(r *request) { 396 | r.params["live_period"] = v 397 | } 398 | } 399 | 400 | // SetHeading option function 401 | func SetHeading(v int) MethodOption { 402 | return func(r *request) { 403 | r.params["heading"] = v 404 | } 405 | } 406 | 407 | // SetProximityAlertRadius option function 408 | func SetProximityAlertRadius(v int) MethodOption { 409 | return func(r *request) { 410 | r.params["proximity_alert_radius"] = v 411 | } 412 | } 413 | 414 | // SetInlineMessageID option function 415 | func SetInlineMessageID(v string) MethodOption { 416 | return func(r *request) { 417 | r.params["inline_message_id"] = v 418 | } 419 | } 420 | 421 | // SetInlineQueryID option function 422 | func SetInlineQueryID(v string) MethodOption { 423 | return func(r *request) { 424 | r.params["inline_query_id"] = v 425 | } 426 | } 427 | 428 | // SetResults option function 429 | func SetResults(v []InlineQueryResult) MethodOption { 430 | return func(r *request) { 431 | r.params["results"] = v 432 | } 433 | } 434 | 435 | // SetAddress option function 436 | func SetAddress(v string) MethodOption { 437 | return func(r *request) { 438 | r.params["address"] = v 439 | } 440 | } 441 | 442 | // SetFoursquareID option function 443 | func SetFoursquareID(v string) MethodOption { 444 | return func(r *request) { 445 | r.params["foursquare_id"] = v 446 | } 447 | } 448 | 449 | // SetFoursquareType option function 450 | func SetFoursquareType(v string) MethodOption { 451 | return func(r *request) { 452 | r.params["foursquare_type"] = v 453 | } 454 | } 455 | 456 | // SetGooglePlaceID option function 457 | func SetGooglePlaceID(v string) MethodOption { 458 | return func(r *request) { 459 | r.params["google_place_id"] = v 460 | } 461 | } 462 | 463 | // SetGooglePlaceType option function 464 | func SetGooglePlaceType(v string) MethodOption { 465 | return func(r *request) { 466 | r.params["google_place_type"] = v 467 | } 468 | } 469 | 470 | // SetPhoneNumber option function 471 | func SetPhoneNumber(v string) MethodOption { 472 | return func(r *request) { 473 | r.params["phone_number"] = v 474 | } 475 | } 476 | 477 | // SetFirstName option function 478 | func SetFirstName(v string) MethodOption { 479 | return func(r *request) { 480 | r.params["first_name"] = v 481 | } 482 | } 483 | 484 | // SetLastName option function 485 | func SetLastName(v string) MethodOption { 486 | return func(r *request) { 487 | r.params["last_name"] = v 488 | } 489 | } 490 | 491 | // SetVCard option function 492 | func SetVCard(v string) MethodOption { 493 | return func(r *request) { 494 | r.params["vcard"] = v 495 | } 496 | } 497 | 498 | // SetQuestion option function 499 | func SetQuestion(v string) MethodOption { 500 | return func(r *request) { 501 | r.params["question"] = v 502 | } 503 | } 504 | 505 | // SetOptions option function 506 | func SetOptions(v ...string) MethodOption { 507 | return func(r *request) { 508 | r.params["options"] = v 509 | } 510 | } 511 | 512 | // SetCommands option function 513 | func SetCommands(v ...BotCommand) MethodOption { 514 | return func(r *request) { 515 | r.params["commands"] = v 516 | } 517 | } 518 | 519 | // SetScope option function 520 | func SetScope(v BotCommandScope) MethodOption { 521 | return func(r *request) { 522 | r.params["scope"] = v 523 | } 524 | } 525 | 526 | // SetLanguageCode option function 527 | func SetLanguageCode(v string) MethodOption { 528 | return func(r *request) { 529 | r.params["language_code"] = v 530 | } 531 | } 532 | 533 | type Action string 534 | 535 | const ( 536 | ActionTyping Action = "typing" 537 | ActionUploadPhoto Action = "upload_photo" 538 | ActionRecordVideo Action = "record_video" 539 | ActionUploadVideo Action = "upload_video" 540 | ActionRecordVoice Action = "record_voice" 541 | ActionUploadVoice Action = "upload_voice" 542 | ActionUploadDocument Action = "upload_document" 543 | ActionChooseSticker Action = "choose_sticker" 544 | ActionFindLocation Action = "find_location" 545 | ActionRecordVideoNote Action = "record_video_note" 546 | ActionUploadVideoNote Action = "upload_video_note" 547 | ) 548 | 549 | // SetAction option function 550 | func SetAction(v Action) MethodOption { 551 | return func(r *request) { 552 | r.params["action"] = v 553 | } 554 | } 555 | 556 | // SetFileID option function 557 | func SetFileID(v string) MethodOption { 558 | return func(r *request) { 559 | r.params["file_id"] = v 560 | } 561 | } 562 | 563 | // SetUserID option function 564 | func SetUserID(v int64) MethodOption { 565 | return func(r *request) { 566 | r.params["user_id"] = v 567 | } 568 | } 569 | 570 | // SetUntilDate option function 571 | func SetUntilDate(v int) MethodOption { 572 | return func(r *request) { 573 | r.params["until_date"] = v 574 | } 575 | } 576 | 577 | // AllowSendingWithoutReply option function 578 | func AllowSendingWithoutReply() MethodOption { 579 | return func(r *request) { 580 | r.params["allow_sending_without_reply"] = true 581 | } 582 | } 583 | 584 | // CanSendMessages option function 585 | func CanSendMessages() MethodOption { 586 | return func(r *request) { 587 | r.params["can_send_messages"] = true 588 | } 589 | } 590 | 591 | // CanSendMediaMessages option function 592 | func CanSendMediaMessages() MethodOption { 593 | return func(r *request) { 594 | r.params["can_send_media_messages"] = true 595 | } 596 | } 597 | 598 | // CanSendOtherMessages option function 599 | func CanSendOtherMessages() MethodOption { 600 | return func(r *request) { 601 | r.params["can_send_other_messages"] = true 602 | } 603 | } 604 | 605 | // CanAddWebPagePreviews option function 606 | func CanAddWebPagePreviews() MethodOption { 607 | return func(r *request) { 608 | r.params["can_add_web_page_previews"] = true 609 | } 610 | } 611 | 612 | // CanChangeInfo option function 613 | func CanChangeInfo() MethodOption { 614 | return func(r *request) { 615 | r.params["can_change_info"] = true 616 | } 617 | } 618 | 619 | // CanPostMessages option function 620 | func CanPostMessages() MethodOption { 621 | return func(r *request) { 622 | r.params["can_post_messages"] = true 623 | } 624 | } 625 | 626 | // CanEditMessages option function 627 | func CanEditMessages() MethodOption { 628 | return func(r *request) { 629 | r.params["can_edit_messages"] = true 630 | } 631 | } 632 | 633 | // CanDeleteMessages option function 634 | func CanDeleteMessages() MethodOption { 635 | return func(r *request) { 636 | r.params["can_delete_messages"] = true 637 | } 638 | } 639 | 640 | // CanInviteUsers option function 641 | func CanInviteUsers() MethodOption { 642 | return func(r *request) { 643 | r.params["can_invite_users"] = true 644 | } 645 | } 646 | 647 | // CanRestrictMembers option function 648 | func CanRestrictMembers() MethodOption { 649 | return func(r *request) { 650 | r.params["can_restrict_members"] = true 651 | } 652 | } 653 | 654 | // CanPinMessages option function 655 | func CanPinMessages() MethodOption { 656 | return func(r *request) { 657 | r.params["can_pin_messages"] = true 658 | } 659 | } 660 | 661 | // CanPromoteMembers option function 662 | func CanPromoteMembers() MethodOption { 663 | return func(r *request) { 664 | r.params["can_promote_members"] = true 665 | } 666 | } 667 | 668 | // SetDescription option function 669 | func SetDescription(v string) MethodOption { 670 | return func(r *request) { 671 | r.params["description"] = v 672 | } 673 | } 674 | 675 | // SetStickerSetName option function 676 | func SetStickerSetName(v string) MethodOption { 677 | return func(r *request) { 678 | r.params["sticker_set_name"] = v 679 | } 680 | } 681 | 682 | // SetCallbackQueryID option function 683 | func SetCallbackQueryID(v string) MethodOption { 684 | return func(r *request) { 685 | r.params["callback_query_id"] = v 686 | } 687 | } 688 | 689 | // ShowAlert option function 690 | func ShowAlert() MethodOption { 691 | return func(r *request) { 692 | r.params["show_alert"] = true 693 | } 694 | } 695 | 696 | // SetCacheTime option function 697 | func SetCacheTime(v int) MethodOption { 698 | return func(r *request) { 699 | r.params["cache_time"] = v 700 | } 701 | } 702 | 703 | // SetNextOffset option function 704 | func SetNextOffset(v string) MethodOption { 705 | return func(r *request) { 706 | r.params["next_offset"] = v 707 | } 708 | } 709 | 710 | // SetSwitchPMText option function 711 | func SetSwitchPMText(v string) MethodOption { 712 | return func(r *request) { 713 | r.params["switch_pm_text"] = v 714 | } 715 | } 716 | 717 | // SetSwitchPMParameter option function 718 | func SetSwitchPMParameter(v string) MethodOption { 719 | return func(r *request) { 720 | r.params["switch_pm_parameter"] = v 721 | } 722 | } 723 | 724 | // IsPersonal option function 725 | func IsPersonal() MethodOption { 726 | return func(r *request) { 727 | r.params["is_personal"] = true 728 | } 729 | } 730 | 731 | // SetPermissions option function 732 | func SetPermissions(v ChatPermissions) MethodOption { 733 | return func(r *request) { 734 | r.params["permissions"] = v 735 | } 736 | } 737 | 738 | // SetCustomTitle option function 739 | func SetCustomTitle(v string) MethodOption { 740 | return func(r *request) { 741 | r.params["custom_title"] = v 742 | } 743 | } 744 | 745 | // IsAnonymous option function 746 | func IsAnonymous() MethodOption { 747 | return func(r *request) { 748 | r.params["is_anonymous"] = true 749 | } 750 | } 751 | 752 | // SetType option function 753 | func SetType(v string) MethodOption { 754 | return func(r *request) { 755 | r.params["type"] = v 756 | } 757 | } 758 | 759 | // SetInlineQueryResultType option function 760 | func SetInlineQueryResultType(v InlineQueryResultType) MethodOption { 761 | return func(r *request) { 762 | r.params["type"] = v 763 | } 764 | } 765 | 766 | // AllowsMultipleAnswers option function 767 | func AllowsMultipleAnswers() MethodOption { 768 | return func(r *request) { 769 | r.params["allows_multiple_answers"] = true 770 | } 771 | } 772 | 773 | // SetCorrectOptionID option function 774 | func SetCorrectOptionID(v int) MethodOption { 775 | return func(r *request) { 776 | r.params["correct_option_id"] = v 777 | } 778 | } 779 | 780 | // IsClosed option function 781 | func IsClosed() MethodOption { 782 | return func(r *request) { 783 | r.params["is_closed"] = true 784 | } 785 | } 786 | 787 | // SetPNGStickerFromFileID option function 788 | func SetPNGStickerFromFileID(v string) MethodOption { 789 | return func(r *request) { 790 | r.params["png_sticker"] = v 791 | } 792 | } 793 | 794 | // SetPNGStickerFromURL option function 795 | func SetPNGStickerFromURL(v string) MethodOption { 796 | return func(r *request) { 797 | r.params["png_sticker"] = v 798 | } 799 | } 800 | 801 | // SetPNGSticker option function 802 | func SetPNGSticker(v InputFile) MethodOption { 803 | return func(r *request) { 804 | r.params["png_sticker"] = v 805 | } 806 | } 807 | 808 | // SetTGSSticker option function 809 | func SetTGSSticker(v InputFile) MethodOption { 810 | return func(r *request) { 811 | r.params["tgs_sticker"] = v 812 | } 813 | } 814 | 815 | // SetEmojis option function 816 | func SetEmojis(v string) MethodOption { 817 | return func(r *request) { 818 | r.params["emojis"] = v 819 | } 820 | } 821 | 822 | // SetEmoji option function 823 | func SetEmoji(v string) MethodOption { 824 | return func(r *request) { 825 | r.params["emoji"] = v 826 | } 827 | } 828 | 829 | // ContainsMasks option function 830 | func ContainsMasks() MethodOption { 831 | return func(r *request) { 832 | r.params["contains_masks"] = true 833 | } 834 | } 835 | 836 | // SetMaskPosition option function 837 | func SetMaskPosition(v MaskPosition) MethodOption { 838 | return func(r *request) { 839 | r.params["mask_position"] = v 840 | } 841 | } 842 | 843 | // SetExplanation option function 844 | func SetExplanation(v string) MethodOption { 845 | return func(r *request) { 846 | r.params["explanation"] = v 847 | } 848 | } 849 | 850 | // SetExplanationParseMode option function 851 | func SetExplanationParseMode(v string) MethodOption { 852 | return func(r *request) { 853 | r.params["explanation_parse_mode"] = v 854 | } 855 | } 856 | 857 | // SetOpenPeriod option function 858 | func SetOpenPeriod(v int) MethodOption { 859 | return func(r *request) { 860 | r.params["open_period"] = v 861 | } 862 | } 863 | 864 | // SetCloseDate option function 865 | func SetCloseDate(v int) MethodOption { 866 | return func(r *request) { 867 | r.params["close_date"] = v 868 | } 869 | } 870 | 871 | // SetExpireDate option function 872 | func SetExpireDate(v int) MethodOption { 873 | return func(r *request) { 874 | r.params["expire_date"] = v 875 | } 876 | } 877 | 878 | // SetMemberLimit option function 879 | func SetMemberLimit(v int) MethodOption { 880 | return func(r *request) { 881 | r.params["member_limit"] = v 882 | } 883 | } 884 | 885 | // SetInviteLink option function 886 | func SetInviteLink(v string) MethodOption { 887 | return func(r *request) { 888 | r.params["invite_link"] = v 889 | } 890 | } 891 | 892 | // CanManageChat option function 893 | func CanManageChat() MethodOption { 894 | return func(r *request) { 895 | r.params["can_manage_chat"] = true 896 | } 897 | } 898 | 899 | // CanManageVoiceChats option function 900 | // Deprecated 901 | func CanManageVoiceChats() MethodOption { 902 | return func(r *request) { 903 | r.params["can_manage_voice_chats"] = true 904 | } 905 | } 906 | 907 | // CanManageVideoChats option function 908 | func CanManageVideoChats() MethodOption { 909 | return func(r *request) { 910 | r.params["can_manage_video_chats"] = true 911 | } 912 | } 913 | 914 | // RevokeMessages option function 915 | func RevokeMessages() MethodOption { 916 | return func(r *request) { 917 | r.params["revoke_messages"] = true 918 | } 919 | } 920 | 921 | // SetPayload option function 922 | func SetPayload(v string) MethodOption { 923 | return func(r *request) { 924 | r.params["payload"] = v 925 | } 926 | } 927 | 928 | // SetProviderToken option function 929 | func SetProviderToken(v string) MethodOption { 930 | return func(r *request) { 931 | r.params["provider_token"] = v 932 | } 933 | } 934 | 935 | // SetCurrency option function 936 | func SetCurrency(v Currency) MethodOption { 937 | return func(r *request) { 938 | r.params["currency"] = v 939 | } 940 | } 941 | 942 | // SetPrices option function 943 | func SetPrices(v ...LabeledPrice) MethodOption { 944 | return func(r *request) { 945 | r.params["prices"] = v 946 | } 947 | } 948 | 949 | // SetMaxTipAmount option function 950 | func SetMaxTipAmount(v int) MethodOption { 951 | return func(r *request) { 952 | r.params["max_tip_amount"] = v 953 | } 954 | } 955 | 956 | // SetSuggestedTipAmounts option function 957 | func SetSuggestedTipAmounts(v ...int) MethodOption { 958 | return func(r *request) { 959 | r.params["suggested_tip_amounts"] = v 960 | } 961 | } 962 | 963 | // SetStartParameter option function 964 | func SetStartParameter(v string) MethodOption { 965 | return func(r *request) { 966 | r.params["start_parameter"] = v 967 | } 968 | } 969 | 970 | // SetProviderData option function 971 | func SetProviderData(v string) MethodOption { 972 | return func(r *request) { 973 | r.params["provider_data"] = v 974 | } 975 | } 976 | 977 | // SetPhotoURL option function 978 | func SetPhotoURL(v string) MethodOption { 979 | return func(r *request) { 980 | r.params["photo_url"] = v 981 | } 982 | } 983 | 984 | // SetPhotoSize option function 985 | func SetPhotoSize(v int) MethodOption { 986 | return func(r *request) { 987 | r.params["photo_size"] = v 988 | } 989 | } 990 | 991 | // SetPhotoWidth option function 992 | func SetPhotoWidth(v int) MethodOption { 993 | return func(r *request) { 994 | r.params["photo_width"] = v 995 | } 996 | } 997 | 998 | // SetPhotoHeight option function 999 | func SetPhotoHeight(v int) MethodOption { 1000 | return func(r *request) { 1001 | r.params["photo_height"] = v 1002 | } 1003 | } 1004 | 1005 | // NeedName option function 1006 | func NeedName() MethodOption { 1007 | return func(r *request) { 1008 | r.params["need_name"] = true 1009 | } 1010 | } 1011 | 1012 | // NeedPhoneNumber option function 1013 | func NeedPhoneNumber() MethodOption { 1014 | return func(r *request) { 1015 | r.params["need_phone_number"] = true 1016 | } 1017 | } 1018 | 1019 | // NeedEmail option function 1020 | func NeedEmail() MethodOption { 1021 | return func(r *request) { 1022 | r.params["need_email"] = true 1023 | } 1024 | } 1025 | 1026 | // NeedShippingAddress option function 1027 | func NeedShippingAddress() MethodOption { 1028 | return func(r *request) { 1029 | r.params["need_shipping_address"] = true 1030 | } 1031 | } 1032 | 1033 | // SendPhoneNumberToProvider option function 1034 | func SendPhoneNumberToProvider() MethodOption { 1035 | return func(r *request) { 1036 | r.params["send_phone_number_to_provider"] = true 1037 | } 1038 | } 1039 | 1040 | // SendEmailToProvider option function 1041 | func SendEmailToProvider() MethodOption { 1042 | return func(r *request) { 1043 | r.params["send_email_to_provider"] = true 1044 | } 1045 | } 1046 | 1047 | // IsFlexible option function 1048 | func IsFlexible() MethodOption { 1049 | return func(r *request) { 1050 | r.params["is_flexible"] = true 1051 | } 1052 | } 1053 | 1054 | // CreatesJoinRequest option function 1055 | func CreatesJoinRequest() MethodOption { 1056 | return func(r *request) { 1057 | r.params["creates_join_request"] = true 1058 | } 1059 | } 1060 | 1061 | // SetName option function 1062 | func SetName(v string) MethodOption { 1063 | return func(r *request) { 1064 | r.params["name"] = v 1065 | } 1066 | } 1067 | 1068 | // SetSenderChatID option function 1069 | func SetSenderChatID(v int) MethodOption { 1070 | return func(r *request) { 1071 | r.params["sender_chat_id"] = v 1072 | } 1073 | } 1074 | 1075 | // ProtectContent option function 1076 | func ProtectContent() MethodOption { 1077 | return func(r *request) { 1078 | r.params["protect_content"] = true 1079 | } 1080 | } 1081 | 1082 | // SetWebAppQueryID option function 1083 | func SetWebAppQueryID(v string) MethodOption { 1084 | return func(r *request) { 1085 | r.params["web_app_query_id"] = v 1086 | } 1087 | } 1088 | 1089 | // SetMenuButton option function 1090 | func SetMenuButton(v MenuButton) MethodOption { 1091 | return func(r *request) { 1092 | r.params["menu_button"] = v 1093 | } 1094 | } 1095 | 1096 | // SetRights option function 1097 | func SetRights(v ChatAdministratorRights) MethodOption { 1098 | return func(r *request) { 1099 | r.params["rights"] = v 1100 | } 1101 | } 1102 | 1103 | // ForChannels option function 1104 | func ForChannels() MethodOption { 1105 | return func(r *request) { 1106 | r.params["for_channels"] = true 1107 | } 1108 | } 1109 | -------------------------------------------------------------------------------- /available-methods.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "context" 4 | 5 | // GetMeResponse interface. 6 | type GetMeResponse interface { 7 | Response 8 | GetUser() *User 9 | } 10 | 11 | type getMeResponse struct { 12 | response 13 | Result *User `json:"result,omitempty"` 14 | } 15 | 16 | func (r *getMeResponse) GetUser() *User { 17 | return r.Result 18 | } 19 | 20 | func (b *bot) GetMe(ctx context.Context) (GetMeResponse, error) { 21 | var res getMeResponse 22 | 23 | err := b.doRequest(ctx, "getMe", &res) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return &res, nil 29 | } 30 | 31 | // LogOutResponse interface. 32 | type LogOutResponse interface { 33 | Response 34 | } 35 | 36 | type logOutResponse struct { 37 | response 38 | } 39 | 40 | func (b *bot) LogOut(ctx context.Context) (LogOutResponse, error) { 41 | var res logOutResponse 42 | 43 | err := b.doRequest(ctx, "logOut", &res) 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | return &res, nil 49 | } 50 | 51 | // CloseResponse interface. 52 | type CloseResponse interface { 53 | Response 54 | } 55 | 56 | type closeResponse struct { 57 | response 58 | } 59 | 60 | func (b *bot) Close(ctx context.Context) (CloseResponse, error) { 61 | var res closeResponse 62 | 63 | err := b.doRequest(ctx, "close", &res) 64 | if err != nil { 65 | return nil, err 66 | } 67 | 68 | return &res, nil 69 | } 70 | 71 | // SendMessageResponse interface. 72 | type SendMessageResponse interface { 73 | Response 74 | GetMessage() *Message 75 | } 76 | 77 | type sendMessageResponse struct { 78 | response 79 | Result *Message `json:"result,omitempty"` 80 | } 81 | 82 | func (r *sendMessageResponse) GetMessage() *Message { 83 | return r.Result 84 | } 85 | 86 | func (b *bot) SendMessage(ctx context.Context, options ...MethodOption) (SendMessageResponse, error) { 87 | var res sendMessageResponse 88 | 89 | err := b.doRequest(ctx, "sendMessage", &res, options...) 90 | if err != nil { 91 | return nil, err 92 | } 93 | 94 | return &res, nil 95 | } 96 | 97 | // ForwardMessageResponse interface. 98 | type ForwardMessageResponse interface { 99 | Response 100 | GetMessage() *Message 101 | } 102 | 103 | type forwardMessageResponse struct { 104 | response 105 | Result *Message `json:"result,omitempty"` 106 | } 107 | 108 | func (r *forwardMessageResponse) GetMessage() *Message { 109 | return r.Result 110 | } 111 | 112 | func (b *bot) ForwardMessage(ctx context.Context, options ...MethodOption) (ForwardMessageResponse, error) { 113 | var res forwardMessageResponse 114 | 115 | err := b.doRequest(ctx, "forwardMessage", &res, options...) 116 | if err != nil { 117 | return nil, err 118 | } 119 | 120 | return &res, nil 121 | } 122 | 123 | // CopyMessageResponse interface. 124 | type CopyMessageResponse interface { 125 | Response 126 | GetMessageID() *MessageID 127 | } 128 | 129 | type copyMessageResponse struct { 130 | response 131 | Result *MessageID `json:"result,omitempty"` 132 | } 133 | 134 | func (r *copyMessageResponse) GetMessageID() *MessageID { 135 | return r.Result 136 | } 137 | 138 | func (b *bot) CopyMessage(ctx context.Context, options ...MethodOption) (CopyMessageResponse, error) { 139 | var res copyMessageResponse 140 | 141 | err := b.doRequest(ctx, "copyMessage", &res, options...) 142 | if err != nil { 143 | return nil, err 144 | } 145 | 146 | return &res, nil 147 | } 148 | 149 | // SendPhotoResponse interface 150 | type SendPhotoResponse interface { 151 | Response 152 | GetMessage() *Message 153 | } 154 | 155 | type sendPhotoResponse struct { 156 | response 157 | Result *Message `json:"result,omitempty"` 158 | } 159 | 160 | func (r *sendPhotoResponse) GetMessage() *Message { 161 | return r.Result 162 | } 163 | 164 | func (b *bot) SendPhoto(ctx context.Context, options ...MethodOption) (SendPhotoResponse, error) { 165 | var res sendPhotoResponse 166 | 167 | err := b.doRequest(ctx, "sendPhoto", &res, options...) 168 | if err != nil { 169 | return nil, err 170 | } 171 | 172 | return &res, nil 173 | } 174 | 175 | // SendAudioResponse interface 176 | type SendAudioResponse interface { 177 | Response 178 | GetMessage() *Message 179 | } 180 | 181 | type sendAudioResponse struct { 182 | response 183 | Result *Message `json:"result,omitempty"` 184 | } 185 | 186 | func (r *sendAudioResponse) GetMessage() *Message { 187 | return r.Result 188 | } 189 | 190 | func (b *bot) SendAudio(ctx context.Context, options ...MethodOption) (SendAudioResponse, error) { 191 | var res sendAudioResponse 192 | 193 | err := b.doRequest(ctx, "sendAudio", &res, options...) 194 | if err != nil { 195 | return nil, err 196 | } 197 | 198 | return &res, nil 199 | } 200 | 201 | // SendDocumentResponse interface 202 | type SendDocumentResponse interface { 203 | Response 204 | GetMessage() *Message 205 | } 206 | 207 | type sendDocumentResponse struct { 208 | response 209 | Result *Message `json:"result,omitempty"` 210 | } 211 | 212 | func (r *sendDocumentResponse) GetMessage() *Message { 213 | return r.Result 214 | } 215 | 216 | func (b *bot) SendDocument(ctx context.Context, options ...MethodOption) (SendDocumentResponse, error) { 217 | var res sendDocumentResponse 218 | 219 | err := b.doRequest(ctx, "sendDocument", &res, options...) 220 | if err != nil { 221 | return nil, err 222 | } 223 | 224 | return &res, nil 225 | } 226 | 227 | // SendVideoResponse interface 228 | type SendVideoResponse interface { 229 | Response 230 | GetMessage() *Message 231 | } 232 | 233 | type sendVideoResponse struct { 234 | response 235 | Result *Message `json:"result,omitempty"` 236 | } 237 | 238 | func (r *sendVideoResponse) GetMessage() *Message { 239 | return r.Result 240 | } 241 | 242 | func (b *bot) SendVideo(ctx context.Context, options ...MethodOption) (SendVideoResponse, error) { 243 | var res sendVideoResponse 244 | 245 | err := b.doRequest(ctx, "sendVideo", &res, options...) 246 | if err != nil { 247 | return nil, err 248 | } 249 | 250 | return &res, nil 251 | } 252 | 253 | // SendAnimationResponse interface 254 | type SendAnimationResponse interface { 255 | Response 256 | GetMessage() *Message 257 | } 258 | 259 | type sendAnimationResponse struct { 260 | response 261 | Result *Message `json:"result,omitempty"` 262 | } 263 | 264 | func (r *sendAnimationResponse) GetMessage() *Message { 265 | return r.Result 266 | } 267 | 268 | func (b *bot) SendAnimation(ctx context.Context, options ...MethodOption) (SendAnimationResponse, error) { 269 | var res sendAnimationResponse 270 | 271 | err := b.doRequest(ctx, "sendAnimation", &res, options...) 272 | if err != nil { 273 | return nil, err 274 | } 275 | 276 | return &res, nil 277 | } 278 | 279 | // SendVoiceResponse interface 280 | type SendVoiceResponse interface { 281 | Response 282 | GetMessage() *Message 283 | } 284 | 285 | type sendVoiceResponse struct { 286 | response 287 | Result *Message `json:"result,omitempty"` 288 | } 289 | 290 | func (r *sendVoiceResponse) GetMessage() *Message { 291 | return r.Result 292 | } 293 | 294 | func (b *bot) SendVoice(ctx context.Context, options ...MethodOption) (SendVoiceResponse, error) { 295 | var res sendVoiceResponse 296 | 297 | err := b.doRequest(ctx, "sendVoice", &res, options...) 298 | if err != nil { 299 | return nil, err 300 | } 301 | 302 | return &res, nil 303 | } 304 | 305 | // SendVideoNoteResponse interface 306 | type SendVideoNoteResponse interface { 307 | Response 308 | GetMessage() *Message 309 | } 310 | 311 | type sendVideoNoteResponse struct { 312 | response 313 | Result *Message `json:"result,omitempty"` 314 | } 315 | 316 | func (r *sendVideoNoteResponse) GetMessage() *Message { 317 | return r.Result 318 | } 319 | 320 | func (b *bot) SendVideoNote(ctx context.Context, options ...MethodOption) (SendVideoNoteResponse, error) { 321 | var res sendVideoNoteResponse 322 | 323 | err := b.doRequest(ctx, "sendVideoNote", &res, options...) 324 | if err != nil { 325 | return nil, err 326 | } 327 | 328 | return &res, nil 329 | } 330 | 331 | // SendMediaGroupResponse interface 332 | type SendMediaGroupResponse interface { 333 | Response 334 | GetMessage() *Message 335 | } 336 | 337 | type sendMediaGroupResponse struct { 338 | response 339 | Result *Message `json:"result,omitempty"` 340 | } 341 | 342 | func (r *sendMediaGroupResponse) GetMessage() *Message { 343 | return r.Result 344 | } 345 | 346 | func (b *bot) SendMediaGroup(ctx context.Context, options ...MethodOption) (SendMediaGroupResponse, error) { 347 | var res sendMediaGroupResponse 348 | 349 | err := b.doRequest(ctx, "sendMediaGroup", &res, options...) 350 | if err != nil { 351 | return nil, err 352 | } 353 | 354 | return &res, nil 355 | } 356 | 357 | // SendLocationResponse interface 358 | type SendLocationResponse interface { 359 | Response 360 | GetMessage() *Message 361 | } 362 | 363 | type sendLocationResponse struct { 364 | response 365 | Result *Message `json:"result,omitempty"` 366 | } 367 | 368 | func (r *sendLocationResponse) GetMessage() *Message { 369 | return r.Result 370 | } 371 | 372 | func (b *bot) SendLocation(ctx context.Context, options ...MethodOption) (SendLocationResponse, error) { 373 | var res sendLocationResponse 374 | 375 | err := b.doRequest(ctx, "sendLocation", &res, options...) 376 | if err != nil { 377 | return nil, err 378 | } 379 | 380 | return &res, nil 381 | } 382 | 383 | // EditMessageLiveLocationResponse interface 384 | type EditMessageLiveLocationResponse interface { 385 | Response 386 | GetEditedMessage() *Message 387 | } 388 | 389 | type editMessageLiveLocationResponse struct { 390 | response 391 | Result *Message `json:"result,omitempty"` 392 | } 393 | 394 | func (r *editMessageLiveLocationResponse) GetEditedMessage() *Message { 395 | return r.Result 396 | } 397 | 398 | func (b *bot) EditMessageLiveLocation(ctx context.Context, options ...MethodOption) (EditMessageLiveLocationResponse, error) { 399 | var res editMessageLiveLocationResponse 400 | 401 | err := b.doRequest(ctx, "editMessageLiveLocation", &res, options...) 402 | if err != nil { 403 | return nil, err 404 | } 405 | 406 | return &res, nil 407 | } 408 | 409 | // StopMessageLiveLocationResponse interface 410 | type StopMessageLiveLocationResponse interface { 411 | Response 412 | GetMessage() *Message 413 | } 414 | 415 | type stopMessageLiveLocationResponse struct { 416 | response 417 | Result *Message `json:"result,omitempty"` 418 | } 419 | 420 | func (r *stopMessageLiveLocationResponse) GetMessage() *Message { 421 | return r.Result 422 | } 423 | 424 | func (b *bot) StopMessageLiveLocation(ctx context.Context, options ...MethodOption) (StopMessageLiveLocationResponse, error) { 425 | var res stopMessageLiveLocationResponse 426 | 427 | err := b.doRequest(ctx, "stopMessageLiveLocation", &res, options...) 428 | if err != nil { 429 | return nil, err 430 | } 431 | 432 | return &res, nil 433 | } 434 | 435 | // SendVenueResponse interface 436 | type SendVenueResponse interface { 437 | Response 438 | GetMessage() *Message 439 | } 440 | 441 | type sendVenueResponse struct { 442 | response 443 | Result *Message `json:"result,omitempty"` 444 | } 445 | 446 | func (r *sendVenueResponse) GetMessage() *Message { 447 | return r.Result 448 | } 449 | 450 | func (b *bot) SendVenue(ctx context.Context, options ...MethodOption) (SendVenueResponse, error) { 451 | var res sendVenueResponse 452 | 453 | err := b.doRequest(ctx, "sendVenue", &res, options...) 454 | if err != nil { 455 | return nil, err 456 | } 457 | 458 | return &res, nil 459 | } 460 | 461 | // SendContactResponse interface 462 | type SendContactResponse interface { 463 | Response 464 | GetMessage() *Message 465 | } 466 | 467 | type sendContactResponse struct { 468 | response 469 | Result *Message `json:"result,omitempty"` 470 | } 471 | 472 | func (r *sendContactResponse) GetMessage() *Message { 473 | return r.Result 474 | } 475 | 476 | func (b *bot) SendContact(ctx context.Context, options ...MethodOption) (SendContactResponse, error) { 477 | var res sendContactResponse 478 | 479 | err := b.doRequest(ctx, "sendContact", &res, options...) 480 | if err != nil { 481 | return nil, err 482 | } 483 | 484 | return &res, nil 485 | } 486 | 487 | // SendPollResponse interface 488 | type SendPollResponse interface { 489 | Response 490 | GetMessage() *Message 491 | } 492 | 493 | type sendPollResponse struct { 494 | response 495 | Result *Message `json:"result,omitempty"` 496 | } 497 | 498 | func (r *sendPollResponse) GetMessage() *Message { 499 | return r.Result 500 | } 501 | 502 | func (b *bot) SendPoll(ctx context.Context, options ...MethodOption) (SendPollResponse, error) { 503 | var res sendPollResponse 504 | 505 | err := b.doRequest(ctx, "sendPoll", &res, options...) 506 | if err != nil { 507 | return nil, err 508 | } 509 | 510 | return &res, nil 511 | } 512 | 513 | // SendDiceResponse interface 514 | type SendDiceResponse interface { 515 | Response 516 | } 517 | 518 | type sendDiceResponse struct { 519 | response 520 | } 521 | 522 | func (b *bot) SendDice(ctx context.Context, options ...MethodOption) (SendDiceResponse, error) { 523 | var res sendDiceResponse 524 | 525 | err := b.doRequest(ctx, "sendDice", &res, options...) 526 | if err != nil { 527 | return nil, err 528 | } 529 | 530 | return &res, nil 531 | } 532 | 533 | // SendChatActionResponse interface 534 | type SendChatActionResponse interface { 535 | Response 536 | } 537 | 538 | type sendChatActionResponse struct { 539 | response 540 | } 541 | 542 | func (b *bot) SendChatAction(ctx context.Context, options ...MethodOption) (SendChatActionResponse, error) { 543 | var res sendChatActionResponse 544 | 545 | err := b.doRequest(ctx, "sendChatAction", &res, options...) 546 | if err != nil { 547 | return nil, err 548 | } 549 | 550 | return &res, nil 551 | } 552 | 553 | // GetUserProfilePhotosResponse interface 554 | type GetUserProfilePhotosResponse interface { 555 | Response 556 | GetUserProfilePhotos() *UserProfilePhotos 557 | } 558 | 559 | type getUserProfilePhotosResponse struct { 560 | response 561 | Result *UserProfilePhotos `json:"result,omitempty"` 562 | } 563 | 564 | func (r *getUserProfilePhotosResponse) GetUserProfilePhotos() *UserProfilePhotos { 565 | return r.Result 566 | } 567 | 568 | func (b *bot) GetUserProfilePhotos(ctx context.Context, options ...MethodOption) (GetUserProfilePhotosResponse, error) { 569 | var res getUserProfilePhotosResponse 570 | 571 | err := b.doRequest(ctx, "getUserProfilePhotos", &res, options...) 572 | if err != nil { 573 | return nil, err 574 | } 575 | 576 | return &res, nil 577 | } 578 | 579 | // GetFileResponse interface 580 | type GetFileResponse interface { 581 | Response 582 | GetFile() *File 583 | } 584 | 585 | type getFileResponse struct { 586 | response 587 | Result *File `json:"result,omitempty"` 588 | } 589 | 590 | func (r *getFileResponse) GetFile() *File { 591 | return r.Result 592 | } 593 | 594 | func (b *bot) GetFile(ctx context.Context, options ...MethodOption) (GetFileResponse, error) { 595 | var res getFileResponse 596 | 597 | err := b.doRequest(ctx, "getFile", &res, options...) 598 | if err != nil { 599 | return nil, err 600 | } 601 | 602 | return &res, nil 603 | } 604 | 605 | // BanChatMemberResponse interface 606 | type BanChatMemberResponse interface { 607 | Response 608 | } 609 | 610 | type banChatMemberResponse struct { 611 | response 612 | } 613 | 614 | func (b *bot) BanChatMember(ctx context.Context, options ...MethodOption) (BanChatMemberResponse, error) { 615 | var res banChatMemberResponse 616 | 617 | err := b.doRequest(ctx, "banChatMember", &res, options...) 618 | if err != nil { 619 | return nil, err 620 | } 621 | 622 | return &res, nil 623 | } 624 | 625 | // UnbanChatMemberResponse interface 626 | type UnbanChatMemberResponse interface { 627 | Response 628 | } 629 | 630 | type unbanChatMemberResponse struct { 631 | response 632 | } 633 | 634 | func (b *bot) UnbanChatMember(ctx context.Context, options ...MethodOption) (UnbanChatMemberResponse, error) { 635 | var res unbanChatMemberResponse 636 | 637 | err := b.doRequest(ctx, "unbanChatMember", &res, options...) 638 | if err != nil { 639 | return nil, err 640 | } 641 | 642 | return &res, nil 643 | } 644 | 645 | // RestrictChatMemberResponse interface 646 | type RestrictChatMemberResponse interface { 647 | Response 648 | } 649 | 650 | type restrictChatMemberResponse struct { 651 | response 652 | } 653 | 654 | func (b *bot) RestrictChatMember(ctx context.Context, options ...MethodOption) (RestrictChatMemberResponse, error) { 655 | var res restrictChatMemberResponse 656 | 657 | err := b.doRequest(ctx, "restrictChatMember", &res, options...) 658 | if err != nil { 659 | return nil, err 660 | } 661 | 662 | return &res, nil 663 | } 664 | 665 | // PromoteChatMemberResponse interface 666 | type PromoteChatMemberResponse interface { 667 | Response 668 | } 669 | 670 | type promoteChatMemberResponse struct { 671 | response 672 | } 673 | 674 | func (b *bot) PromoteChatMember(ctx context.Context, options ...MethodOption) (PromoteChatMemberResponse, error) { 675 | var res promoteChatMemberResponse 676 | 677 | err := b.doRequest(ctx, "promoteChatMember", &res, options...) 678 | if err != nil { 679 | return nil, err 680 | } 681 | 682 | return &res, nil 683 | } 684 | 685 | // SetChatAdministratorCustomTitleResponse interface 686 | type SetChatAdministratorCustomTitleResponse interface { 687 | Response 688 | } 689 | 690 | type setChatAdministratorCustomTitleResponse struct { 691 | response 692 | } 693 | 694 | func (b *bot) SetChatAdministratorCustomTitle(ctx context.Context, options ...MethodOption) (SetChatAdministratorCustomTitleResponse, error) { 695 | var res setChatAdministratorCustomTitleResponse 696 | 697 | err := b.doRequest(ctx, "setChatAdministratorCustomTitle", &res, options...) 698 | if err != nil { 699 | return nil, err 700 | } 701 | 702 | return &res, nil 703 | } 704 | 705 | // BanChatSenderChatResponse interface 706 | type BanChatSenderChatResponse interface { 707 | Response 708 | } 709 | 710 | type banChatSenderChatResponse struct { 711 | response 712 | } 713 | 714 | func (b *bot) BanChatSenderChat(ctx context.Context, options ...MethodOption) (BanChatSenderChatResponse, error) { 715 | var res banChatSenderChatResponse 716 | 717 | err := b.doRequest(ctx, "banChatSenderChat", &res, options...) 718 | if err != nil { 719 | return nil, err 720 | } 721 | 722 | return &res, nil 723 | } 724 | 725 | // UnbanChatSenderChatResponse interface 726 | type UnbanChatSenderChatResponse interface { 727 | Response 728 | } 729 | 730 | type unbanChatSenderChatResponse struct { 731 | response 732 | } 733 | 734 | func (b *bot) UnbanChatSenderChat(ctx context.Context, options ...MethodOption) (UnbanChatSenderChatResponse, error) { 735 | var res unbanChatSenderChatResponse 736 | 737 | err := b.doRequest(ctx, "unbanChatSenderChat", &res, options...) 738 | if err != nil { 739 | return nil, err 740 | } 741 | 742 | return &res, nil 743 | } 744 | 745 | // SetChatPermissionsResponse interface 746 | type SetChatPermissionsResponse interface { 747 | Response 748 | } 749 | 750 | type setChatPermissionsResponse struct { 751 | response 752 | } 753 | 754 | func (b *bot) SetChatPermissions(ctx context.Context, options ...MethodOption) (SetChatPermissionsResponse, error) { 755 | var res setChatPermissionsResponse 756 | 757 | err := b.doRequest(ctx, "setChatPermissions", &res, options...) 758 | if err != nil { 759 | return nil, err 760 | } 761 | 762 | return &res, nil 763 | } 764 | 765 | // ExportChatInviteLinkResponse interface 766 | type ExportChatInviteLinkResponse interface { 767 | Response 768 | GetNewInviteLink() string 769 | } 770 | 771 | type exportChatInviteLinkResponse struct { 772 | response 773 | Result string `json:"result,omitempty"` 774 | } 775 | 776 | func (r *exportChatInviteLinkResponse) GetNewInviteLink() string { 777 | return r.Result 778 | } 779 | 780 | func (b *bot) ExportChatInviteLink(ctx context.Context, options ...MethodOption) (ExportChatInviteLinkResponse, error) { 781 | var res exportChatInviteLinkResponse 782 | 783 | err := b.doRequest(ctx, "exportChatInviteLink", &res, options...) 784 | if err != nil { 785 | return nil, err 786 | } 787 | 788 | return &res, nil 789 | } 790 | 791 | // CreateChatInviteLinkResponse interface 792 | type CreateChatInviteLinkResponse interface { 793 | Response 794 | GetNewInviteLink() ChatInviteLink 795 | } 796 | 797 | type createChatInviteLinkResponse struct { 798 | response 799 | Result ChatInviteLink `json:"result,omitempty"` 800 | } 801 | 802 | func (r *createChatInviteLinkResponse) GetNewInviteLink() ChatInviteLink { 803 | return r.Result 804 | } 805 | 806 | func (b *bot) CreateChatInviteLink(ctx context.Context, options ...MethodOption) (CreateChatInviteLinkResponse, error) { 807 | var res createChatInviteLinkResponse 808 | 809 | err := b.doRequest(ctx, "createChatInviteLink", &res, options...) 810 | if err != nil { 811 | return nil, err 812 | } 813 | 814 | return &res, nil 815 | } 816 | 817 | // EditChatInviteLinkResponse interface 818 | type EditChatInviteLinkResponse interface { 819 | Response 820 | GetEditedInviteLink() ChatInviteLink 821 | } 822 | 823 | type editChatInviteLinkResponse struct { 824 | response 825 | Result ChatInviteLink `json:"result,omitempty"` 826 | } 827 | 828 | func (r *editChatInviteLinkResponse) GetEditedInviteLink() ChatInviteLink { 829 | return r.Result 830 | } 831 | 832 | func (b *bot) EditChatInviteLink(ctx context.Context, options ...MethodOption) (EditChatInviteLinkResponse, error) { 833 | var res editChatInviteLinkResponse 834 | 835 | err := b.doRequest(ctx, "editChatInviteLink", &res, options...) 836 | if err != nil { 837 | return nil, err 838 | } 839 | 840 | return &res, nil 841 | } 842 | 843 | // RevokeChatInviteLinkResponse interface 844 | type RevokeChatInviteLinkResponse interface { 845 | Response 846 | GetRevokedInviteLink() ChatInviteLink 847 | } 848 | 849 | type revokeChatInviteLinkResponse struct { 850 | response 851 | Result ChatInviteLink `json:"result,omitempty"` 852 | } 853 | 854 | func (r *revokeChatInviteLinkResponse) GetRevokedInviteLink() ChatInviteLink { 855 | return r.Result 856 | } 857 | 858 | func (b *bot) RevokeChatInviteLink(ctx context.Context, options ...MethodOption) (RevokeChatInviteLinkResponse, error) { 859 | var res revokeChatInviteLinkResponse 860 | 861 | err := b.doRequest(ctx, "revokeChatInviteLink", &res, options...) 862 | if err != nil { 863 | return nil, err 864 | } 865 | 866 | return &res, nil 867 | } 868 | 869 | // ApproveChatJoinRequestResponse interface 870 | type ApproveChatJoinRequestResponse interface { 871 | Response 872 | } 873 | 874 | type approveChatJoinRequestResponse struct { 875 | response 876 | } 877 | 878 | func (b *bot) ApproveChatJoinRequest(ctx context.Context, options ...MethodOption) (ApproveChatJoinRequestResponse, error) { 879 | var res approveChatJoinRequestResponse 880 | 881 | err := b.doRequest(ctx, "approveChatJoinRequest", &res, options...) 882 | if err != nil { 883 | return nil, err 884 | } 885 | 886 | return &res, nil 887 | } 888 | 889 | // DeclineChatJoinRequestResponse interface 890 | type DeclineChatJoinRequestResponse interface { 891 | Response 892 | } 893 | 894 | type declineChatJoinRequestResponse struct { 895 | response 896 | } 897 | 898 | func (b *bot) DeclineChatJoinRequest(ctx context.Context, options ...MethodOption) (DeclineChatJoinRequestResponse, error) { 899 | var res declineChatJoinRequestResponse 900 | 901 | err := b.doRequest(ctx, "declineChatJoinRequest", &res, options...) 902 | if err != nil { 903 | return nil, err 904 | } 905 | 906 | return &res, nil 907 | } 908 | 909 | // SetChatPhotoResponse interface 910 | type SetChatPhotoResponse interface { 911 | Response 912 | } 913 | 914 | type setChatPhotoResponse struct { 915 | response 916 | } 917 | 918 | func (b *bot) SetChatPhoto(ctx context.Context, options ...MethodOption) (SetChatPhotoResponse, error) { 919 | var res setChatPhotoResponse 920 | 921 | err := b.doRequest(ctx, "setChatPhoto", &res, options...) 922 | if err != nil { 923 | return nil, err 924 | } 925 | 926 | return &res, nil 927 | } 928 | 929 | // DeleteChatPhotoResponse interface 930 | type DeleteChatPhotoResponse interface { 931 | Response 932 | } 933 | 934 | type deleteChatPhotoResponse struct { 935 | response 936 | } 937 | 938 | func (b *bot) DeleteChatPhoto(ctx context.Context, options ...MethodOption) (DeleteChatPhotoResponse, error) { 939 | var res deleteChatPhotoResponse 940 | 941 | err := b.doRequest(ctx, "deleteChatPhoto", &res, options...) 942 | if err != nil { 943 | return nil, err 944 | } 945 | 946 | return &res, nil 947 | } 948 | 949 | // SetChatTitleResponse interface 950 | type SetChatTitleResponse interface { 951 | Response 952 | } 953 | 954 | type setChatTitleResponse struct { 955 | response 956 | } 957 | 958 | func (b *bot) SetChatTitle(ctx context.Context, options ...MethodOption) (SetChatTitleResponse, error) { 959 | var res setChatTitleResponse 960 | 961 | err := b.doRequest(ctx, "setChatTitle", &res, options...) 962 | if err != nil { 963 | return nil, err 964 | } 965 | 966 | return &res, nil 967 | } 968 | 969 | // SetChatDescriptionResponse interface 970 | type SetChatDescriptionResponse interface { 971 | Response 972 | } 973 | 974 | type setChatDescriptionResponse struct { 975 | response 976 | } 977 | 978 | func (b *bot) SetChatDescription(ctx context.Context, options ...MethodOption) (SetChatDescriptionResponse, error) { 979 | var res setChatDescriptionResponse 980 | 981 | err := b.doRequest(ctx, "setChatDescription", &res, options...) 982 | if err != nil { 983 | return nil, err 984 | } 985 | 986 | return &res, nil 987 | } 988 | 989 | // PinChatMessageResponse interface 990 | type PinChatMessageResponse interface { 991 | Response 992 | } 993 | 994 | type pinChatMessageResponse struct { 995 | response 996 | } 997 | 998 | func (b *bot) PinChatMessage(ctx context.Context, options ...MethodOption) (PinChatMessageResponse, error) { 999 | var res pinChatMessageResponse 1000 | 1001 | err := b.doRequest(ctx, "pinChatMessage", &res, options...) 1002 | if err != nil { 1003 | return nil, err 1004 | } 1005 | 1006 | return &res, nil 1007 | } 1008 | 1009 | // UnpinChatMessageResponse interface 1010 | type UnpinChatMessageResponse interface { 1011 | Response 1012 | } 1013 | 1014 | type unpinChatMessageResponse struct { 1015 | response 1016 | } 1017 | 1018 | func (b *bot) UnpinChatMessage(ctx context.Context, options ...MethodOption) (UnpinChatMessageResponse, error) { 1019 | var res unpinChatMessageResponse 1020 | 1021 | err := b.doRequest(ctx, "unpinChatMessage", &res, options...) 1022 | if err != nil { 1023 | return nil, err 1024 | } 1025 | 1026 | return &res, nil 1027 | } 1028 | 1029 | // UnpinAllChatMessagesResponse interface 1030 | type UnpinAllChatMessagesResponse interface { 1031 | Response 1032 | } 1033 | 1034 | type unpinAllChatMessagesResponse struct { 1035 | response 1036 | } 1037 | 1038 | func (b *bot) UnpinAllChatMessages(ctx context.Context, options ...MethodOption) (UnpinAllChatMessagesResponse, error) { 1039 | var res unpinAllChatMessagesResponse 1040 | 1041 | err := b.doRequest(ctx, "unpinAllChatMessages", &res, options...) 1042 | if err != nil { 1043 | return nil, err 1044 | } 1045 | 1046 | return &res, nil 1047 | } 1048 | 1049 | // LeaveChatResponse interface 1050 | type LeaveChatResponse interface { 1051 | Response 1052 | } 1053 | 1054 | type leaveChatResponse struct { 1055 | response 1056 | } 1057 | 1058 | func (b *bot) LeaveChat(ctx context.Context, options ...MethodOption) (LeaveChatResponse, error) { 1059 | var res leaveChatResponse 1060 | 1061 | err := b.doRequest(ctx, "leaveChat", &res, options...) 1062 | if err != nil { 1063 | return nil, err 1064 | } 1065 | 1066 | return &res, nil 1067 | } 1068 | 1069 | // GetChatResponse interface 1070 | type GetChatResponse interface { 1071 | Response 1072 | GetChat() *Chat 1073 | } 1074 | 1075 | type getChatResponse struct { 1076 | response 1077 | Result *Chat `json:"result,omitempty"` 1078 | } 1079 | 1080 | func (r *getChatResponse) GetChat() *Chat { 1081 | return r.Result 1082 | } 1083 | 1084 | func (b *bot) GetChat(ctx context.Context, options ...MethodOption) (GetChatResponse, error) { 1085 | var res getChatResponse 1086 | 1087 | err := b.doRequest(ctx, "getChat", &res, options...) 1088 | if err != nil { 1089 | return nil, err 1090 | } 1091 | 1092 | return &res, nil 1093 | } 1094 | 1095 | // GetChatAdministratorsResponse interface 1096 | type GetChatAdministratorsResponse interface { 1097 | Response 1098 | GetChatAdministrators() []ChatMember 1099 | } 1100 | 1101 | type getChatAdministratorsResponse struct { 1102 | response 1103 | Result []ChatMember `json:"result,omitempty"` 1104 | } 1105 | 1106 | func (r *getChatAdministratorsResponse) GetChatAdministrators() []ChatMember { 1107 | return r.Result 1108 | } 1109 | 1110 | func (b *bot) GetChatAdministrators(ctx context.Context, options ...MethodOption) (GetChatAdministratorsResponse, error) { 1111 | var res getChatAdministratorsResponse 1112 | 1113 | err := b.doRequest(ctx, "getChatAdministrators", &res, options...) 1114 | if err != nil { 1115 | return nil, err 1116 | } 1117 | 1118 | return &res, nil 1119 | } 1120 | 1121 | // GetChatMemberCountResponse interface 1122 | type GetChatMemberCountResponse interface { 1123 | Response 1124 | GetChatMemberCount() int 1125 | } 1126 | 1127 | type getChatMemberCountResponse struct { 1128 | response 1129 | Result int `json:"result,omitempty"` 1130 | } 1131 | 1132 | func (r *getChatMemberCountResponse) GetChatMemberCount() int { 1133 | return r.Result 1134 | } 1135 | 1136 | func (b *bot) GetChatMemberCount(ctx context.Context, options ...MethodOption) (GetChatMemberCountResponse, error) { 1137 | var res getChatMemberCountResponse 1138 | 1139 | err := b.doRequest(ctx, "getChatMemberCount", &res, options...) 1140 | if err != nil { 1141 | return nil, err 1142 | } 1143 | 1144 | return &res, nil 1145 | } 1146 | 1147 | // GetChatMemberResponse interface 1148 | type GetChatMemberResponse interface { 1149 | Response 1150 | GetChatMember() *ChatMember 1151 | } 1152 | 1153 | type getChatMemberResponse struct { 1154 | response 1155 | Result *ChatMember `json:"result,omitempty"` 1156 | } 1157 | 1158 | func (r *getChatMemberResponse) GetChatMember() *ChatMember { 1159 | return r.Result 1160 | } 1161 | 1162 | func (b *bot) GetChatMember(ctx context.Context, options ...MethodOption) (GetChatMemberResponse, error) { 1163 | var res getChatMemberResponse 1164 | 1165 | err := b.doRequest(ctx, "getChatMember", &res, options...) 1166 | if err != nil { 1167 | return nil, err 1168 | } 1169 | 1170 | return &res, nil 1171 | } 1172 | 1173 | // SetChatStickerSetResponse interface 1174 | type SetChatStickerSetResponse interface { 1175 | Response 1176 | } 1177 | 1178 | type setChatStickerSetResponse struct { 1179 | response 1180 | } 1181 | 1182 | func (b *bot) SetChatStickerSet(ctx context.Context, options ...MethodOption) (SetChatStickerSetResponse, error) { 1183 | var res setChatStickerSetResponse 1184 | 1185 | err := b.doRequest(ctx, "setChatStickerSet", &res, options...) 1186 | if err != nil { 1187 | return nil, err 1188 | } 1189 | 1190 | return &res, nil 1191 | } 1192 | 1193 | // DeleteChatStickerSetResponse interface 1194 | type DeleteChatStickerSetResponse interface { 1195 | Response 1196 | } 1197 | 1198 | type deleteChatStickerSetResponse struct { 1199 | response 1200 | } 1201 | 1202 | func (b *bot) DeleteChatStickerSet(ctx context.Context, options ...MethodOption) (DeleteChatStickerSetResponse, error) { 1203 | var res deleteChatStickerSetResponse 1204 | 1205 | err := b.doRequest(ctx, "deleteChatStickerSet", &res, options...) 1206 | if err != nil { 1207 | return nil, err 1208 | } 1209 | 1210 | return &res, nil 1211 | } 1212 | 1213 | // AnswerCallbackQueryResponse interface 1214 | type AnswerCallbackQueryResponse interface { 1215 | Response 1216 | } 1217 | 1218 | type answerCallbackQueryResponse struct { 1219 | response 1220 | } 1221 | 1222 | func (b *bot) AnswerCallbackQuery(ctx context.Context, options ...MethodOption) (AnswerCallbackQueryResponse, error) { 1223 | var res answerCallbackQueryResponse 1224 | 1225 | err := b.doRequest(ctx, "answerCallbackQuery", &res, options...) 1226 | if err != nil { 1227 | return nil, err 1228 | } 1229 | 1230 | return &res, nil 1231 | } 1232 | 1233 | // SetMyCommandsResponse interface 1234 | type SetMyCommandsResponse interface { 1235 | Response 1236 | } 1237 | 1238 | type setMyCommandsResponse struct { 1239 | response 1240 | } 1241 | 1242 | func (b *bot) SetMyCommands(ctx context.Context, options ...MethodOption) (SetMyCommandsResponse, error) { 1243 | var res setMyCommandsResponse 1244 | 1245 | err := b.doRequest(ctx, "setMyCommands", &res, options...) 1246 | if err != nil { 1247 | return nil, err 1248 | } 1249 | 1250 | return &res, nil 1251 | } 1252 | 1253 | // DeleteMyCommandsResponse interface 1254 | type DeleteMyCommandsResponse interface { 1255 | Response 1256 | } 1257 | 1258 | type deleteMyCommandsResponse struct { 1259 | response 1260 | } 1261 | 1262 | func (b *bot) DeleteMyCommands(ctx context.Context, options ...MethodOption) (DeleteMyCommandsResponse, error) { 1263 | var res deleteMyCommandsResponse 1264 | 1265 | err := b.doRequest(ctx, "deleteMyCommands", &res, options...) 1266 | if err != nil { 1267 | return nil, err 1268 | } 1269 | 1270 | return &res, nil 1271 | } 1272 | 1273 | // GetMyCommandsResponse interface 1274 | type GetMyCommandsResponse interface { 1275 | Response 1276 | GetCommands() []BotCommand 1277 | } 1278 | 1279 | type getMyCommandsResponse struct { 1280 | response 1281 | Result []BotCommand `json:"result,omitempty"` 1282 | } 1283 | 1284 | func (r *getMyCommandsResponse) GetCommands() []BotCommand { 1285 | return r.Result 1286 | } 1287 | 1288 | func (b *bot) GetMyCommands(ctx context.Context) (GetMyCommandsResponse, error) { 1289 | var res getMyCommandsResponse 1290 | 1291 | err := b.doRequest(ctx, "getMyCommands", &res) 1292 | if err != nil { 1293 | return nil, err 1294 | } 1295 | 1296 | return &res, nil 1297 | } 1298 | 1299 | // SetChatMenuButtonResponse interface 1300 | type SetChatMenuButtonResponse interface { 1301 | Response 1302 | } 1303 | 1304 | type setChatMenuButtonResponse struct { 1305 | response 1306 | } 1307 | 1308 | func (b *bot) SetChatMenuButton(ctx context.Context) (SetChatMenuButtonResponse, error) { 1309 | var res setChatMenuButtonResponse 1310 | 1311 | err := b.doRequest(ctx, "setChatMenuButton", &res) 1312 | if err != nil { 1313 | return nil, err 1314 | } 1315 | 1316 | return &res, nil 1317 | } 1318 | 1319 | // GetChatMenuButtonResponse interface 1320 | type GetChatMenuButtonResponse interface { 1321 | Response 1322 | GetMenuButton() *MenuButton 1323 | } 1324 | 1325 | type getChatMenuButtonResponse struct { 1326 | response 1327 | Result *MenuButton `json:"result,omitempty"` 1328 | } 1329 | 1330 | func (r *getChatMenuButtonResponse) GetMenuButton() *MenuButton { 1331 | return r.Result 1332 | } 1333 | 1334 | func (b *bot) GetChatMenuButton(ctx context.Context) (GetChatMenuButtonResponse, error) { 1335 | var res getChatMenuButtonResponse 1336 | 1337 | err := b.doRequest(ctx, "getChatMenuButton", &res) 1338 | if err != nil { 1339 | return nil, err 1340 | } 1341 | 1342 | return &res, nil 1343 | } 1344 | 1345 | // SetMyDefaultAdministratorRightsResponse interface 1346 | type SetMyDefaultAdministratorRightsResponse interface { 1347 | Response 1348 | } 1349 | 1350 | type setMyDefaultAdministratorRightsResponse struct { 1351 | response 1352 | } 1353 | 1354 | func (b *bot) SetMyDefaultAdministratorRights(ctx context.Context) (SetMyDefaultAdministratorRightsResponse, error) { 1355 | var res setMyDefaultAdministratorRightsResponse 1356 | 1357 | err := b.doRequest(ctx, "setMyDefaultAdministratorRights", &res) 1358 | if err != nil { 1359 | return nil, err 1360 | } 1361 | 1362 | return &res, nil 1363 | } 1364 | 1365 | // GetMyDefaultAdministratorRightsResponse interface 1366 | type GetMyDefaultAdministratorRightsResponse interface { 1367 | Response 1368 | GetChatAdministratorRights() *ChatAdministratorRights 1369 | } 1370 | 1371 | type getMyDefaultAdministratorRightsResponse struct { 1372 | response 1373 | Result *ChatAdministratorRights `json:"result,omitempty"` 1374 | } 1375 | 1376 | func (r *getMyDefaultAdministratorRightsResponse) GetChatAdministratorRights() *ChatAdministratorRights { 1377 | return r.Result 1378 | } 1379 | 1380 | func (b *bot) GetMyDefaultAdministratorRights(ctx context.Context) (GetMyDefaultAdministratorRightsResponse, error) { 1381 | var res getMyDefaultAdministratorRightsResponse 1382 | 1383 | err := b.doRequest(ctx, "getMyDefaultAdministratorRights", &res) 1384 | if err != nil { 1385 | return nil, err 1386 | } 1387 | 1388 | return &res, nil 1389 | } 1390 | -------------------------------------------------------------------------------- /available-types.go: -------------------------------------------------------------------------------- 1 | package telegram 2 | 3 | import "io" 4 | 5 | // User struct. 6 | type User struct { 7 | ID int64 `json:"id"` 8 | IsBot bool `json:"is_bot"` 9 | FirstName string `json:"first_name"` 10 | LastName *string `json:"last_name,omitempty"` 11 | Username *string `json:"username,omitempty"` 12 | LanguageCode *string `json:"language_code,omitempty"` 13 | CanJoinGroups *bool `json:"can_join_groups,omitempty"` 14 | CanReadAllGroupMessages *bool `json:"can_read_all_group_messages,omitempty"` 15 | SupportsInlineQueries *bool `json:"supports_inline_queries,omitempty"` 16 | } 17 | 18 | // Chat struct. 19 | type Chat struct { 20 | ID int64 `json:"id"` 21 | Type ChatType `json:"type"` 22 | Title *string `json:"title,omitempty"` 23 | Username *string `json:"username,omitempty"` 24 | FirstName *string `json:"first_name,omitempty"` 25 | LastName *string `json:"last_name,omitempty"` 26 | Photo *ChatPhoto `json:"photo,omitempty"` 27 | Bio *string `json:"bio,omitempty"` 28 | HasPrivateForwards *bool `json:"has_private_forwards,omitempty"` 29 | Description *string `json:"description,omitempty"` 30 | InviteLink *string `json:"invite_link,omitempty"` 31 | PinnedMessage *Message `json:"pinned_message,omitempty"` 32 | Permissions *ChatPermissions `json:"permissions,omitempty"` 33 | SlowModeDelay *int `json:"slow_mode_delay,omitempty"` 34 | MessageAutoDeleteTime *int `json:"message_auto_delete_time,omitempty"` 35 | HasProtectedContent *bool `json:"has_protected_content,omitempty"` 36 | StickerSetName *string `json:"sticker_set_name,omitempty"` 37 | CanSetStickerSet *bool `json:"can_set_sticker_set,omitempty"` 38 | LinkedChatID *int64 `json:"linked_chat_id,omitempty"` 39 | Location *ChatLocation `json:"location,omitempty"` 40 | } 41 | 42 | // Message struct. 43 | type Message struct { 44 | MessageID int `json:"message_id"` 45 | From *User `json:"from,omitempty"` 46 | SenderChat *Chat `json:"sender_chat,omitempty"` 47 | Date int `json:"date"` 48 | Chat Chat `json:"chat"` 49 | ForwardFrom *User `json:"forward_from,omitempty"` 50 | ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` 51 | ForwardFromMessageID *int `json:"forward_from_message_id,omitempty"` 52 | ForwardSignature *string `json:"forward_signature,omitempty"` 53 | ForwardSenderName *string `json:"forward_sender_name,omitempty"` 54 | ForwardDate *int `json:"forward_date,omitempty"` 55 | IsAutomaticForward *bool `json:"is_automatic_forward,omitempty"` 56 | ReplyToMessage *Message `json:"reply_to_message,omitempty"` 57 | ViaBot *User `json:"via_bot,omitempty"` 58 | EditDate *int `json:"edit_date,omitempty"` 59 | HasProtectedContent *bool `json:"has_protected_content,omitempty"` 60 | MediaGroupID *string `json:"media_group_id,omitempty"` 61 | AuthorSignature *string `json:"author_signature,omitempty"` 62 | Text *string `json:"text,omitempty"` 63 | Entities []MessageEntity `json:"entities,omitempty"` 64 | Animation *Animation `json:"animation,omitempty"` 65 | Audio *Audio `json:"audio,omitempty"` 66 | Document *Document `json:"document,omitempty"` 67 | Photo []PhotoSize `json:"photo,omitempty"` 68 | Sticker *Sticker `json:"sticker,omitempty"` 69 | Video *Video `json:"video,omitempty"` 70 | VideoNote *VideoNote `json:"video_note,omitempty"` 71 | Voice *Voice `json:"voice,omitempty"` 72 | Caption *string `json:"caption,omitempty"` 73 | CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` 74 | Contact *Contact `json:"contact,omitempty"` 75 | Dice *Dice `json:"dice,omitempty"` 76 | Game *Game `json:"game,omitempty"` 77 | Poll *Poll `json:"poll,omitempty"` 78 | Venue *Venue `json:"venue,omitempty"` 79 | Location *Location `json:"location,omitempty"` 80 | NewChatMembers []User `json:"new_chat_members,omitempty"` 81 | LeftChatMember *User `json:"left_chat_member,omitempty"` 82 | NewChatTitle *string `json:"new_chat_title,omitempty"` 83 | NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"` 84 | DeleteChatPhoto *bool `json:"delete_chat_photo,omitempty"` 85 | GroupChatCreated *bool `json:"group_chat_created,omitempty"` 86 | SupergroupChatCreated *bool `json:"supergroup_chat_created,omitempty"` 87 | ChannelChatCreated *bool `json:"channel_chat_created,omitempty"` 88 | MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed,omitempty"` 89 | MigrateToChatID *int64 `json:"migrate_to_chat_id,omitempty"` 90 | MigrateFromChatID *int64 `json:"migrate_from_chat_id,omitempty"` 91 | PinnedMessage *Message `json:"pinned_message,omitempty"` 92 | Invoice *Invoice `json:"invoice,omitempty"` 93 | SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` 94 | ConnectedWebsite *string `json:"connected_website,omitempty"` 95 | PassportData *PassportData `json:"passport_data,omitempty"` 96 | ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered,omitempty"` 97 | VoiceChatScheduled *VoiceChatScheduled `json:"voice_chat_scheduled,omitempty"` // Deprecated 98 | VideoChatScheduled *VideoChatScheduled `json:"video_chat_scheduled,omitempty"` 99 | VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started,omitempty"` // Deprecated 100 | VideoChatStarted *VideoChatStarted `json:"video_chat_started,omitempty"` 101 | VoiceChatEnded *VoiceChatEnded `json:"voice_chat_ended,omitempty"` // Deprecated 102 | VideoChatEnded *VideoChatEnded `json:"video_chat_ended,omitempty"` 103 | VoiceChatParticipantsInvited *VoiceChatParticipantsInvited `json:"voice_chat_participants_invited,omitempty"` // Deprecated 104 | VideoChatParticipantsInvited *VideoChatParticipantsInvited `json:"video_chat_participants_invited,omitempty"` 105 | WebAppData *WebAppData `json:"web_app_data,omitempty"` // Optional. Service message: data sent by a Web App 106 | ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` 107 | } 108 | 109 | // MessageID struct. 110 | type MessageID struct { 111 | MessageID int `json:"message_id"` 112 | } 113 | 114 | type MessageEntityType string 115 | 116 | const ( 117 | MessageEntityTypeMention MessageEntityType = "mention" 118 | MessageEntityTypeHashtag MessageEntityType = "hashtag" 119 | MessageEntityTypeCashtag MessageEntityType = "cashtag" 120 | MessageEntityTypeBotCommand MessageEntityType = "bot_command" 121 | MessageEntityTypeURL MessageEntityType = "url" 122 | MessageEntityTypeEmail MessageEntityType = "email" 123 | MessageEntityTypePhoneNumber MessageEntityType = "phone_number" 124 | MessageEntityTypeBold MessageEntityType = "bold" 125 | MessageEntityTypeItalic MessageEntityType = "italic" 126 | MessageEntityTypeUnderline MessageEntityType = "underline" 127 | MessageEntityTypeStrikethrough MessageEntityType = "strikethrough" 128 | MessageEntityTypeCode MessageEntityType = "code" 129 | MessageEntityTypePre MessageEntityType = "pre" 130 | MessageEntityTypeTextLink MessageEntityType = "text_link" 131 | MessageEntityTypeTextMention MessageEntityType = "text_mention" 132 | MessageEntityTypeSpoiler MessageEntityType = "spoiler" 133 | ) 134 | 135 | // MessageEntity struct. 136 | type MessageEntity struct { 137 | Type MessageEntityType `json:"type"` 138 | Offset int `json:"offset"` 139 | Length int `json:"length"` 140 | URL *string `json:"url,omitempty"` 141 | User *User `json:"user,omitempty"` 142 | Language string `json:"language,omitempty"` 143 | } 144 | 145 | // PhotoSize struct. 146 | type PhotoSize struct { 147 | FileID string `json:"file_id"` 148 | FileUniqueID string `json:"file_unique_id"` 149 | Width int `json:"width"` 150 | Height int `json:"height"` 151 | FileSize *int `json:"file_size,omitempty"` 152 | } 153 | 154 | // Animation struct. 155 | type Animation struct { 156 | FileID string `json:"file_id"` 157 | FileUniqueID string `json:"file_unique_id"` 158 | Width int `json:"width"` 159 | Height int `json:"height"` 160 | Duration int `json:"duration"` 161 | Thumb *PhotoSize `json:"thumb,omitempty"` 162 | Filename *string `json:"filename,omitempty"` 163 | MimeType *string `json:"mime_type,omitempty"` 164 | FileSize *int `json:"file_size,omitempty"` 165 | } 166 | 167 | // Audio struct. 168 | type Audio struct { 169 | FileID string `json:"file_id"` 170 | FileUniqueID string `json:"file_unique_id"` 171 | Duration int `json:"duration"` 172 | Performer *string `json:"performer,omitempty"` 173 | Title *string `json:"title,omitempty"` 174 | FileName *string `json:"file_name,omitempty"` 175 | MimeType *string `json:"mime_type,omitempty"` 176 | FileSize *int `json:"file_size,omitempty"` 177 | Thumb *PhotoSize `json:"thumb,omitempty"` 178 | } 179 | 180 | // Document struct 181 | type Document struct { 182 | FileID string `json:"file_id"` 183 | FileUniqueID string `json:"file_unique_id"` 184 | Thumb *PhotoSize `json:"thumb,omitempty"` 185 | FileName *string `json:"file_name,omitempty"` 186 | MimeType *string `json:"mime_type,omitempty"` 187 | FileSize *int `json:"file_size,omitempty"` 188 | } 189 | 190 | // Video struct 191 | type Video struct { 192 | FileID string `json:"file_id"` 193 | FileUniqueID string `json:"file_unique_id"` 194 | Width int `json:"width"` 195 | Height int `json:"height"` 196 | Duration int `json:"duration"` 197 | Thumb *PhotoSize `json:"thumb,omitempty"` 198 | FileName *string `json:"file_name,omitempty"` 199 | MimeType *string `json:"mime_type,omitempty"` 200 | FileSize *int `json:"file_size,omitempty"` 201 | } 202 | 203 | // Voice struct 204 | type Voice struct { 205 | FileID string `json:"file_id"` 206 | FileUniqueID string `json:"file_unique_id"` 207 | Duration int `json:"duration"` 208 | MimeType *string `json:"mime_type,omitempty"` 209 | FileSize *int `json:"file_size,omitempty"` 210 | } 211 | 212 | // VideoNote struct 213 | type VideoNote struct { 214 | FileID string `json:"file_id"` 215 | FileUniqueID string `json:"file_unique_id"` 216 | Length int `json:"length"` 217 | Duration int `json:"duration"` 218 | Thumbs *PhotoSize `json:"thumbs,omitempty"` 219 | FileSize *int `json:"file_size,omitempty"` 220 | } 221 | 222 | // Contact struct 223 | type Contact struct { 224 | PhoneNumber string `json:"phone_number"` 225 | FirstName string `json:"first_name"` 226 | LastName *string `json:"last_name,omitempty"` 227 | UserID *int64 `json:"user_id,omitempty"` 228 | VCard *string `json:"vcard,omitempty"` 229 | } 230 | 231 | // Dice struct 232 | type Dice struct { 233 | Emoji string `json:"emoji"` 234 | Value int `json:"value"` 235 | } 236 | 237 | // PollOption struct 238 | type PollOption struct { 239 | Text string `json:"text"` 240 | VoterCount int `json:"voter_count"` 241 | } 242 | 243 | // PollAnswer struct 244 | type PollAnswer struct { 245 | PollID string `json:"poll_id"` 246 | User User `json:"user"` 247 | OptionIDs []int `json:"option_ids"` 248 | } 249 | 250 | // Poll struct 251 | type Poll struct { 252 | ID string `json:"id"` 253 | Question string `json:"question"` 254 | Options []PollOption `json:"options"` 255 | TotalVoterCount int `json:"total_voter_count"` 256 | IsClosed bool `json:"is_closed"` 257 | IsAnonymous bool `json:"is_anonymous"` 258 | Type string `json:"type"` 259 | AllowsMultipleAnswers bool `json:"allows_multiple_answers"` 260 | CorrectOptionID *int `json:"correct_option_id,omitempty"` 261 | Explanation *string `json:"explanation,omitempty"` 262 | ExplanationEntities []MessageEntity `json:"explanation_entities,omitempty"` 263 | OpenPeriod *int `json:"open_period,omitempty"` 264 | CloseDate *int `json:"close_date,omitempty"` 265 | } 266 | 267 | // Location struct 268 | type Location struct { 269 | Longitude float32 `json:"longitude"` 270 | Latitude float32 `json:"latitude"` 271 | HorizontalAccuracy *float32 `json:"horizontal_accuracy,omitempty"` 272 | LivePeriod *int `json:"live_period,omitempty"` 273 | Heading *int `json:"heading,omitempty"` 274 | ProximityAlertRadius *int `json:"proximity_alert_radius,omitempty"` 275 | } 276 | 277 | // Venue struct 278 | type Venue struct { 279 | Location Location `json:"location"` 280 | Title string `json:"title"` 281 | Address string `json:"address"` 282 | FoursquareID *string `json:"foursquare_id,omitempty"` 283 | FoursquareType *string `json:"foursquare_type,omitempty"` 284 | GooglePlaceID *string `json:"google_place_id,omitempty"` 285 | GooglePlaceType *string `json:"google_place_type,omitempty"` 286 | } 287 | 288 | // WebAppData describes data sent from a Web App to the bot. 289 | type WebAppData struct { 290 | Data string `json:"data"` // The data. Be aware that a bad client can send arbitrary data in this field. 291 | 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. 292 | } 293 | 294 | // ProximityAlertTriggered struct 295 | type ProximityAlertTriggered struct { 296 | Traveler User `json:"traveler"` 297 | Watcher User `json:"watcher"` 298 | Distance int `json:"distance"` 299 | } 300 | 301 | // MessageAutoDeleteTimerChanged struct 302 | type MessageAutoDeleteTimerChanged struct { 303 | MessageAutoDeleteTime int `json:"message_auto_delete_time"` 304 | } 305 | 306 | // VoiceChatScheduled represents a service message about a voice chat scheduled in the chat. 307 | // Deprecated 308 | type VoiceChatScheduled struct { 309 | StartDate int `json:"start_date"` // Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator 310 | } 311 | 312 | // VideoChatScheduled represents a service message about a voice chat scheduled in the chat. 313 | type VideoChatScheduled struct { 314 | StartDate int `json:"start_date"` // Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator 315 | } 316 | 317 | // VoiceChatStarted struct 318 | // Deprecated 319 | type VoiceChatStarted struct{} 320 | 321 | // VideoChatStarted struct 322 | type VideoChatStarted struct{} 323 | 324 | // VoiceChatEnded struct 325 | // Deprecated 326 | type VoiceChatEnded struct { 327 | Duration int `json:"duration"` // Voice chat duration; in seconds 328 | } 329 | 330 | // VideoChatEnded struct 331 | type VideoChatEnded struct { 332 | Duration int `json:"duration"` // Voice chat duration; in seconds 333 | } 334 | 335 | // VoiceChatParticipantsInvited struct 336 | // Deprecated 337 | type VoiceChatParticipantsInvited struct { 338 | Users *[]User `json:"users,omitempty"` 339 | } 340 | 341 | // VideoChatParticipantsInvited struct 342 | type VideoChatParticipantsInvited struct { 343 | Users *[]User `json:"users,omitempty"` 344 | } 345 | 346 | // UserProfilePhotos struct 347 | type UserProfilePhotos struct { 348 | TotalCount int `json:"total_count"` 349 | Photos [][]PhotoSize `json:"photos"` 350 | } 351 | 352 | // File struct 353 | type File struct { 354 | FileID string `json:"file_id"` 355 | FileUniqueID string `json:"file_unique_id"` 356 | FileSize *int `json:"file_size,omitempty"` 357 | FilePath *string `json:"file_path,omitempty"` 358 | } 359 | 360 | // WebAppInfo struct 361 | type WebAppInfo struct { 362 | URL string `json:"url"` // An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps (https://core.telegram.org/bots/webapps#initializing-web-apps) 363 | } 364 | 365 | // ReplyKeyboardMarkup struct 366 | type ReplyKeyboardMarkup struct { 367 | Keyboard [][]KeyboardButton `json:"keyboard"` // Array of button rows, each represented by an Array of KeyboardButton objects 368 | 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. 369 | 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. 370 | 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 371 | 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. 372 | } 373 | 374 | // KeyboardButton struct 375 | type KeyboardButton struct { 376 | Text string `json:"text"` 377 | RequestContact *bool `json:"request_contact,omitempty"` 378 | RequestLocation *bool `json:"request_location,omitempty"` 379 | RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"` 380 | WebApp *WebAppInfo `json:"web_app,omitempty"` 381 | } 382 | 383 | // KeyboardButtonPollType struct 384 | type KeyboardButtonPollType struct { 385 | Type *string `json:"type,omitempty"` 386 | } 387 | 388 | // ReplyKeyboardRemove struct 389 | type ReplyKeyboardRemove struct { 390 | RemoveKeyboard bool `json:"remove_keyboard"` 391 | Selective *bool `json:"selective,omitempty"` 392 | } 393 | 394 | // InlineKeyboardMarkup struct 395 | type InlineKeyboardMarkup struct { 396 | InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"` 397 | } 398 | 399 | // InlineKeyboardButton struct 400 | type InlineKeyboardButton struct { 401 | Text string `json:"text"` 402 | URL *string `json:"url,omitempty"` 403 | LoginURL *LoginURL `json:"login_url,omitempty"` 404 | CallbackData *string `json:"callback_data,omitempty"` 405 | WebApp *WebAppInfo `json:"web_app,omitempty"` 406 | SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` 407 | SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` 408 | CallbackGame *CallbackGame `json:"callback_game,omitempty"` 409 | Pay *bool `json:"pay,omitempty"` 410 | } 411 | 412 | // LoginURL struct 413 | type LoginURL struct { 414 | URL string `json:"url"` 415 | ForwardText *string `json:"forward_text,omitempty"` 416 | BotUsername *string `json:"bot_username,omitempty"` 417 | RequestWriteAccess *bool `json:"request_write_access,omitempty"` 418 | } 419 | 420 | // CallbackQuery struct 421 | type CallbackQuery struct { 422 | ID string `json:"id"` 423 | From User `json:"from"` 424 | Message *Message `json:"message,omitempty"` 425 | InlineMessageID *string `json:"inline_message_id,omitempty"` 426 | ChatInstance *string `json:"chat_instance,omitempty"` 427 | Data *string `json:"data,omitempty"` 428 | GameShortName *string `json:"game_short_name,omitempty"` 429 | } 430 | 431 | // ForceReply struct 432 | type ForceReply struct { 433 | ForceReply bool `json:"force_reply"` // Shows reply interface to the user, as if they manually selected the bot's message and tapped 'Reply' 434 | 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 435 | 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. 436 | } 437 | 438 | // ChatPhoto struct 439 | type ChatPhoto struct { 440 | SmallFileID string `json:"small_file_id"` 441 | SmallFileUniqueID string `json:"small_file_unique_id"` 442 | BigFileID string `json:"big_file_id"` 443 | BigFileUniqueID string `json:"big_file_unique_id"` 444 | } 445 | 446 | // ChatInviteLink represents an invite link for a chat. 447 | type ChatInviteLink struct { 448 | InviteLink string `json:"invite_link"` 449 | Creator User `json:"creator"` 450 | CreatesJoinRequest User `json:"creates_join_request"` 451 | IsPrimary bool `json:"is_primary"` 452 | IsRevoked bool `json:"is_revoked"` 453 | Name *string `json:"name"` 454 | ExpireDate *int `json:"expire_date,omitempty"` 455 | MemberLimit *int `json:"member_limit,omitempty"` 456 | PendingJoinRequestCount *int `json:"pending_join_request_count,omitempty"` 457 | } 458 | 459 | // ChatAdministratorRights represents the rights of an administrator in a chat. 460 | type ChatAdministratorRights struct { 461 | IsAnonymous bool `json:"is_anonymous"` // True, if the user's presence in the chat is hidden 462 | 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 463 | CanDeleteMessages bool `json:"can_delete_messages"` // True, if the administrator can delete messages of other users 464 | CanManageVideoChats bool `json:"can_manage_video_chats"` // True, if the administrator can manage video chats 465 | CanRestrictMembers bool `json:"can_restrict_members"` // True, if the administrator can restrict, ban or unban chat members 466 | 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 they have promoted, directly or indirectly (promoted by administrators that were appointed by the user) 467 | CanChangeInfo bool `json:"can_change_info"` // True, if the user is allowed to change the chat title, photo and other settings 468 | CanInviteUsers bool `json:"can_invite_users"` // True, if the user is allowed to invite new users to the chat 469 | CanPostMessages bool `json:"can_post_messages"` // Optional. True, if the administrator can post in the channel; channels only 470 | CanEditMessages bool `json:"can_edit_messages"` // Optional. True, if the administrator can edit messages of other users and can pin messages; channels only 471 | CanPinMessages bool `json:"can_pin_messages"` // Optional. True, if the user is allowed to pin messages; groups and supergroups only 472 | CanManageTopics bool `json:"can_manage_topics"` // Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only 473 | } 474 | 475 | // ChatMember contains information about one member of a chat. Currently, the following 6 types of chat members are supported: 476 | // * ChatMemberOwner 477 | // * ChatMemberAdministrator 478 | // * ChatMemberMember 479 | // * ChatMemberRestricted 480 | // * ChatMemberLeft 481 | // * ChatMemberBanned 482 | type ChatMember interface{} 483 | 484 | // ChatMemberOwner represents a chat member that owns the chat and has all administrator privileges. 485 | type ChatMemberOwner struct { 486 | Status string `json:"status"` 487 | User User `json:"user"` 488 | IsAnonymous bool `json:"is_anonymous,omitempty"` 489 | CustomTitle *string `json:"custom_title,omitempty"` 490 | } 491 | 492 | // ChatMemberAdministrator represents a chat member that has some additional privileges. 493 | type ChatMemberAdministrator struct { 494 | Status string `json:"status"` 495 | User User `json:"user"` 496 | CanBeEdited bool `json:"can_be_edited,omitempty"` 497 | IsAnonymous bool `json:"is_anonymous,omitempty"` 498 | CanManageChat bool `json:"can_manage_chat,omitempty"` 499 | CanDeleteMessages bool `json:"can_delete_messages,omitempty"` 500 | CanManageVoiceChats bool `json:"can_manage_voice_chats,omitempty"` // deprecated 501 | CanManageVideoChats bool `json:"can_manage_video_chats,omitempty"` 502 | CanRestrictMembers bool `json:"can_restrict_members,omitempty"` 503 | CanPromoteMembers bool `json:"can_promote_members,omitempty"` 504 | CanChangeInfo bool `json:"can_change_info,omitempty"` 505 | CanInviteUsers bool `json:"can_invite_users,omitempty"` 506 | CanPostMessages *bool `json:"can_post_messages,omitempty"` 507 | CanEditMessages *bool `json:"can_edit_messages,omitempty"` 508 | CanPinMessages *bool `json:"can_pin_messages,omitempty"` 509 | CustomTitle *string `json:"custom_title,omitempty"` 510 | } 511 | 512 | // ChatMemberMember represents a chat member that has no additional privileges or restrictions. 513 | type ChatMemberMember struct { 514 | Status string `json:"status"` 515 | User User `json:"user"` 516 | } 517 | 518 | // ChatMemberRestricted represents a chat member that is under certain restrictions in the chat. Supergroups only. 519 | type ChatMemberRestricted struct { 520 | Status string `json:"status"` 521 | User User `json:"user"` 522 | IsMember bool `json:"is_member,omitempty"` 523 | CanChangeInfo bool `json:"can_change_info,omitempty"` 524 | CanInviteUsers bool `json:"can_invite_users,omitempty"` 525 | CanPinMessages bool `json:"can_pin_messages,omitempty"` 526 | CanSendMessages bool `json:"can_send_messages,omitempty"` 527 | CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` 528 | CanSendPolls bool `json:"can_send_polls,omitempty"` 529 | CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` 530 | CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` 531 | UntilDate int `json:"until_date,omitempty"` 532 | } 533 | 534 | // ChatMemberLeft represents a chat member that isn't currently a member of the chat, but may join it themselves. 535 | type ChatMemberLeft struct { 536 | Status string `json:"status"` 537 | User User `json:"user"` 538 | } 539 | 540 | // ChatMemberBanned represents a chat member that was banned in the chat and can't return to the chat or view chat messages. 541 | type ChatMemberBanned struct { 542 | Status string `json:"status"` 543 | User User `json:"user"` 544 | UntilDate int `json:"until_date,omitempty"` 545 | } 546 | 547 | // ChatMemberUpdated represents changes in the status of a chat member. 548 | type ChatMemberUpdated struct { 549 | Chat Chat `json:"chat"` 550 | From User `json:"from"` 551 | Date int `json:"date"` 552 | OldChatMember ChatMember `json:"old_chat_member"` 553 | NewChatMember ChatMember `json:"new_chat_member"` 554 | InviteLink *ChatInviteLink `json:"invite_link,omitempty"` 555 | } 556 | 557 | // ChatJoinRequest represents a join request sent to a chat. 558 | type ChatJoinRequest struct { 559 | Chat Chat `json:"chat"` 560 | From User `json:"from"` 561 | Date int `json:"date"` 562 | Bio *string `json:"bio,omitempty"` 563 | InviteLink *ChatInviteLink `json:"invite_link,omitempty"` 564 | } 565 | 566 | // ChatPermissions struct 567 | type ChatPermissions struct { 568 | CanSendMessages *bool `json:"can_send_messages,omitempty"` 569 | CanSendMediaMessages *bool `json:"can_send_media_messages,omitempty"` 570 | CanSendPolls *bool `json:"can_send_polls,omitempty"` 571 | CanSendOtherMessages *bool `json:"can_send_other_messages,omitempty"` 572 | CanAddWebPagePreviews *bool `json:"can_add_web_page_previews,omitempty"` 573 | CanChangeInfo *bool `json:"can_change_info,omitempty"` 574 | CanInviteUsers *bool `json:"can_invite_users,omitempty"` 575 | CanPinMessages *bool `json:"can_pin_messages,omitempty"` 576 | } 577 | 578 | // ChatLocation struct 579 | type ChatLocation struct { 580 | Location Location `json:"location"` 581 | Address string `json:"address"` 582 | } 583 | 584 | // BotCommand struct 585 | type BotCommand struct { 586 | Command string `json:"command"` 587 | Description string `json:"description"` 588 | } 589 | 590 | // BotCommandScope represents the scope to which bot commands are applied. Currently, the following 7 scopes are supported: 591 | // * BotCommandScopeDefault 592 | // * BotCommandScopeAllPrivateChats 593 | // * BotCommandScopeAllGroupChats 594 | // * BotCommandScopeAllChatAdministrators 595 | // * BotCommandScopeChat 596 | // * BotCommandScopeChatAdministrators 597 | // * BotCommandScopeChatMember 598 | type BotCommandScope interface{} 599 | 600 | // BotCommandScopeDefault represents the default scope of bot commands. Default commands are used if no commands with a narrower scope are specified for the user. 601 | type BotCommandScopeDefault struct { 602 | Type string `json:"type"` // Scope type, must be default 603 | } 604 | 605 | // BotCommandScopeAllPrivateChats represents the scope of bot commands, covering all private chats. 606 | type BotCommandScopeAllPrivateChats struct { 607 | Type string `json:"type"` // Scope type, must be all_private_chats 608 | } 609 | 610 | // BotCommandScopeAllGroupChats represents the scope of bot commands, covering all group and supergroup chats. 611 | type BotCommandScopeAllGroupChats struct { 612 | Type string `json:"type"` // Scope type, must be all_group_chats 613 | } 614 | 615 | // BotCommandScopeAllChatAdministrators represents the scope of bot commands, covering all group and supergroup chat administrators. 616 | type BotCommandScopeAllChatAdministrators struct { 617 | Type string `json:"type"` // Scope type, must be all_chat_administrators 618 | } 619 | 620 | // BotCommandScopeChat represents the scope of bot commands, covering specific chat. 621 | type BotCommandScopeChat struct { 622 | Type string `json:"type"` // Scope type, must be chat 623 | ChatID interface{} `json:"chat_id"` // Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 624 | } 625 | 626 | // BotCommandScopeChatAdministrators represents the scope of bot commands, covering all administrators of a specific group or supergroup chat. 627 | type BotCommandScopeChatAdministrators struct { 628 | Type string `json:"type"` // Scope type, must be chat_administrators 629 | ChatID interface{} `json:"chat_id"` // Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 630 | } 631 | 632 | // BotCommandScopeChatMember represents the scope of bot commands, covering a specific member of a group or supergroup chat. 633 | type BotCommandScopeChatMember struct { 634 | Type string `json:"type"` // Scope type, must be chat_member 635 | ChatID interface{} `json:"chat_id"` // Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) 636 | UserID int `json:"user_id"` // Unique identifier of the target user 637 | } 638 | 639 | // MenuButton describes the bot's menu button in a private chat. It should be one of 640 | // 641 | // - MenuButtonCommands 642 | // - MenuButtonWebApp 643 | // - MenuButtonDefault 644 | // 645 | // 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. 646 | type MenuButton interface{} 647 | 648 | // MenuButtonCommands represents a menu button, which opens the bot's list of commands. 649 | type MenuButtonCommands struct { 650 | Type string `json:"type"` 651 | } 652 | 653 | // MenuButtonWebApp represents a menu button, which launches a Web App. 654 | type MenuButtonWebApp struct { 655 | Type string `json:"type"` 656 | Text string `json:"text"` 657 | WebApp WebAppInfo `json:"web_app"` 658 | } 659 | 660 | // MenuButtonDefault describes that no specific value for the menu button was set. 661 | type MenuButtonDefault struct { 662 | Type string `json:"type"` 663 | } 664 | 665 | // ResponseParameters struct 666 | type ResponseParameters struct { 667 | MigrateToChatID *int64 `json:"migrate_to_chat_id,omitempty"` 668 | RetryAfter *int `json:"retry_after,omitempty"` 669 | } 670 | 671 | // InputMedia interface 672 | type InputMedia interface{} 673 | 674 | // InputMediaPhoto struct 675 | type InputMediaPhoto struct { 676 | Type string `json:"type"` 677 | Media string `json:"media"` 678 | Caption *string `json:"caption,omitempty"` 679 | ParseMode *string `json:"parse_mode,omitempty"` 680 | } 681 | 682 | // InputMediaVideo struct 683 | type InputMediaVideo struct { 684 | Type string `json:"type"` 685 | Media string `json:"media"` 686 | Thumb interface{} `json:"thumb,omitempty"` 687 | Caption *string `json:"caption,omitempty"` 688 | ParseMode *string `json:"parse_mode,omitempty"` 689 | Width *int `json:"width,omitempty"` 690 | Height *int `json:"height,omitempty"` 691 | Duration *int `json:"duration,omitempty"` 692 | SupportsStreaming *bool `json:"supports_streaming,omitempty"` 693 | } 694 | 695 | // InputMediaAnimation struct 696 | type InputMediaAnimation struct { 697 | Type string `json:"type"` 698 | Media string `json:"media"` 699 | Thumb interface{} `json:"thumb,omitempty"` 700 | Caption *string `json:"caption,omitempty"` 701 | ParseMode *string `json:"parse_mode,omitempty"` 702 | Width *int `json:"width,omitempty"` 703 | Height *int `json:"height,omitempty"` 704 | Duration *int `json:"duration,omitempty"` 705 | } 706 | 707 | // InputMediaAudio struct 708 | type InputMediaAudio struct { 709 | Type string `json:"type"` 710 | Media string `json:"media"` 711 | Thumb interface{} `json:"thumb,omitempty"` 712 | Caption *string `json:"caption,omitempty"` 713 | ParseMode *string `json:"parse_mode,omitempty"` 714 | Duration *int `json:"duration,omitempty"` 715 | Performer *string `json:"performer,omitempty"` 716 | Title *string `json:"title,omitempty"` 717 | } 718 | 719 | // InputMediaDocument struct 720 | type InputMediaDocument struct { 721 | Type string `json:"type"` 722 | Media string `json:"media"` 723 | Thumb interface{} `json:"thumb,omitempty"` 724 | Caption *string `json:"caption,omitempty"` 725 | ParseMode *string `json:"parse_mode,omitempty"` 726 | DisableContentTypeDetection *bool `json:"disable_content_type_detection,omitempty"` 727 | } 728 | 729 | // InputFile interface 730 | type InputFile interface { 731 | io.Reader 732 | } 733 | --------------------------------------------------------------------------------