all repos — telegram-bot-api @ 224e585bd97ba06daa9ab566d6b277385b1bd3ae

Golang bindings for the Telegram Bot API

all API methods
Syfaro syfaro@foxpaw.in
Thu, 25 Jun 2015 11:50:24 -0500
commit

224e585bd97ba06daa9ab566d6b277385b1bd3ae

parent

059baffbfbf2683405ac97a06a3592a203ed5a57

1 files changed, 216 insertions(+), 0 deletions(-)

jump to
M methods.gomethods.go

@@ -250,6 +250,195 @@

return message, nil } +func (bot *BotApi) sendDocument(config DocumentConfig) (Message, error) { + if config.UseExitingDocument { + 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.config.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.config.debug { + log.Printf("sendDocument resp: %+v\n", message) + } + + return message, nil +} + +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.config.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.config.debug { + log.Printf("sendSticker resp: %+v\n", message) + } + + return message, nil +} + +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.config.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.config.debug { + log.Printf("sendVideo resp: %+v\n", message) + } + + return message, nil +} + func (bot *BotApi) sendLocation(config LocationConfig) (Message, error) { v := url.Values{} v.Add("chat_id", strconv.Itoa(config.ChatId))

@@ -380,6 +569,33 @@ Caption string

ReplyToMessageId int ReplyMarkup interface{} UseExistingPhoto bool + FilePath string + FileId string +} + +type DocumentConfig struct { + ChatId int + ReplyToMessageId int + ReplyMarkup interface{} + UseExitingDocument bool + FilePath string + FileId string +} + +type StickerConfig struct { + ChatId int + ReplyToMessageId int + ReplyMarkup interface{} + UseExistingSticker bool + FilePath string + FileId string +} + +type VideoConfig struct { + ChatId int + ReplyToMessageId int + ReplyMarkup interface{} + UseExistingVideo bool FilePath string FileId string }