better comments for godoc

bot-api-6.1
Syfaro 2015-06-26 00:57:39 -05:00
parent 76460f8a5b
commit 04d46c2896
1 changed files with 53 additions and 39 deletions

View File

@ -115,8 +115,8 @@ type WebhookConfig struct {
Url *url.URL Url *url.URL
} }
// Makes a request to a specific endpoint with our token // Makes a request to a specific endpoint with our token.
// All requests are POSTs because Telegram doesn't care, and it's easier // 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) resp, err := http.PostForm("https://api.telegram.org/bot"+bot.Token+"/"+endpoint, params)
defer resp.Body.Close() defer resp.Body.Close()
@ -143,8 +143,9 @@ func (bot *BotApi) MakeRequest(endpoint string, params url.Values) (ApiResponse,
return apiResp, nil return apiResp, nil
} }
// Makes a request to the API with a file // Makes a request to the API with a file.
// Requires the parameter to hold the file not be in the params //
// 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 var b bytes.Buffer
w := multipart.NewWriter(&b) w := multipart.NewWriter(&b)
@ -203,8 +204,9 @@ func (bot *BotApi) UploadFile(endpoint string, params map[string]string, fieldna
return apiResp, nil return apiResp, nil
} }
// Fetches the currently authenticated bot // Fetches the currently authenticated bot.
// There are no parameters for this method //
// 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) resp, err := bot.MakeRequest("getMe", nil)
if err != nil { if err != nil {
@ -221,9 +223,10 @@ func (bot *BotApi) GetMe() (User, error) {
return user, nil return user, nil
} }
// Sends a Message to a chat // Sends a Message to a chat.
// Requires ChatId and Text //
// DisableWebPagePreview, ReplyToMessageId, and ReplyMarkup are optional // Requires ChatId and Text.
// DisableWebPagePreview, ReplyToMessageId, and ReplyMarkup are optional.
func (bot *BotApi) SendMessage(config MessageConfig) (Message, error) { func (bot *BotApi) SendMessage(config MessageConfig) (Message, error) {
v := url.Values{} v := url.Values{}
v.Add("chat_id", strconv.Itoa(config.ChatId)) v.Add("chat_id", strconv.Itoa(config.ChatId))
@ -257,8 +260,9 @@ func (bot *BotApi) SendMessage(config MessageConfig) (Message, error) {
return message, nil return message, nil
} }
// Forwards a message from one chat to another // Forwards a message from one chat to another.
// Requires ChatId (destionation), FromChatId (source), and MessageId //
// Requires ChatId (destionation), FromChatId (source), and MessageId.
func (bot *BotApi) ForwardMessage(config ForwardConfig) (Message, error) { func (bot *BotApi) ForwardMessage(config ForwardConfig) (Message, error) {
v := url.Values{} v := url.Values{}
v.Add("chat_id", strconv.Itoa(config.ChatId)) v.Add("chat_id", strconv.Itoa(config.ChatId))
@ -281,9 +285,10 @@ func (bot *BotApi) ForwardMessage(config ForwardConfig) (Message, error) {
return message, nil return message, nil
} }
// Sends or uploads a photo to a chat // Sends or uploads a photo to a chat.
// Requires ChatId and FileId OR FilePath //
// Caption, ReplyToMessageId, and ReplyMarkup are optional // Requires ChatId and FileId OR FilePath.
// Caption, ReplyToMessageId, and ReplyMarkup are optional.
func (bot *BotApi) SendPhoto(config PhotoConfig) (Message, error) { func (bot *BotApi) SendPhoto(config PhotoConfig) (Message, error) {
if config.UseExistingPhoto { if config.UseExistingPhoto {
v := url.Values{} v := url.Values{}
@ -352,9 +357,10 @@ func (bot *BotApi) SendPhoto(config PhotoConfig) (Message, error) {
return message, nil return message, nil
} }
// Sends or uploads an audio clip to a chat // Sends or uploads an audio clip to a chat.
// Requires ChatId and FileId OR FilePath //
// ReplyToMessageId and ReplyMarkup are optional // Requires ChatId and FileId OR FilePath.
// ReplyToMessageId and ReplyMarkup are optional.
func (bot *BotApi) SendAudio(config AudioConfig) (Message, error) { func (bot *BotApi) SendAudio(config AudioConfig) (Message, error) {
if config.UseExistingAudio { if config.UseExistingAudio {
v := url.Values{} v := url.Values{}
@ -418,9 +424,10 @@ func (bot *BotApi) SendAudio(config AudioConfig) (Message, error) {
return message, nil return message, nil
} }
// Sends or uploads a document to a chat // Sends or uploads a document to a chat.
// Requires ChatId and FileId OR FilePath //
// ReplyToMessageId and ReplyMarkup are optional // Requires ChatId and FileId OR FilePath.
// ReplyToMessageId and ReplyMarkup are optional.
func (bot *BotApi) SendDocument(config DocumentConfig) (Message, error) { func (bot *BotApi) SendDocument(config DocumentConfig) (Message, error) {
if config.UseExistingDocument { if config.UseExistingDocument {
v := url.Values{} v := url.Values{}
@ -484,9 +491,10 @@ func (bot *BotApi) SendDocument(config DocumentConfig) (Message, error) {
return message, nil return message, nil
} }
// Sends or uploads a sticker to a chat // Sends or uploads a sticker to a chat.
// Requires ChatId and FileId OR FilePath //
// ReplyToMessageId and ReplyMarkup are optional // Requires ChatId and FileId OR FilePath.
// ReplyToMessageId and ReplyMarkup are optional.
func (bot *BotApi) SendSticker(config StickerConfig) (Message, error) { func (bot *BotApi) SendSticker(config StickerConfig) (Message, error) {
if config.UseExistingSticker { if config.UseExistingSticker {
v := url.Values{} v := url.Values{}
@ -550,9 +558,10 @@ func (bot *BotApi) SendSticker(config StickerConfig) (Message, error) {
return message, nil return message, nil
} }
// Sends or uploads a video to a chat // Sends or uploads a video to a chat.
// Requires ChatId and FileId OR FilePath //
// ReplyToMessageId and ReplyMarkup are optional // Requires ChatId and FileId OR FilePath.
// ReplyToMessageId and ReplyMarkup are optional.
func (bot *BotApi) SendVideo(config VideoConfig) (Message, error) { func (bot *BotApi) SendVideo(config VideoConfig) (Message, error) {
if config.UseExistingVideo { if config.UseExistingVideo {
v := url.Values{} v := url.Values{}
@ -616,9 +625,10 @@ func (bot *BotApi) SendVideo(config VideoConfig) (Message, error) {
return message, nil return message, nil
} }
// Sends a location to a chat // Sends a location to a chat.
// Requires ChatId, Latitude, and Longitude //
// ReplyToMessageId and ReplyMarkup are optional // Requires ChatId, Latitude, and Longitude.
// ReplyToMessageId and ReplyMarkup are optional.
func (bot *BotApi) SendLocation(config LocationConfig) (Message, error) { func (bot *BotApi) SendLocation(config LocationConfig) (Message, error) {
v := url.Values{} v := url.Values{}
v.Add("chat_id", strconv.Itoa(config.ChatId)) v.Add("chat_id", strconv.Itoa(config.ChatId))
@ -652,8 +662,9 @@ func (bot *BotApi) SendLocation(config LocationConfig) (Message, error) {
return message, nil return message, nil
} }
// Sets a current action in a chat // Sets a current action in a chat.
// Requires ChatId and a valid Action (see CHAT constants) //
// Requires ChatId and a valid Action (see CHAT constants).
func (bot *BotApi) SendChatAction(config ChatActionConfig) error { func (bot *BotApi) SendChatAction(config ChatActionConfig) error {
v := url.Values{} v := url.Values{}
v.Add("chat_id", strconv.Itoa(config.ChatId)) v.Add("chat_id", strconv.Itoa(config.ChatId))
@ -667,9 +678,10 @@ func (bot *BotApi) SendChatAction(config ChatActionConfig) error {
return nil return nil
} }
// Gets a user's profile photos // Gets a user's profile photos.
// Requires UserId //
// Offset and Limit are optional // 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 := url.Values{}
v.Add("user_id", strconv.Itoa(config.UserId)) v.Add("user_id", strconv.Itoa(config.UserId))
@ -696,11 +708,12 @@ func (bot *BotApi) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro
return profilePhotos, nil return profilePhotos, nil
} }
// Fetches updates // Fetches updates.
// If a WebHook is set, this will not return any data! // If a WebHook is set, this will not return any data!
//
// Offset, Limit, and Timeout are optional. // Offset, Limit, and Timeout are optional.
// To not get old items, set Offset to one higher than the previous item // 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 // 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{} v := url.Values{}
if config.Offset > 0 { if config.Offset > 0 {
@ -728,9 +741,10 @@ func (bot *BotApi) GetUpdates(config UpdateConfig) ([]Update, error) {
return updates, nil return updates, nil
} }
// Sets a webhook // Sets a webhook.
// If this is set, GetUpdates will not get any data! // If this is set, GetUpdates will not get any data!
// Requires Url OR to set Clear to true //
// 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{} v := url.Values{}
if !config.Clear { if !config.Clear {