From 6e69f99d113a3ac6537961e7ea3e1b1160f688eb Mon Sep 17 00:00:00 2001 From: Oleksandr Savchuk Date: Sat, 3 Mar 2018 20:20:03 +0200 Subject: [PATCH 1/3] add setChatTitle and setChatDescription methods --- bot.go | 24 ++++++++++++++++++++++++ configs.go | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/bot.go b/bot.go index e201944..48d729b 100644 --- a/bot.go +++ b/bot.go @@ -898,3 +898,27 @@ func (bot *BotAPI) UnpinChatMessage(config UnpinChatMessageConfig) (APIResponse, return bot.MakeRequest(config.method(), v) } + +// SetChatTitle change title of chat. +func (bot *BotAPI) SetChatTitle(config SetChatTitleConfig) (APIResponse, error) { + v, err := config.values() + if err != nil { + return APIResponse{}, err + } + + bot.debugLog(config.method(), v, nil) + + return bot.MakeRequest(config.method(), v) +} + +// SetChatDescription change description of chat. +func (bot *BotAPI) SetChatDescription(config SetChatDescriptionConfig) (APIResponse, error) { + v, err := config.values() + if err != nil { + return APIResponse{}, err + } + + bot.debugLog(config.method(), v, nil) + + return bot.MakeRequest(config.method(), v) +} diff --git a/configs.go b/configs.go index 6c12d64..e16cbbb 100644 --- a/configs.go +++ b/configs.go @@ -1038,8 +1038,8 @@ func (config DeleteMessageConfig) values() (url.Values, error) { // PinChatMessageConfig contains information of a message in a chat to pin. type PinChatMessageConfig struct { - ChatID int64 - MessageID int + ChatID int64 + MessageID int DisableNotification bool } @@ -1072,4 +1072,42 @@ func (config UnpinChatMessageConfig) values() (url.Values, error) { v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) return v, nil -} \ No newline at end of file +} + +// SetChatTitleConfig contains information for change chat title. +type SetChatTitleConfig struct { + ChatID int64 + Title string +} + +func (config SetChatTitleConfig) method() string { + return "setChatTitle" +} + +func (config SetChatTitleConfig) values() (url.Values, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + v.Add("title", config.Title) + + return v, nil +} + +// SetChatDescriptionConfig contains information for change chat description. +type SetChatDescriptionConfig struct { + ChatID int64 + Description string +} + +func (config SetChatDescriptionConfig) method() string { + return "setChatDescription" +} + +func (config SetChatDescriptionConfig) values() (url.Values, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + v.Add("description", config.Description) + + return v, nil +} From 57be98801107f19622d22a718cdc4a5f52cc0712 Mon Sep 17 00:00:00 2001 From: Oleksandr Savchuk Date: Mon, 5 Mar 2018 17:04:37 +0200 Subject: [PATCH 2/3] add setChatPhoto method --- bot.go | 12 ++++++++++++ configs.go | 15 +++++++++++++++ helpers.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/bot.go b/bot.go index 48d729b..165d3b6 100644 --- a/bot.go +++ b/bot.go @@ -922,3 +922,15 @@ func (bot *BotAPI) SetChatDescription(config SetChatDescriptionConfig) (APIRespo return bot.MakeRequest(config.method(), v) } + +// SetChatPhoto change photo of chat. +func (bot *BotAPI) SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error) { + params, err := config.params() + if err != nil { + return APIResponse{}, err + } + + file := config.getFile() + + return bot.UploadFile(config.method(), params, config.name(), file) +} diff --git a/configs.go b/configs.go index e16cbbb..1bbaff4 100644 --- a/configs.go +++ b/configs.go @@ -1111,3 +1111,18 @@ func (config SetChatDescriptionConfig) values() (url.Values, error) { return v, nil } + +// SetChatPhotoConfig contains information for change chat photo +type SetChatPhotoConfig struct { + BaseFile +} + +// name returns the field name for the Photo. +func (config SetChatPhotoConfig) name() string { + return "photo" +} + +// method returns Telegram API method name for sending Photo. +func (config SetChatPhotoConfig) method() string { + return "setChatPhoto" +} diff --git a/helpers.go b/helpers.go index f5800f4..c23a3bf 100644 --- a/helpers.go +++ b/helpers.go @@ -653,3 +653,34 @@ func NewInvoice(chatID int64, title, description, payload, providerToken, startP Currency: currency, Prices: prices} } + +// NewSetChatPhotoUpload creates a new chat photo uploader. +// +// chatID is where to send it, file is a string path to the file, +// FileReader, or FileBytes. +// +// Note that you must send animated GIFs as a document. +func NewSetChatPhotoUpload(chatID int64, file interface{}) SetChatPhotoConfig { + return SetChatPhotoConfig{ + BaseFile: BaseFile{ + BaseChat: BaseChat{ChatID: chatID}, + File: file, + UseExisting: false, + }, + } +} + +// NewSetChatPhotoShare shares an existing photo. +// You may use this to reshare an existing photo without reuploading it. +// +// chatID is where to send it, fileID is the ID of the file +// already uploaded. +func NewSetChatPhotoShare(chatID int64, fileID string) SetChatPhotoConfig { + return SetChatPhotoConfig{ + BaseFile: BaseFile{ + BaseChat: BaseChat{ChatID: chatID}, + FileID: fileID, + UseExisting: true, + }, + } +} From a36af7a672af72fb2202924ab5c9001e17b76464 Mon Sep 17 00:00:00 2001 From: Oleksandr Savchuk Date: Mon, 5 Mar 2018 17:12:56 +0200 Subject: [PATCH 3/3] add deleteChatPhoto method --- bot.go | 12 ++++++++++++ configs.go | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/bot.go b/bot.go index 165d3b6..ee1ddd0 100644 --- a/bot.go +++ b/bot.go @@ -934,3 +934,15 @@ func (bot *BotAPI) SetChatPhoto(config SetChatPhotoConfig) (APIResponse, error) return bot.UploadFile(config.method(), params, config.name(), file) } + +// DeleteChatPhoto delete photo of chat. +func (bot *BotAPI) DeleteChatPhoto(config DeleteChatPhotoConfig) (APIResponse, error) { + v, err := config.values() + if err != nil { + return APIResponse{}, err + } + + bot.debugLog(config.method(), v, nil) + + return bot.MakeRequest(config.method(), v) +} diff --git a/configs.go b/configs.go index 1bbaff4..574b3dd 100644 --- a/configs.go +++ b/configs.go @@ -1126,3 +1126,20 @@ func (config SetChatPhotoConfig) name() string { func (config SetChatPhotoConfig) method() string { return "setChatPhoto" } + +// DeleteChatPhotoConfig contains information for delete chat photo. +type DeleteChatPhotoConfig struct { + ChatID int64 +} + +func (config DeleteChatPhotoConfig) method() string { + return "deleteChatPhoto" +} + +func (config DeleteChatPhotoConfig) values() (url.Values, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + + return v, nil +}