From f90493fac6ee3a4cc3918d3edb4da1f7999acc38 Mon Sep 17 00:00:00 2001 From: Amir Khazaie <733amir@gmail.com> Date: Sat, 30 Jun 2018 11:01:59 +0430 Subject: [PATCH 1/8] Add ParseMode to EditMessageCaption --- configs.go | 4 +++- helpers.go | 5 +++-- helpers_test.go | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/configs.go b/configs.go index bcc850d..08aa491 100644 --- a/configs.go +++ b/configs.go @@ -793,13 +793,15 @@ func (config EditMessageTextConfig) method() string { // EditMessageCaptionConfig allows you to modify the caption of a message. type EditMessageCaptionConfig struct { BaseEdit - Caption string + Caption string + ParseMode string } func (config EditMessageCaptionConfig) values() (url.Values, error) { v, _ := config.BaseEdit.values() v.Add("caption", config.Caption) + v.Add("parse_mode", config.ParseMode) return v, nil } diff --git a/helpers.go b/helpers.go index b5480ea..9088d31 100644 --- a/helpers.go +++ b/helpers.go @@ -494,13 +494,14 @@ func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTex } // NewEditMessageCaption allows you to edit the caption of a message. -func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMessageCaptionConfig { +func NewEditMessageCaption(chatID int64, messageID int, caption, parseMode string) EditMessageCaptionConfig { return EditMessageCaptionConfig{ BaseEdit: BaseEdit{ ChatID: chatID, MessageID: messageID, }, - Caption: caption, + Caption: caption, + ParseMode: parseMode, } } diff --git a/helpers_test.go b/helpers_test.go index 9542f02..6075612 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -148,9 +148,10 @@ func TestNewEditMessageText(t *testing.T) { } func TestNewEditMessageCaption(t *testing.T) { - edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") + edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption", tgbotapi.ModeHTML) if edit.Caption != "new caption" || + edit.ParseMode != tgbotapi.ModeHTML || edit.BaseEdit.ChatID != ChatID || edit.BaseEdit.MessageID != ReplyToMessageID { t.Fail() From 31f4975464f318de5f00fb1c2fd905c259c14199 Mon Sep 17 00:00:00 2001 From: Amir Khazaie <733amir@gmail.com> Date: Wed, 4 Jul 2018 15:18:19 +0430 Subject: [PATCH 2/8] Add cached types for inline query answer --- helpers.go | 66 +++++++++++++++++++++++++++++++++++++++++ types.go | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/helpers.go b/helpers.go index 9088d31..d4ee98b 100644 --- a/helpers.go +++ b/helpers.go @@ -403,6 +403,15 @@ func NewInlineQueryResultGIF(id, url string) InlineQueryResultGIF { } } +// NewInlineQueryResultCachedGIF create a new inline query with cached photo. +func NewInlineQueryResultCachedGIF(id, gifID string) InlineQueryResultCachedGIF { + return InlineQueryResultCachedGIF{ + Type: "gif", + ID: id, + GifID: gifID, + } +} + // NewInlineQueryResultMPEG4GIF creates a new inline query MPEG4 GIF. func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF { return InlineQueryResultMPEG4GIF{ @@ -412,6 +421,15 @@ func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF { } } +// NewInlineQueryResultCachedPhoto create a new inline query with cached photo. +func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMpeg4Gif { + return InlineQueryResultCachedMpeg4Gif{ + Type: "mpeg4_gif", + ID: id, + MGifID: MPEG4GifID, + } +} + // NewInlineQueryResultPhoto creates a new inline query photo. func NewInlineQueryResultPhoto(id, url string) InlineQueryResultPhoto { return InlineQueryResultPhoto{ @@ -431,6 +449,15 @@ func NewInlineQueryResultPhotoWithThumb(id, url, thumb string) InlineQueryResult } } +// NewInlineQueryResultCachedPhoto create a new inline query with cached photo. +func NewInlineQueryResultCachedPhoto(id, photoID string) InlineQueryResultCachedPhoto { + return InlineQueryResultCachedPhoto{ + Type: "photo", + ID: id, + PhotoID: photoID, + } +} + // NewInlineQueryResultVideo creates a new inline query video. func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo { return InlineQueryResultVideo{ @@ -440,6 +467,16 @@ func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo { } } +// NewInlineQueryResultCachedVideo create a new inline query with cached video. +func NewInlineQueryResultCachedVideo(id, videoID, title string) InlineQueryResultCachedVideo { + return InlineQueryResultCachedVideo{ + Type: "video", + ID: id, + VideoID: videoID, + Title: title, + } +} + // NewInlineQueryResultAudio creates a new inline query audio. func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio { return InlineQueryResultAudio{ @@ -450,6 +487,15 @@ func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio { } } +// NewInlineQueryResultCachedAudio create a new inline query with cached photo. +func NewInlineQueryResultCachedAudio(id, audioID string) InlineQueryResultCachedAudio { + return InlineQueryResultCachedAudio{ + Type: "audio", + ID: id, + AudioID: audioID, + } +} + // NewInlineQueryResultVoice creates a new inline query voice. func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice { return InlineQueryResultVoice{ @@ -460,6 +506,16 @@ func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice { } } +// NewInlineQueryResultCachedVoice create a new inline query with cached photo. +func NewInlineQueryResultCachedVoice(id, voiceID, title string) InlineQueryResultCachedVoice { + return InlineQueryResultCachedVoice{ + Type: "voice", + ID: id, + VoiceID: voiceID, + Title: title, + } +} + // NewInlineQueryResultDocument creates a new inline query document. func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryResultDocument { return InlineQueryResultDocument{ @@ -471,6 +527,16 @@ func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryRe } } +// NewInlineQueryResultCachedDocument create a new inline query with cached photo. +func NewInlineQueryResultCachedDocument(id, documentID, title string) InlineQueryResultCachedDocument { + return InlineQueryResultCachedDocument{ + Type: "document", + ID: id, + DocumentID: documentID, + Title: title, + } +} + // NewInlineQueryResultLocation creates a new inline query location. func NewInlineQueryResultLocation(id, title string, latitude, longitude float64) InlineQueryResultLocation { return InlineQueryResultLocation{ diff --git a/types.go b/types.go index 0843ab9..da325f4 100644 --- a/types.go +++ b/types.go @@ -551,6 +551,19 @@ type InlineQueryResultPhoto struct { InputMessageContent interface{} `json:"input_message_content,omitempty"` } +// InlineQueryResultCachedPhoto is an inline query response with cached photo. +type InlineQueryResultCachedPhoto struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + PhotoID string `json:"photo_file_id"` // required + Title string `json:"title"` + Description string `json:"description"` + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultGIF is an inline query response GIF. type InlineQueryResultGIF struct { Type string `json:"type"` // required @@ -566,6 +579,18 @@ type InlineQueryResultGIF struct { InputMessageContent interface{} `json:"input_message_content,omitempty"` } +// InlineQueryResultCachedGIF is an inline query response with cached gif. +type InlineQueryResultCachedGIF struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + GifID string `json:"gif_file_id"` // required + Title string `json:"title"` + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF. type InlineQueryResultMPEG4GIF struct { Type string `json:"type"` // required @@ -581,6 +606,19 @@ type InlineQueryResultMPEG4GIF struct { InputMessageContent interface{} `json:"input_message_content,omitempty"` } +// InlineQueryResultCachedMpeg4Gif is an inline query response with cached +// H.264/MPEG-4 AVC video without sound gif. +type InlineQueryResultCachedMpeg4Gif struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + MGifID string `json:"mpeg4_file_id"` // required + Title string `json:"title"` + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultVideo is an inline query response video. type InlineQueryResultVideo struct { Type string `json:"type"` // required @@ -598,6 +636,19 @@ type InlineQueryResultVideo struct { InputMessageContent interface{} `json:"input_message_content,omitempty"` } +// InlineQueryResultCachedVideo is an inline query response with cached video. +type InlineQueryResultCachedVideo struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + VideoID string `json:"video_file_id"` // required + Title string `json:"title"` // required + Description string `json:"description"` + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultAudio is an inline query response audio. type InlineQueryResultAudio struct { Type string `json:"type"` // required @@ -611,6 +662,17 @@ type InlineQueryResultAudio struct { InputMessageContent interface{} `json:"input_message_content,omitempty"` } +// InlineQueryResultCachedAudio is an inline query response with cached audio. +type InlineQueryResultCachedAudio struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + AudioID string `json:"audio_file_id"` // required + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultVoice is an inline query response voice. type InlineQueryResultVoice struct { Type string `json:"type"` // required @@ -623,6 +685,18 @@ type InlineQueryResultVoice struct { InputMessageContent interface{} `json:"input_message_content,omitempty"` } +// InlineQueryResultCachedVoice is an inline query response with cached voice. +type InlineQueryResultCachedVoice struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + VoiceID string `json:"voice_file_id"` // required + Title string `json:"title"` // required + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultDocument is an inline query response document. type InlineQueryResultDocument struct { Type string `json:"type"` // required @@ -639,6 +713,19 @@ type InlineQueryResultDocument struct { ThumbHeight int `json:"thumb_height"` } +// InlineQueryResultCachedDocument is an inline query response with cached document. +type InlineQueryResultCachedDocument struct { + Type string `json:"type"` // required + ID string `json:"id"` // required + DocumentID string `json:"document_file_id"` // required + Title string `json:"title"` // required + Caption string `json:"caption"` + Description string `json:"description"` + ParseMode string `json:"parse_mode"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + // InlineQueryResultLocation is an inline query response location. type InlineQueryResultLocation struct { Type string `json:"type"` // required From 4edcb0fa1ab5e691899ca33c58d79f517c6bf30f Mon Sep 17 00:00:00 2001 From: Amir Khazaie <733amir@gmail.com> Date: Wed, 4 Jul 2018 15:19:37 +0430 Subject: [PATCH 3/8] Correct formatting of code with `go fmt` --- helpers.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/helpers.go b/helpers.go index d4ee98b..310319f 100644 --- a/helpers.go +++ b/helpers.go @@ -406,8 +406,8 @@ func NewInlineQueryResultGIF(id, url string) InlineQueryResultGIF { // NewInlineQueryResultCachedGIF create a new inline query with cached photo. func NewInlineQueryResultCachedGIF(id, gifID string) InlineQueryResultCachedGIF { return InlineQueryResultCachedGIF{ - Type: "gif", - ID: id, + Type: "gif", + ID: id, GifID: gifID, } } @@ -424,8 +424,8 @@ func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF { // NewInlineQueryResultCachedPhoto create a new inline query with cached photo. func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMpeg4Gif { return InlineQueryResultCachedMpeg4Gif{ - Type: "mpeg4_gif", - ID: id, + Type: "mpeg4_gif", + ID: id, MGifID: MPEG4GifID, } } @@ -452,8 +452,8 @@ func NewInlineQueryResultPhotoWithThumb(id, url, thumb string) InlineQueryResult // NewInlineQueryResultCachedPhoto create a new inline query with cached photo. func NewInlineQueryResultCachedPhoto(id, photoID string) InlineQueryResultCachedPhoto { return InlineQueryResultCachedPhoto{ - Type: "photo", - ID: id, + Type: "photo", + ID: id, PhotoID: photoID, } } @@ -470,10 +470,10 @@ func NewInlineQueryResultVideo(id, url string) InlineQueryResultVideo { // NewInlineQueryResultCachedVideo create a new inline query with cached video. func NewInlineQueryResultCachedVideo(id, videoID, title string) InlineQueryResultCachedVideo { return InlineQueryResultCachedVideo{ - Type: "video", - ID: id, + Type: "video", + ID: id, VideoID: videoID, - Title: title, + Title: title, } } @@ -490,8 +490,8 @@ func NewInlineQueryResultAudio(id, url, title string) InlineQueryResultAudio { // NewInlineQueryResultCachedAudio create a new inline query with cached photo. func NewInlineQueryResultCachedAudio(id, audioID string) InlineQueryResultCachedAudio { return InlineQueryResultCachedAudio{ - Type: "audio", - ID: id, + Type: "audio", + ID: id, AudioID: audioID, } } @@ -509,10 +509,10 @@ func NewInlineQueryResultVoice(id, url, title string) InlineQueryResultVoice { // NewInlineQueryResultCachedVoice create a new inline query with cached photo. func NewInlineQueryResultCachedVoice(id, voiceID, title string) InlineQueryResultCachedVoice { return InlineQueryResultCachedVoice{ - Type: "voice", - ID: id, + Type: "voice", + ID: id, VoiceID: voiceID, - Title: title, + Title: title, } } @@ -530,10 +530,10 @@ func NewInlineQueryResultDocument(id, url, title, mimeType string) InlineQueryRe // NewInlineQueryResultCachedDocument create a new inline query with cached photo. func NewInlineQueryResultCachedDocument(id, documentID, title string) InlineQueryResultCachedDocument { return InlineQueryResultCachedDocument{ - Type: "document", - ID: id, + Type: "document", + ID: id, DocumentID: documentID, - Title: title, + Title: title, } } From 9860bdfd3a171ceafb6e1eafa163482a6ef92643 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Mon, 8 Oct 2018 14:45:45 -0500 Subject: [PATCH 4/8] Fix capitalization in doc. --- passport.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passport.go b/passport.go index f949b88..5f55006 100644 --- a/passport.go +++ b/passport.go @@ -307,7 +307,7 @@ type ( MiddleNameNative string `json:"middle_name_native"` } - // IdDocumentData https://core.telegram.org/passport#iddocumentdata + // IDDocumentData https://core.telegram.org/passport#iddocumentdata IDDocumentData struct { DocumentNumber string `json:"document_no"` ExpiryDate string `json:"expiry_date"` From b2addf5f91a4c2750c3f03aa22e1aab243e6db6d Mon Sep 17 00:00:00 2001 From: Amir Khazaie <733amir@gmail.com> Date: Mon, 15 Oct 2018 12:31:37 +0330 Subject: [PATCH 5/8] Fix backwards compatibility problem --- helpers.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helpers.go b/helpers.go index b15b9f2..3dabe11 100644 --- a/helpers.go +++ b/helpers.go @@ -616,14 +616,13 @@ func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTex } // NewEditMessageCaption allows you to edit the caption of a message. -func NewEditMessageCaption(chatID int64, messageID int, caption, parseMode string) EditMessageCaptionConfig { +func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMessageCaptionConfig { return EditMessageCaptionConfig{ BaseEdit: BaseEdit{ ChatID: chatID, MessageID: messageID, }, Caption: caption, - ParseMode: parseMode, } } From 97ba9e12bf1de0043362910282546d167e9f74f5 Mon Sep 17 00:00:00 2001 From: Amir Khazaie <733amir@gmail.com> Date: Mon, 15 Oct 2018 12:41:02 +0330 Subject: [PATCH 6/8] Fix help tests --- helpers_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index 6075612..9542f02 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -148,10 +148,9 @@ func TestNewEditMessageText(t *testing.T) { } func TestNewEditMessageCaption(t *testing.T) { - edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption", tgbotapi.ModeHTML) + edit := tgbotapi.NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") if edit.Caption != "new caption" || - edit.ParseMode != tgbotapi.ModeHTML || edit.BaseEdit.ChatID != ChatID || edit.BaseEdit.MessageID != ReplyToMessageID { t.Fail() From ab8d5487da0c84a0923a44203aa0a4b3b8ca51fb Mon Sep 17 00:00:00 2001 From: bcmk <45658475+bcmk@users.noreply.github.com> Date: Mon, 10 Dec 2018 18:02:58 +0400 Subject: [PATCH 7/8] Closing update body --- bot.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.go b/bot.go index d56aaf8..85e16c1 100644 --- a/bot.go +++ b/bot.go @@ -526,6 +526,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel { http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { bytes, _ := ioutil.ReadAll(r.Body) + r.Body.Close() var update Update json.Unmarshal(bytes, &update) From fef37c79dca9863dc45bbb5b509dab7a868064e9 Mon Sep 17 00:00:00 2001 From: Marc Arndt Date: Mon, 21 Jan 2019 13:57:18 +0200 Subject: [PATCH 8/8] adding interface --- bot.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/bot.go b/bot.go index 85e16c1..9156df2 100644 --- a/bot.go +++ b/bot.go @@ -19,6 +19,47 @@ import ( "github.com/technoweenie/multipartstreamer" ) + +type Bot interface { + MakeRequest(endpoint string, params url.Values) (APIResponse, error) + UploadFile(endpoint string, params map[string]string, fieldname string, file interface{}) (APIResponse, error) + GetFileDirectURL(fileID string) (string, error) + GetMe() (User, error) + IsMessageToMe(message Message) bool + Send(c Chattable) (Message, error) + GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error) + GetFile(config FileConfig) (File, error) + GetUpdates(config UpdateConfig) ([]Update, error) + RemoveWebhook() (APIResponse, error) + SetWebhook(config WebhookConfig) (APIResponse, error) + GetWebhookInfo() (WebhookInfo, error) + GetUpdatesChan(config UpdateConfig) (UpdatesChannel, error) + StopReceivingUpdates() + ListenForWebhook(pattern string) UpdatesChannel + AnswerInlineQuery(config InlineConfig) (APIResponse, error) + AnswerCallbackQuery(config CallbackConfig) (APIResponse, error) + KickChatMember(config KickChatMemberConfig) (APIResponse, error) + LeaveChat(config ChatConfig) (APIResponse, error) + GetChat(config ChatConfig) (Chat, error) + GetChatAdministrators(config ChatConfig) ([]ChatMember, error) + GetChatMembersCount(config ChatConfig) (int, error) + GetChatMember(config ChatConfigWithUser) (ChatMember, error) + UnbanChatMember(config ChatMemberConfig) (APIResponse, error) + RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) + PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) + GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) + AnswerShippingQuery(config ShippingConfig) (APIResponse, error) + AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse, error) + DeleteMessage(config DeleteMessageConfig) (APIResponse, error) + GetInviteLink(config ChatConfig) (string, error) + PinChatMessage(config PinChatMessageConfig) (APIResponse, error) + UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, error) + SetChatTitle(config SetChatTitleConfig) (APIResponse, error) + SetChatDescription(config SetChatDescriptionConfig) (APIResponse, error) + SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error) + DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, error) + +} // BotAPI allows you to interact with the Telegram Bot API. type BotAPI struct { Token string `json:"token"`