|
|
|
@ -14,163 +14,176 @@ import ( |
|
|
|
|
"strconv" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Constant values for ChatActions
|
|
|
|
|
const ( |
|
|
|
|
CHAT_TYPING = "typing" |
|
|
|
|
CHAT_UPLOAD_PHOTO = "upload_photo" |
|
|
|
|
CHAT_RECORD_VIDEO = "record_video" |
|
|
|
|
CHAT_UPLOAD_VIDEO = "upload_video" |
|
|
|
|
CHAT_RECORD_AUDIO = "record_audio" |
|
|
|
|
CHAT_UPLOAD_AUDIO = "upload_audio" |
|
|
|
|
CHAT_UPLOAD_DOCUMENT = "upload_document" |
|
|
|
|
CHAT_FIND_LOCATION = "find_location" |
|
|
|
|
ChatTyping = "typing" |
|
|
|
|
ChatUploadPhoto = "upload_photo" |
|
|
|
|
ChatRecordVideo = "record_video" |
|
|
|
|
ChatUploadVideo = "upload_video" |
|
|
|
|
ChatRecordAudio = "record_audio" |
|
|
|
|
ChatUploadAudio = "upload_audio" |
|
|
|
|
ChatUploadDocument = "upload_document" |
|
|
|
|
ChatFindLocation = "find_location" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// MessageConfig contains information about a SendMessage request.
|
|
|
|
|
type MessageConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ChatID int |
|
|
|
|
Text string |
|
|
|
|
DisableWebPagePreview bool |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ForwardConfig contains infomation about a ForwardMessage request.
|
|
|
|
|
type ForwardConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
FromChatId int |
|
|
|
|
MessageId int |
|
|
|
|
ChatID int |
|
|
|
|
FromChatID int |
|
|
|
|
MessageID int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// PhotoConfig contains information about a SendPhoto request.
|
|
|
|
|
type PhotoConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ChatID int |
|
|
|
|
Caption string |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
UseExistingPhoto bool |
|
|
|
|
FilePath string |
|
|
|
|
FileId string |
|
|
|
|
FileID string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// AudioConfig contains information about a SendAudio request.
|
|
|
|
|
type AudioConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ChatID int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
UseExistingAudio bool |
|
|
|
|
FilePath string |
|
|
|
|
FileId string |
|
|
|
|
FileID string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DocumentConfig contains information about a SendDocument request.
|
|
|
|
|
type DocumentConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ChatID int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
UseExistingDocument bool |
|
|
|
|
FilePath string |
|
|
|
|
FileId string |
|
|
|
|
FileID string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// StickerConfig contains information about a SendSticker request.
|
|
|
|
|
type StickerConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ChatID int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
UseExistingSticker bool |
|
|
|
|
FilePath string |
|
|
|
|
FileId string |
|
|
|
|
FileID string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// VideoConfig contains information about a SendVideo request.
|
|
|
|
|
type VideoConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ChatID int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
UseExistingVideo bool |
|
|
|
|
FilePath string |
|
|
|
|
FileId string |
|
|
|
|
FileID string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LocationConfig contains information about a SendLocation request.
|
|
|
|
|
type LocationConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ChatID int |
|
|
|
|
Latitude float64 |
|
|
|
|
Longitude float64 |
|
|
|
|
ReplyToMessageId int |
|
|
|
|
ReplyToMessageID int |
|
|
|
|
ReplyMarkup interface{} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ChatActionConfig contains information about a SendChatAction request.
|
|
|
|
|
type ChatActionConfig struct { |
|
|
|
|
ChatId int |
|
|
|
|
ChatID int |
|
|
|
|
Action string |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// UserProfilePhotosConfig contains information about a GetUserProfilePhotos request.
|
|
|
|
|
type UserProfilePhotosConfig struct { |
|
|
|
|
UserId int |
|
|
|
|
UserID int |
|
|
|
|
Offset int |
|
|
|
|
Limit int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// UpdateConfig contains information about a GetUpdates request.
|
|
|
|
|
type UpdateConfig struct { |
|
|
|
|
Offset int |
|
|
|
|
Limit int |
|
|
|
|
Timeout int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// WebhookConfig contains information about a SetWebhook request.
|
|
|
|
|
type WebhookConfig struct { |
|
|
|
|
Clear bool |
|
|
|
|
Url *url.URL |
|
|
|
|
URL *url.URL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Makes a request to a specific endpoint with our token.
|
|
|
|
|
// MakeRequest makes a request to a specific endpoint with our token.
|
|
|
|
|
// All requests are POSTs because Telegram doesn't care, and it's easier.
|
|
|
|
|
func (bot *BotApi) MakeRequest(endpoint string, params url.Values) (ApiResponse, error) { |
|
|
|
|
func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) { |
|
|
|
|
resp, err := http.PostForm("https://api.telegram.org/bot"+bot.Token+"/"+endpoint, params) |
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bytes, err := ioutil.ReadAll(resp.Body) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
log.Println(endpoint, string(bytes)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var apiResp ApiResponse |
|
|
|
|
var apiResp APIResponse |
|
|
|
|
json.Unmarshal(bytes, &apiResp) |
|
|
|
|
|
|
|
|
|
if !apiResp.Ok { |
|
|
|
|
return ApiResponse{}, errors.New(apiResp.Description) |
|
|
|
|
return APIResponse{}, errors.New(apiResp.Description) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return apiResp, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Makes a request to the API with a file.
|
|
|
|
|
// UploadFile makes a request to the API with a file.
|
|
|
|
|
//
|
|
|
|
|
// Requires the parameter to hold the file not be in the params.
|
|
|
|
|
func (bot *BotApi) UploadFile(endpoint string, params map[string]string, fieldname string, filename string) (ApiResponse, error) { |
|
|
|
|
func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldname string, filename string) (APIResponse, error) { |
|
|
|
|
var b bytes.Buffer |
|
|
|
|
w := multipart.NewWriter(&b) |
|
|
|
|
|
|
|
|
|
f, err := os.Open(filename) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fw, err := w.CreateFormFile(fieldname, filename) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if _, err = io.Copy(fw, f); err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for key, val := range params { |
|
|
|
|
if fw, err = w.CreateFormField(key); err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if _, err = fw.Write([]byte(val)); err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -178,7 +191,7 @@ func (bot *BotApi) UploadFile(endpoint string, params map[string]string, fieldna |
|
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", "https://api.telegram.org/bot"+bot.Token+"/"+endpoint, &b) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
req.Header.Set("Content-Type", w.FormDataContentType()) |
|
|
|
@ -186,28 +199,28 @@ func (bot *BotApi) UploadFile(endpoint string, params map[string]string, fieldna |
|
|
|
|
client := &http.Client{} |
|
|
|
|
res, err := client.Do(req) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bytes, err := ioutil.ReadAll(res.Body) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiResponse{}, err |
|
|
|
|
return APIResponse{}, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if bot.Debug { |
|
|
|
|
log.Println(string(bytes[:])) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var apiResp ApiResponse |
|
|
|
|
var apiResp APIResponse |
|
|
|
|
json.Unmarshal(bytes, &apiResp) |
|
|
|
|
|
|
|
|
|
return apiResp, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Fetches the currently authenticated bot.
|
|
|
|
|
// GetMe fetches the currently authenticated bot.
|
|
|
|
|
//
|
|
|
|
|
// There are no parameters for this method.
|
|
|
|
|
func (bot *BotApi) GetMe() (User, error) { |
|
|
|
|
func (bot *BotAPI) GetMe() (User, error) { |
|
|
|
|
resp, err := bot.MakeRequest("getMe", nil) |
|
|
|
|
if err != nil { |
|
|
|
|
return User{}, err |
|
|
|
@ -223,17 +236,17 @@ func (bot *BotApi) GetMe() (User, error) { |
|
|
|
|
return user, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends a Message to a chat.
|
|
|
|
|
// 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) { |
|
|
|
|
// Requires ChatID and Text.
|
|
|
|
|
// DisableWebPagePreview, ReplyToMessageID, and ReplyMarkup are optional.
|
|
|
|
|
func (bot *BotAPI) SendMessage(config MessageConfig) (Message, error) { |
|
|
|
|
v := url.Values{} |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatId)) |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
v.Add("text", config.Text) |
|
|
|
|
v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview)) |
|
|
|
|
if config.ReplyToMessageId != 0 { |
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageId)) |
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID)) |
|
|
|
|
} |
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
@ -260,14 +273,14 @@ func (bot *BotApi) SendMessage(config MessageConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Forwards a message from one chat to another.
|
|
|
|
|
// ForwardMessage forwards a message from one chat to another.
|
|
|
|
|
//
|
|
|
|
|
// Requires ChatId (destionation), FromChatId (source), and MessageId.
|
|
|
|
|
func (bot *BotApi) ForwardMessage(config ForwardConfig) (Message, error) { |
|
|
|
|
// Requires ChatID (destionation), FromChatID (source), and MessageID.
|
|
|
|
|
func (bot *BotAPI) ForwardMessage(config ForwardConfig) (Message, error) { |
|
|
|
|
v := url.Values{} |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatId)) |
|
|
|
|
v.Add("from_chat_id", strconv.Itoa(config.FromChatId)) |
|
|
|
|
v.Add("message_id", strconv.Itoa(config.MessageId)) |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
v.Add("from_chat_id", strconv.Itoa(config.FromChatID)) |
|
|
|
|
v.Add("message_id", strconv.Itoa(config.MessageID)) |
|
|
|
|
|
|
|
|
|
resp, err := bot.MakeRequest("forwardMessage", v) |
|
|
|
|
if err != nil { |
|
|
|
@ -285,20 +298,20 @@ func (bot *BotApi) ForwardMessage(config ForwardConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends or uploads a photo to a chat.
|
|
|
|
|
// SendPhoto sends or uploads a photo to a chat.
|
|
|
|
|
//
|
|
|
|
|
// Requires ChatId and FileId OR FilePath.
|
|
|
|
|
// Caption, ReplyToMessageId, and ReplyMarkup are optional.
|
|
|
|
|
func (bot *BotApi) SendPhoto(config PhotoConfig) (Message, error) { |
|
|
|
|
// Requires ChatID and FileID OR FilePath.
|
|
|
|
|
// Caption, ReplyToMessageID, and ReplyMarkup are optional.
|
|
|
|
|
func (bot *BotAPI) SendPhoto(config PhotoConfig) (Message, error) { |
|
|
|
|
if config.UseExistingPhoto { |
|
|
|
|
v := url.Values{} |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatId)) |
|
|
|
|
v.Add("photo", config.FileId) |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
v.Add("photo", config.FileID) |
|
|
|
|
if config.Caption != "" { |
|
|
|
|
v.Add("caption", config.Caption) |
|
|
|
|
} |
|
|
|
|
if config.ReplyToMessageId != 0 { |
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ChatId)) |
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
} |
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
@ -326,12 +339,12 @@ func (bot *BotApi) SendPhoto(config PhotoConfig) (Message, error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
params := make(map[string]string) |
|
|
|
|
params["chat_id"] = strconv.Itoa(config.ChatId) |
|
|
|
|
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.ReplyToMessageID != 0 { |
|
|
|
|
params["reply_to_message_id"] = strconv.Itoa(config.ReplyToMessageID) |
|
|
|
|
} |
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
@ -357,17 +370,18 @@ func (bot *BotApi) SendPhoto(config PhotoConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends or uploads an audio clip to a chat.
|
|
|
|
|
// 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) { |
|
|
|
|
// 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)) |
|
|
|
|
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) |
|
|
|
@ -396,9 +410,9 @@ func (bot *BotApi) SendAudio(config AudioConfig) (Message, error) { |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
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) |
|
|
|
@ -424,17 +438,17 @@ func (bot *BotApi) SendAudio(config AudioConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends or uploads a document to a chat.
|
|
|
|
|
// 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) { |
|
|
|
|
// 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)) |
|
|
|
|
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) |
|
|
|
@ -463,9 +477,9 @@ func (bot *BotApi) SendDocument(config DocumentConfig) (Message, error) { |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
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) |
|
|
|
@ -491,17 +505,17 @@ func (bot *BotApi) SendDocument(config DocumentConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends or uploads a sticker to a chat.
|
|
|
|
|
// 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) { |
|
|
|
|
// 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)) |
|
|
|
|
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) |
|
|
|
@ -530,9 +544,9 @@ func (bot *BotApi) SendSticker(config StickerConfig) (Message, error) { |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
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) |
|
|
|
@ -558,17 +572,17 @@ func (bot *BotApi) SendSticker(config StickerConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends or uploads a video to a chat.
|
|
|
|
|
// 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) { |
|
|
|
|
// 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)) |
|
|
|
|
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) |
|
|
|
@ -597,9 +611,9 @@ func (bot *BotApi) SendVideo(config VideoConfig) (Message, error) { |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
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) |
|
|
|
@ -625,17 +639,17 @@ func (bot *BotApi) SendVideo(config VideoConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sends a location to a chat.
|
|
|
|
|
// 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) { |
|
|
|
|
// Requires ChatID, Latitude, and Longitude.
|
|
|
|
|
// ReplyToMessageID and ReplyMarkup are optional.
|
|
|
|
|
func (bot *BotAPI) SendLocation(config LocationConfig) (Message, error) { |
|
|
|
|
v := url.Values{} |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatId)) |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64)) |
|
|
|
|
v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64)) |
|
|
|
|
if config.ReplyToMessageId != 0 { |
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageId)) |
|
|
|
|
if config.ReplyToMessageID != 0 { |
|
|
|
|
v.Add("reply_to_message_id", strconv.Itoa(config.ReplyToMessageID)) |
|
|
|
|
} |
|
|
|
|
if config.ReplyMarkup != nil { |
|
|
|
|
data, err := json.Marshal(config.ReplyMarkup) |
|
|
|
@ -662,12 +676,12 @@ func (bot *BotApi) SendLocation(config LocationConfig) (Message, error) { |
|
|
|
|
return message, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sets a current action in a chat.
|
|
|
|
|
// SendChatAction sets a current action in a chat.
|
|
|
|
|
//
|
|
|
|
|
// Requires ChatId and a valid Action (see CHAT constants).
|
|
|
|
|
func (bot *BotApi) SendChatAction(config ChatActionConfig) error { |
|
|
|
|
// Requires ChatID and a valid Action (see Chat constants).
|
|
|
|
|
func (bot *BotAPI) SendChatAction(config ChatActionConfig) error { |
|
|
|
|
v := url.Values{} |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatId)) |
|
|
|
|
v.Add("chat_id", strconv.Itoa(config.ChatID)) |
|
|
|
|
v.Add("action", config.Action) |
|
|
|
|
|
|
|
|
|
_, err := bot.MakeRequest("sendChatAction", v) |
|
|
|
@ -678,13 +692,13 @@ func (bot *BotApi) SendChatAction(config ChatActionConfig) error { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Gets a user's profile photos.
|
|
|
|
|
// GetUserProfilePhotos gets a user's profile photos.
|
|
|
|
|
//
|
|
|
|
|
// Requires UserId.
|
|
|
|
|
// Requires UserID.
|
|
|
|
|
// Offset and Limit are optional.
|
|
|
|
|
func (bot *BotApi) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error) { |
|
|
|
|
func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserProfilePhotos, error) { |
|
|
|
|
v := url.Values{} |
|
|
|
|
v.Add("user_id", strconv.Itoa(config.UserId)) |
|
|
|
|
v.Add("user_id", strconv.Itoa(config.UserID)) |
|
|
|
|
if config.Offset != 0 { |
|
|
|
|
v.Add("offset", strconv.Itoa(config.Offset)) |
|
|
|
|
} |
|
|
|
@ -708,13 +722,13 @@ func (bot *BotApi) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro |
|
|
|
|
return profilePhotos, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Fetches updates.
|
|
|
|
|
// GetUpdates fetches updates.
|
|
|
|
|
// If a WebHook is set, this will not return any data!
|
|
|
|
|
//
|
|
|
|
|
// Offset, Limit, and Timeout are optional.
|
|
|
|
|
// To not get old items, set Offset to one higher than the previous item.
|
|
|
|
|
// Set Timeout to a large number to reduce requests and get responses instantly.
|
|
|
|
|
func (bot *BotApi) GetUpdates(config UpdateConfig) ([]Update, error) { |
|
|
|
|
func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) { |
|
|
|
|
v := url.Values{} |
|
|
|
|
if config.Offset > 0 { |
|
|
|
|
v.Add("offset", strconv.Itoa(config.Offset)) |
|
|
|
@ -741,14 +755,14 @@ func (bot *BotApi) GetUpdates(config UpdateConfig) ([]Update, error) { |
|
|
|
|
return updates, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sets a webhook.
|
|
|
|
|
// SetWebhook sets a webhook.
|
|
|
|
|
// If this is set, GetUpdates will not get any data!
|
|
|
|
|
//
|
|
|
|
|
// Requires Url OR to set Clear to true.
|
|
|
|
|
func (bot *BotApi) SetWebhook(config WebhookConfig) error { |
|
|
|
|
func (bot *BotAPI) SetWebhook(config WebhookConfig) error { |
|
|
|
|
v := url.Values{} |
|
|
|
|
if !config.Clear { |
|
|
|
|
v.Add("url", config.Url.String()) |
|
|
|
|
v.Add("url", config.URL.String()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, err := bot.MakeRequest("setWebhook", v) |
|
|
|
|