Merge pull request #152 from mr-linch/master
Add setChatTitle and setChatDescription methodsbot-api-6.1
commit
690363a5f8
48
bot.go
48
bot.go
|
@ -898,3 +898,51 @@ 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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
|
74
configs.go
74
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
|
||||
}
|
||||
|
||||
|
@ -1073,3 +1073,73 @@ func (config UnpinChatMessageConfig) values() (url.Values, error) {
|
|||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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"
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
31
helpers.go
31
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue