Refactoring
@@ -188,7 +188,7 @@
return user, nil } -func (bot *BotAPI) Send(c Chattable) error { +func (bot *BotAPI) Send(c BaseChat) error { return nil }@@ -199,13 +199,27 @@ log.Printf("%s resp: %+v\n", context, message)
} } +func (bot *BotAPI) sendExisting(method string, config Fileable) (Message, error) { + v, err := config.Values() + + if err != nil { + return Message{}, err + } + + message, err := bot.MakeMessageRequest(method, v) + if err != nil { + return Message{}, err + } + + return message, nil +} + // SendMessage sends a Message to a chat. // // Requires ChatID and Text. // DisableWebPagePreview, ReplyToMessageID, and ReplyMarkup are optional. func (bot *BotAPI) SendMessage(config MessageConfig) (Message, error) { v, err := config.Values() - if err != nil { return Message{}, err }@@ -223,9 +237,30 @@ // ForwardMessage forwards a message from one chat to another.
// // Requires ChatID (destination), FromChatID (source), and MessageID. func (bot *BotAPI) ForwardMessage(config ForwardConfig) (Message, error) { - v, _ := config.Values() + v, err := config.Values() + if err != nil { + return Message{}, err + } message, err := bot.MakeMessageRequest("forwardMessage", v) + if err != nil { + return Message{}, err + } + + return message, nil +} + +// SendLocation sends a location to a chat. +// +// Requires ChatID, Latitude, and Longitude. +// ReplyToMessageID and ReplyMarkup are optional. +func (bot *BotAPI) SendLocation(config LocationConfig) (Message, error) { + v, err := config.Values() + if err != nil { + return Message{}, err + } + + message, err := bot.MakeMessageRequest("sendLocation", v) if err != nil { return Message{}, err }@@ -239,48 +274,16 @@ // Requires ChatID and FileID OR File.
// Caption, ReplyToMessageID, and ReplyMarkup are optional. // File should be either a string, FileBytes, or FileReader. func (bot *BotAPI) SendPhoto(config PhotoConfig) (Message, error) { - if config.UseExistingPhoto { - v, err := config.Values() - - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("SendPhoto", v) - if err != nil { - return Message{}, err - } - - return message, nil + if config.UseExisting { + return bot.sendExisting("SendPhoto", config) } - params := make(map[string]string) - if config.ChannelUsername != "" { - params["chat_id"] = config.ChannelUsername - } else { - params["chat_id"] = strconv.Itoa(config.ChatID) - } - if config.Caption != "" { - params["caption"] = config.Caption - } - if config.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) - } - if config.ReplyMarkup != nil { - data, err := json.Marshal(config.ReplyMarkup) - if err != nil { - return Message{}, err - } - - params["reply_markup"] = string(data) + params, err := config.Params() + if err != nil { + return Message{}, err } - var file interface{} - if config.FilePath == "" { - file = config.File - } else { - file = config.FilePath - } + file := config.GetFile() resp, err := bot.UploadFile("SendPhoto", params, "photo", file) if err != nil {@@ -309,54 +312,16 @@ // Requires ChatID and FileID OR File.
// ReplyToMessageID and ReplyMarkup are optional. // File should be either a string, FileBytes, or FileReader. func (bot *BotAPI) SendAudio(config AudioConfig) (Message, error) { - if config.UseExistingAudio { - v, err := config.Values() - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("sendAudio", v) - if err != nil { - return Message{}, err - } - - return message, nil + if config.UseExisting { + return bot.sendExisting("sendAudio", config) } - params := make(map[string]string) - - if config.ChannelUsername != "" { - params["chat_id"] = config.ChannelUsername - } else { - params["chat_id"] = strconv.Itoa(config.ChatID) - } - if config.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) - } - if config.Duration != 0 { - params["duration"] = strconv.Itoa(config.Duration) - } - if config.ReplyMarkup != nil { - data, err := json.Marshal(config.ReplyMarkup) - if err != nil { - return Message{}, err - } - - params["reply_markup"] = string(data) - } - if config.Performer != "" { - params["performer"] = config.Performer - } - if config.Title != "" { - params["title"] = config.Title + params, err := config.Params() + if err != nil { + return Message{}, err } - var file interface{} - if config.FilePath == "" { - file = config.File - } else { - file = config.FilePath - } + file := config.GetFile() resp, err := bot.UploadFile("sendAudio", params, "audio", file) if err != nil {@@ -379,45 +344,16 @@ // Requires ChatID and FileID OR File.
// ReplyToMessageID and ReplyMarkup are optional. // File should be either a string, FileBytes, or FileReader. func (bot *BotAPI) SendDocument(config DocumentConfig) (Message, error) { - if config.UseExistingDocument { - v, err := config.Values() - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("sendDocument", v) - if err != nil { - return Message{}, err - } - - return message, nil + if config.UseExisting { + return bot.sendExisting("sendDocument", config) } - params := make(map[string]string) - - if config.ChannelUsername != "" { - params["chat_id"] = config.ChannelUsername - } else { - params["chat_id"] = strconv.Itoa(config.ChatID) - } - if config.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + params, err := config.Params() + if err != nil { + return Message{}, err } - if config.ReplyMarkup != nil { - data, err := json.Marshal(config.ReplyMarkup) - if err != nil { - return Message{}, err - } - params["reply_markup"] = string(data) - } - - var file interface{} - if config.FilePath == "" { - file = config.File - } else { - file = config.FilePath - } + file := config.GetFile() resp, err := bot.UploadFile("sendDocument", params, "document", file) if err != nil {@@ -442,48 +378,16 @@ // Requires ChatID and FileID OR File.
// ReplyToMessageID and ReplyMarkup are optional. // File should be either a string, FileBytes, or FileReader. func (bot *BotAPI) SendVoice(config VoiceConfig) (Message, error) { - if config.UseExistingVoice { - v, err := config.Values() - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("sendVoice", v) - if err != nil { - return Message{}, err - } - - return message, nil + if config.UseExisting { + return bot.sendExisting("sendVoice", config) } - params := make(map[string]string) - - if config.ChannelUsername != "" { - params["chat_id"] = config.ChannelUsername - } else { - params["chat_id"] = strconv.Itoa(config.ChatID) - } - if config.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) - } - if config.Duration != 0 { - params["duration"] = strconv.Itoa(config.Duration) - } - if config.ReplyMarkup != nil { - data, err := json.Marshal(config.ReplyMarkup) - if err != nil { - return Message{}, err - } - - params["reply_markup"] = string(data) + params, err := config.Params() + if err != nil { + return Message{}, err } - var file interface{} - if config.FilePath == "" { - file = config.File - } else { - file = config.FilePath - } + file := config.GetFile() resp, err := bot.UploadFile("SendVoice", params, "voice", file) if err != nil {@@ -506,45 +410,16 @@ // Requires ChatID and FileID OR File.
// ReplyToMessageID and ReplyMarkup are optional. // File should be either a string, FileBytes, or FileReader. func (bot *BotAPI) SendSticker(config StickerConfig) (Message, error) { - if config.UseExistingSticker { - v, err := config.Values() - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("sendSticker", v) - if err != nil { - return Message{}, err - } - - return message, nil + if config.UseExisting { + return bot.sendExisting("sendSticker", config) } - params := make(map[string]string) - - if config.ChannelUsername != "" { - params["chat_id"] = config.ChannelUsername - } else { - params["chat_id"] = strconv.Itoa(config.ChatID) - } - if config.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + params, err := config.Params() + if err != nil { + return Message{}, err } - if config.ReplyMarkup != nil { - data, err := json.Marshal(config.ReplyMarkup) - if err != nil { - return Message{}, err - } - params["reply_markup"] = string(data) - } - - var file interface{} - if config.FilePath == "" { - file = config.File - } else { - file = config.FilePath - } + file := config.GetFile() resp, err := bot.UploadFile("sendSticker", params, "sticker", file) if err != nil {@@ -567,45 +442,16 @@ // Requires ChatID and FileID OR File.
// ReplyToMessageID and ReplyMarkup are optional. // File should be either a string, FileBytes, or FileReader. func (bot *BotAPI) SendVideo(config VideoConfig) (Message, error) { - if config.UseExistingVideo { - v, err := config.Values() - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("sendVideo", v) - if err != nil { - return Message{}, err - } - - return message, nil + if config.UseExisting { + return bot.sendExisting("sendVideo", config) } - params := make(map[string]string) - - if config.ChannelUsername != "" { - params["chat_id"] = config.ChannelUsername - } else { - params["chat_id"] = strconv.Itoa(config.ChatID) - } - if config.ReplyToMessageID != 0 { - params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + params, err := config.Params() + if err != nil { + return Message{}, err } - if config.ReplyMarkup != nil { - data, err := json.Marshal(config.ReplyMarkup) - if err != nil { - return Message{}, err - } - params["reply_markup"] = string(data) - } - - var file interface{} - if config.FilePath == "" { - file = config.File - } else { - file = config.FilePath - } + file := config.GetFile() resp, err := bot.UploadFile("sendVideo", params, "video", file) if err != nil {@@ -622,31 +468,16 @@
return message, nil } -// SendLocation sends a location to a chat. -// -// Requires ChatID, Latitude, and Longitude. -// ReplyToMessageID and ReplyMarkup are optional. -func (bot *BotAPI) SendLocation(config LocationConfig) (Message, error) { - v, err := config.Values() - if err != nil { - return Message{}, err - } - - message, err := bot.MakeMessageRequest("sendLocation", v) - if err != nil { - return Message{}, err - } - - return message, nil -} - // SendChatAction sets a current action in a chat. // // Requires ChatID and a valid Action (see Chat constants). func (bot *BotAPI) SendChatAction(config ChatActionConfig) error { - v, _ := config.Values() + v, err := config.Values() + if err != nil { + return err + } - _, err := bot.MakeRequest("sendChatAction", v) + _, err = bot.MakeRequest("sendChatAction", v) if err != nil { return err }
@@ -38,31 +38,66 @@ const (
ModeMarkdown = "Markdown" ) +type Chattable interface { + Values() (url.Values, error) +} + +type Fileable interface { + Chattable + Params() (map[string]string, error) + GetFile() interface{} +} + // Base struct for all chat event(Message, Photo and so on) -type Chattable struct { +type BaseChat struct { ChatID int ChannelUsername string } -type Fileable struct { - FilePath string - File interface{} - FileID string +func (chat *BaseChat) Values() (url.Values, error) { + v := url.Values{} + if chat.ChannelUsername != "" { + v.Add("chat_id", chat.ChannelUsername) + } else { + v.Add("chat_id", strconv.Itoa(chat.ChatID)) + } + return v, nil +} + +type BaseFile struct { + BaseChat + FilePath string + File interface{} + FileID string + UseExisting bool +} + +func (file BaseFile) Params() (map[string]string, error) { + params := make(map[string]string) + + if file.ChannelUsername != "" { + params["chat_id"] = file.ChannelUsername + } else { + params["chat_id"] = strconv.Itoa(file.ChatID) + } + + return params, nil } -func (chattable *Chattable) Values() (url.Values, error) { - v := url.Values{} - if chattable.ChannelUsername != "" { - v.Add("chat_id", chattable.ChannelUsername) +func (file BaseFile) GetFile() interface{} { + var result interface{} + if file.FilePath == "" { + result = file.File } else { - v.Add("chat_id", strconv.Itoa(chattable.ChatID)) + result = file.FilePath } - return v, nil + + return result } // MessageConfig contains information about a SendMessage request. type MessageConfig struct { - Chattable + BaseChat Text string ParseMode string DisableWebPagePreview bool@@ -70,8 +105,8 @@ ReplyToMessageID int
ReplyMarkup interface{} } -func (config *MessageConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config MessageConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("text", config.Text) v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview)) if config.ParseMode != "" {@@ -94,14 +129,14 @@ }
// ForwardConfig contains information about a ForwardMessage request. type ForwardConfig struct { - Chattable + BaseChat FromChatID int FromChannelUsername string MessageID int } -func (config *ForwardConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config ForwardConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() if config.FromChannelUsername != "" { v.Add("chat_id", config.FromChannelUsername)@@ -115,16 +150,35 @@ }
// PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { - Chattable - Fileable + BaseFile Caption string ReplyToMessageID int ReplyMarkup interface{} - UseExistingPhoto bool +} + +func (config PhotoConfig) Params() (map[string]string, error) { + params, _ := config.BaseFile.Params() + + if config.Caption != "" { + params["caption"] = config.Caption + } + if config.ReplyToMessageID != 0 { + params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + } + if config.ReplyMarkup != nil { + data, err := json.Marshal(config.ReplyMarkup) + if err != nil { + return params, err + } + + params["reply_markup"] = string(data) + } + + return params, nil } -func (config *PhotoConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config PhotoConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("photo", config.FileID) if config.Caption != "" {@@ -147,18 +201,16 @@ }
// AudioConfig contains information about a SendAudio request. type AudioConfig struct { - Chattable - Fileable + BaseFile Duration int Performer string Title string ReplyToMessageID int ReplyMarkup interface{} - UseExistingAudio bool } -func (config *AudioConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config AudioConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("audio", config.FileID) if config.ReplyToMessageID != 0 {@@ -185,17 +237,42 @@
return v, nil } +func (config AudioConfig) Params() (map[string]string, error) { + params, _ := config.BaseFile.Params() + + if config.ReplyToMessageID != 0 { + params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + } + if config.Duration != 0 { + params["duration"] = strconv.Itoa(config.Duration) + } + if config.ReplyMarkup != nil { + data, err := json.Marshal(config.ReplyMarkup) + if err != nil { + return params, err + } + + params["reply_markup"] = string(data) + } + if config.Performer != "" { + params["performer"] = config.Performer + } + if config.Title != "" { + params["title"] = config.Title + } + + return params, nil +} + // DocumentConfig contains information about a SendDocument request. type DocumentConfig struct { - Chattable - Fileable - ReplyToMessageID int - ReplyMarkup interface{} - UseExistingDocument bool + BaseFile + ReplyToMessageID int + ReplyMarkup interface{} } -func (config *DocumentConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config DocumentConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("document", config.FileID) if config.ReplyToMessageID != 0 {@@ -211,19 +288,35 @@ v.Add("reply_markup", string(data))
} return v, nil +} + +func (config DocumentConfig) Params() (map[string]string, error) { + params, _ := config.BaseFile.Params() + + if config.ReplyToMessageID != 0 { + params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + } + if config.ReplyMarkup != nil { + data, err := json.Marshal(config.ReplyMarkup) + if err != nil { + return params, err + } + + params["reply_markup"] = string(data) + } + + return params, nil } // StickerConfig contains information about a SendSticker request. type StickerConfig struct { - Chattable - Fileable - ReplyToMessageID int - ReplyMarkup interface{} - UseExistingSticker bool + BaseFile + ReplyToMessageID int + ReplyMarkup interface{} } -func (config *StickerConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config StickerConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("sticker", config.FileID) if config.ReplyToMessageID != 0 {@@ -241,19 +334,35 @@
return v, nil } +func (config StickerConfig) Params() (map[string]string, error) { + params, _ := config.BaseFile.Params() + + if config.ReplyToMessageID != 0 { + params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + } + if config.ReplyMarkup != nil { + data, err := json.Marshal(config.ReplyMarkup) + if err != nil { + return params, err + } + + params["reply_markup"] = string(data) + } + + return params, nil +} + // VideoConfig contains information about a SendVideo request. type VideoConfig struct { - Chattable - Fileable + BaseFile Duration int Caption string ReplyToMessageID int ReplyMarkup interface{} - UseExistingVideo bool } -func (config *VideoConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config VideoConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("video", config.FileID) if config.ReplyToMessageID != 0 {@@ -277,18 +386,34 @@
return v, nil } +func (config VideoConfig) Params() (map[string]string, error) { + params, _ := config.BaseFile.Params() + + if config.ReplyToMessageID != 0 { + params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + } + if config.ReplyMarkup != nil { + data, err := json.Marshal(config.ReplyMarkup) + if err != nil { + return params, err + } + + params["reply_markup"] = string(data) + } + + return params, nil +} + // VoiceConfig contains information about a SendVoice request. type VoiceConfig struct { - Chattable - Fileable + BaseFile Duration int ReplyToMessageID int ReplyMarkup interface{} - UseExistingVoice bool } -func (config *VoiceConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config VoiceConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("voice", config.FileID) if config.ReplyToMessageID != 0 {@@ -309,17 +434,38 @@
return v, nil } +func (config VoiceConfig) Params() (map[string]string, error) { + params, _ := config.BaseFile.Params() + + if config.ReplyToMessageID != 0 { + params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) + } + if config.Duration != 0 { + params["duration"] = strconv.Itoa(config.Duration) + } + if config.ReplyMarkup != nil { + data, err := json.Marshal(config.ReplyMarkup) + if err != nil { + return params, err + } + + params["reply_markup"] = string(data) + } + + return params, nil +} + // LocationConfig contains information about a SendLocation request. type LocationConfig struct { - Chattable + BaseChat Latitude float64 Longitude float64 ReplyToMessageID int ReplyMarkup interface{} } -func (config *LocationConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config LocationConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))@@ -341,12 +487,12 @@ }
// ChatActionConfig contains information about a SendChatAction request. type ChatActionConfig struct { - Chattable + BaseChat Action string } -func (config *ChatActionConfig) Values() (url.Values, error) { - v, _ := config.Chattable.Values() +func (config ChatActionConfig) Values() (url.Values, error) { + v, _ := config.BaseChat.Values() v.Add("action", config.Action) return v, nil }
@@ -10,7 +10,7 @@ //
// chatID is where to send it, text is the message text. func NewMessage(chatID int, text string) MessageConfig { return MessageConfig{ - Chattable: Chattable{ChatID: chatID}, + BaseChat: BaseChat{ChatID: chatID}, Text: text, DisableWebPagePreview: false, ReplyToMessageID: 0,@@ -23,7 +23,7 @@ // chatID is where to send it, fromChatID is the source chat,
// and messageID is the ID of the original message. func NewForward(chatID int, fromChatID int, messageID int) ForwardConfig { return ForwardConfig{ - Chattable: Chattable{ChatID: chatID}, + BaseChat: BaseChat{ChatID: chatID}, FromChatID: fromChatID, MessageID: messageID, }@@ -36,9 +36,7 @@ //
// chatID is where to send it, file is a string path to the file, or FileReader or FileBytes. func NewPhotoUpload(chatID int, file interface{}) PhotoConfig { return PhotoConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{File: file}, - UseExistingPhoto: false, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, File: file, UseExisting: false}, } }@@ -48,9 +46,7 @@ //
// chatID is where to send it, fileID is the ID of the file already uploaded. func NewPhotoShare(chatID int, fileID string) PhotoConfig { return PhotoConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{FileID: fileID}, - UseExistingPhoto: true, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, FileID: fileID, UseExisting: true}, } }@@ -61,9 +57,7 @@ //
// chatID is where to send it, file is a string path to the file, or FileReader or FileBytes. func NewAudioUpload(chatID int, file interface{}) AudioConfig { return AudioConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{File: file}, - UseExistingAudio: false, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, File: file, UseExisting: false}, } }@@ -73,9 +67,7 @@ //
// chatID is where to send it, fileID is the ID of the audio already uploaded. func NewAudioShare(chatID int, fileID string) AudioConfig { return AudioConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{FileID: fileID}, - UseExistingAudio: true, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, FileID: fileID, UseExisting: true}, } }@@ -86,9 +78,7 @@ //
// chatID is where to send it, file is a string path to the file, or FileReader or FileBytes. func NewDocumentUpload(chatID int, file interface{}) DocumentConfig { return DocumentConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{File: file}, - UseExistingDocument: false, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, File: file, UseExisting: false}, } }@@ -98,9 +88,7 @@ //
// chatID is where to send it, fileID is the ID of the document already uploaded. func NewDocumentShare(chatID int, fileID string) DocumentConfig { return DocumentConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{FileID: fileID}, - UseExistingDocument: true, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, FileID: fileID, UseExisting: true}, } }@@ -110,9 +98,7 @@ //
// chatID is where to send it, file is a string path to the file, or FileReader or FileBytes. func NewStickerUpload(chatID int, file interface{}) StickerConfig { return StickerConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{File: file}, - UseExistingSticker: false, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, File: file, UseExisting: false}, } }@@ -122,9 +108,7 @@ //
// chatID is where to send it, fileID is the ID of the sticker already uploaded. func NewStickerShare(chatID int, fileID string) StickerConfig { return StickerConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{FileID: fileID}, - UseExistingSticker: true, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, FileID: fileID, UseExisting: true}, } }@@ -135,9 +119,7 @@ //
// chatID is where to send it, file is a string path to the file, or FileReader or FileBytes. func NewVideoUpload(chatID int, file interface{}) VideoConfig { return VideoConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{File: file}, - UseExistingVideo: false, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, File: file, UseExisting: false}, } }@@ -147,9 +129,7 @@ //
// chatID is where to send it, fileID is the ID of the video already uploaded. func NewVideoShare(chatID int, fileID string) VideoConfig { return VideoConfig{ - Chattable: Chattable{ChatID: chatID}, - UseExistingVideo: true, - Fileable: Fileable{FileID: fileID}, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, FileID: fileID, UseExisting: true}, } }@@ -160,9 +140,7 @@ //
// chatID is where to send it, file is a string path to the file, or FileReader or FileBytes. func NewVoiceUpload(chatID int, file interface{}) VoiceConfig { return VoiceConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{File: file}, - UseExistingVoice: false, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, File: file, UseExisting: false}, } }@@ -172,9 +150,7 @@ //
// chatID is where to send it, fileID is the ID of the video already uploaded. func NewVoiceShare(chatID int, fileID string) VoiceConfig { return VoiceConfig{ - Chattable: Chattable{ChatID: chatID}, - Fileable: Fileable{FileID: fileID}, - UseExistingVoice: true, + BaseFile: BaseFile{BaseChat: BaseChat{ChatID: chatID}, FileID: fileID, UseExisting: true}, } }@@ -184,7 +160,7 @@ //
// chatID is where to send it, latitude and longitude are coordinates. func NewLocation(chatID int, latitude float64, longitude float64) LocationConfig { return LocationConfig{ - Chattable: Chattable{ChatID: chatID}, + BaseChat: BaseChat{ChatID: chatID}, Latitude: latitude, Longitude: longitude, ReplyToMessageID: 0,@@ -198,7 +174,7 @@ //
// chatID is where to send it, action should be set via CHAT constants. func NewChatAction(chatID int, action string) ChatActionConfig { return ChatActionConfig{ - Chattable: Chattable{ChatID: chatID}, + BaseChat: BaseChat{ChatID: chatID}, Action: action, } }