|
|
@ -188,12 +188,15 @@ func (bot *BotAPI) ForwardMessage(config ForwardConfig) (Message, error) { |
|
|
|
//
|
|
|
|
//
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
// Caption, ReplyToMessageID, and ReplyMarkup are optional.
|
|
|
|
// Caption, ReplyToMessageID, and ReplyMarkup are optional.
|
|
|
|
func (bot *BotAPI) SendPhoto(config PhotoConfig) (Message, error) { |
|
|
|
func (bot *BotAPI) SendFile(config FileConfig) (Message, error) { |
|
|
|
|
|
|
|
if !config.FileType.ValidFileType() { |
|
|
|
|
|
|
|
return Message{}, errors.New("Invalid file type.") |
|
|
|
|
|
|
|
} |
|
|
|
if config.UseExistingPhoto { |
|
|
|
if config.UseExistingPhoto { |
|
|
|
v := url.Values{} |
|
|
|
v := url.Values{} |
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
v.Add("photo", config.FileID) |
|
|
|
v.Add(config.FileType, config.FileID) |
|
|
|
if config.Caption != "" { |
|
|
|
if config.FileType == "photo" && config.Caption != "" { |
|
|
|
v.Add("caption", config.Caption) |
|
|
|
v.Add("caption", config.Caption) |
|
|
|
} |
|
|
|
} |
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
@ -256,275 +259,6 @@ func (bot *BotAPI) SendPhoto(config PhotoConfig) (Message, error) { |
|
|
|
return message, nil |
|
|
|
return message, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SendAudio sends or uploads an audio clip to a chat.
|
|
|
|
|
|
|
|
// If using a file, the file must be encoded as an .ogg with OPUS.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
|
|
|
|
// ReplyToMessageID and ReplyMarkup are optional.
|
|
|
|
|
|
|
|
func (bot *BotAPI) SendAudio(config AudioConfig) (Message, error) { |
|
|
|
|
|
|
|
if config.UseExistingAudio { |
|
|
|
|
|
|
|
v := url.Values{} |
|
|
|
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
|
|
|
v.Add("audio", config.FileID) |
|
|
|
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v.Add("reply_markup", string(data)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.MakeRequest("sendAudio", v) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendAudio req : %+v\n", v) |
|
|
|
|
|
|
|
log.Printf("sendAudio resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params := make(map[string]string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params["chat_id"] = strconv.Itoa(config.ChatID) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.UploadFile("sendAudio", params, "audio", config.FilePath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendAudio resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SendDocument sends or uploads a document to a chat.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
|
|
|
|
// ReplyToMessageID and ReplyMarkup are optional.
|
|
|
|
|
|
|
|
func (bot *BotAPI) SendDocument(config DocumentConfig) (Message, error) { |
|
|
|
|
|
|
|
if config.UseExistingDocument { |
|
|
|
|
|
|
|
v := url.Values{} |
|
|
|
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
|
|
|
v.Add("document", config.FileID) |
|
|
|
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v.Add("reply_markup", string(data)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.MakeRequest("sendDocument", v) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendDocument req : %+v\n", v) |
|
|
|
|
|
|
|
log.Printf("sendDocument resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params := make(map[string]string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params["chat_id"] = strconv.Itoa(config.ChatID) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.UploadFile("sendDocument", params, "document", config.FilePath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendDocument resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SendSticker sends or uploads a sticker to a chat.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
|
|
|
|
// ReplyToMessageID and ReplyMarkup are optional.
|
|
|
|
|
|
|
|
func (bot *BotAPI) SendSticker(config StickerConfig) (Message, error) { |
|
|
|
|
|
|
|
if config.UseExistingSticker { |
|
|
|
|
|
|
|
v := url.Values{} |
|
|
|
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
|
|
|
v.Add("sticker", config.FileID) |
|
|
|
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v.Add("reply_markup", string(data)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.MakeRequest("sendSticker", v) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendSticker req : %+v\n", v) |
|
|
|
|
|
|
|
log.Printf("sendSticker resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params := make(map[string]string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params["chat_id"] = strconv.Itoa(config.ChatID) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.UploadFile("sendSticker", params, "sticker", config.FilePath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendSticker resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SendVideo sends or uploads a video to a chat.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
|
|
|
|
// ReplyToMessageID and ReplyMarkup are optional.
|
|
|
|
|
|
|
|
func (bot *BotAPI) SendVideo(config VideoConfig) (Message, error) { |
|
|
|
|
|
|
|
if config.UseExistingVideo { |
|
|
|
|
|
|
|
v := url.Values{} |
|
|
|
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
|
|
|
v.Add("video", config.FileID) |
|
|
|
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v.Add("reply_markup", string(data)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.MakeRequest("sendVideo", v) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendVideo req : %+v\n", v) |
|
|
|
|
|
|
|
log.Printf("sendVideo resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params := make(map[string]string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
params["chat_id"] = strconv.Itoa(config.ChatID) |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp, err := bot.UploadFile("sendVideo", params, "video", config.FilePath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return Message{}, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var message Message |
|
|
|
|
|
|
|
json.Unmarshal(resp.Result, &message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
|
|
|
log.Printf("sendVideo resp: %+v\n", message) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return message, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SendLocation sends a location to a chat.
|
|
|
|
// SendLocation sends a location to a chat.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Requires ChatID, Latitude, and Longitude.
|
|
|
|
// Requires ChatID, Latitude, and Longitude.
|
|
|
|