From 30d20b61f45f78fa256006781bd89e11edc251b6 Mon Sep 17 00:00:00 2001 From: Ahmadreza Zibaei Date: Sun, 9 Oct 2016 23:18:19 +0330 Subject: [PATCH 01/10] Caption added in Message struct --- message.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/message.go b/message.go index 88c836b..19e3cd4 100644 --- a/message.go +++ b/message.go @@ -130,6 +130,8 @@ type Message struct { MigrateFrom int64 `json:"migrate_from_chat_id"` Entities []MessageEntity `json:"entities",omitempty` + + Caption string `json:"caption",omitempty` } // Origin returns an origin of message: group chat / personal. From 08ec8d756a57134fbf80dae22a700ec2c2da3184 Mon Sep 17 00:00:00 2001 From: aiden Date: Sun, 9 Oct 2016 23:27:08 +0330 Subject: [PATCH 02/10] leaveChat method added --- bot.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/bot.go b/bot.go index b6575f4..0976468 100644 --- a/bot.go +++ b/bot.go @@ -626,7 +626,7 @@ func (b *Bot) AnswerCallbackQuery(callback *Callback, response *CallbackResponse // Usually File objects does not contain any FilePath so you need to perform additional request func (b *Bot) GetFile(fileID string) (File, error) { params := map[string]string{ - "file_id": fileID, + "file_id": fileID, } responseJSON, err := sendCommand("getFile", b.Token, params) if err != nil { @@ -651,11 +651,38 @@ func (b *Bot) GetFile(fileID string) (File, error) { return responseRecieved.Result, nil } +// Use this method for your bot to leave a group, supergroup or channel. Returns True on success. +func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { + params := map[string]string{ + "chat_id": recipient.Destination(), + } + responseJSON, err := sendCommand("leaveChat", b.Token, params) + if err != nil { + return false, err + } + + var responseRecieved struct { + Ok bool + Result bool + } + + err = json.Unmarshal(responseJSON, &responseRecieved) + if err != nil { + return false, err + } + + if !responseRecieved.Ok { + return false, fmt.Errorf("telebot: leavechat failure %s", responseRecieved.Result) + } + + return responseRecieved.Result, nil +} + // GetFileDirectURL returns direct url for files using FileId which you can get from File object func (b *Bot) GetFileDirectURL(fileID string) (string, error) { f, err := b.GetFile(fileID) if err != nil { return "", err } - return "https://api.telegram.org/file/bot"+b.Token+"/"+f.FilePath, nil + return "https://api.telegram.org/file/bot" + b.Token + "/" + f.FilePath, nil } From 936198888e2e43b599f5528acd847eced1151499 Mon Sep 17 00:00:00 2001 From: aiden Date: Sun, 9 Oct 2016 23:30:04 +0330 Subject: [PATCH 03/10] getChat method added --- bot.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index 0976468..ecabba6 100644 --- a/bot.go +++ b/bot.go @@ -672,7 +672,36 @@ func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { } if !responseRecieved.Ok { - return false, fmt.Errorf("telebot: leavechat failure %s", responseRecieved.Result) + return false, fmt.Errorf("telebot: leaveChat failure %s", responseRecieved.Result) + } + + return responseRecieved.Result, nil +} + +// Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). +// +// Returns a Chat object on success. +func (b *Bot) GetChat(recipient Recipient) (Chat, error) { + params := map[string]string{ + "chat_id": recipient.Destination(), + } + responseJSON, err := sendCommand("getChat", b.Token, params) + if err != nil { + return Chat{}, err + } + + var responseRecieved struct { + Ok bool + Result Chat + } + + err = json.Unmarshal(responseJSON, &responseRecieved) + if err != nil { + return Chat{}, err + } + + if !responseRecieved.Ok { + return Chat{}, fmt.Errorf("telebot: getChat failure %s", responseRecieved.Result) } return responseRecieved.Result, nil From d18a89193dfbfd947c7407726bac02d8077bd170 Mon Sep 17 00:00:00 2001 From: aiden Date: Sun, 9 Oct 2016 23:39:07 +0330 Subject: [PATCH 04/10] getChatAdministrators added --- bot.go | 32 ++++++++++++++++++++++++++++++++ types.go | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/bot.go b/bot.go index ecabba6..60542c0 100644 --- a/bot.go +++ b/bot.go @@ -707,6 +707,38 @@ func (b *Bot) GetChat(recipient Recipient) (Chat, error) { return responseRecieved.Result, nil } +// Use this method to get a list of administrators in a chat. +// +// On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. +// +// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. +func (b *Bot) GetChatAdministrators(recipient Recipient) ([]ChatMember, error) { + params := map[string]string{ + "chat_id": recipient.Destination(), + } + responseJSON, err := sendCommand("getChatAdministrators", b.Token, params) + if err != nil { + return []ChatMember{}, err + } + + var responseRecieved struct { + Ok bool + Result []ChatMember + Description string `json:"description",omitempty` + } + + err = json.Unmarshal(responseJSON, &responseRecieved) + if err != nil { + return []ChatMember{}, err + } + + if !responseRecieved.Ok { + return []ChatMember{}, fmt.Errorf("telebot: getChatAdministrators failure %s", responseRecieved.Description) + } + + return responseRecieved.Result, nil +} + // GetFileDirectURL returns direct url for files using FileId which you can get from File object func (b *Bot) GetFileDirectURL(fileID string) (string, error) { f, err := b.GetFile(fileID) diff --git a/types.go b/types.go index 3fc4cb1..890b990 100644 --- a/types.go +++ b/types.go @@ -223,3 +223,9 @@ type MessageEntity struct { //user Optional. For “text_mention” only, the mentioned user User User `json:"user",omitempty` } + +// This object contains information about one member of the chat. +type ChatMember struct { + User User `json:"user"` + Status string `json:"status"` +} From 229001da4a68585a13f8fb86b348d295649a2c32 Mon Sep 17 00:00:00 2001 From: aiden Date: Sun, 9 Oct 2016 23:41:23 +0330 Subject: [PATCH 05/10] getChatMemberCount added --- bot.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bot.go b/bot.go index 60542c0..6d93575 100644 --- a/bot.go +++ b/bot.go @@ -739,6 +739,36 @@ func (b *Bot) GetChatAdministrators(recipient Recipient) ([]ChatMember, error) { return responseRecieved.Result, nil } +// Use this method to get the number of members in a chat. +// +// Returns Int on success. +func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) { + params := map[string]string{ + "chat_id": recipient.Destination(), + } + responseJSON, err := sendCommand("getChatMembersCount", b.Token, params) + if err != nil { + return 0, err + } + + var responseRecieved struct { + Ok bool + Result int + Description string `json:"description",omitempty` + } + + err = json.Unmarshal(responseJSON, &responseRecieved) + if err != nil { + return 0, err + } + + if !responseRecieved.Ok { + return 0, fmt.Errorf("telebot: getChatMembersCount failure %s", responseRecieved.Description) + } + + return responseRecieved.Result, nil +} + // GetFileDirectURL returns direct url for files using FileId which you can get from File object func (b *Bot) GetFileDirectURL(fileID string) (string, error) { f, err := b.GetFile(fileID) From fc4d712ce02a40664472ccd56756a290eb8efc7e Mon Sep 17 00:00:00 2001 From: aiden Date: Sun, 9 Oct 2016 23:46:33 +0330 Subject: [PATCH 06/10] getChatMember added --- bot.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bot.go b/bot.go index 6d93575..fd1791f 100644 --- a/bot.go +++ b/bot.go @@ -769,6 +769,37 @@ func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) { return responseRecieved.Result, nil } +// Use this method to get information about a member of a chat. +// +// Returns a ChatMember object on success. +func (b *Bot) GetChatMember(recipient Recipient, user User) (ChatMember, error) { + params := map[string]string{ + "chat_id": recipient.Destination(), + "user_id": user.Destination(), + } + responseJSON, err := sendCommand("getChatMember", b.Token, params) + if err != nil { + return ChatMember{}, err + } + + var responseRecieved struct { + Ok bool + Result ChatMember + Description string `json:"description",omitempty` + } + + err = json.Unmarshal(responseJSON, &responseRecieved) + if err != nil { + return ChatMember{}, err + } + + if !responseRecieved.Ok { + return ChatMember{}, fmt.Errorf("telebot: getChatMember failure %s", responseRecieved.Description) + } + + return responseRecieved.Result, nil +} + // GetFileDirectURL returns direct url for files using FileId which you can get from File object func (b *Bot) GetFileDirectURL(fileID string) (string, error) { f, err := b.GetFile(fileID) From 2558381794dbc0545f6eee72ff455df465bbe090 Mon Sep 17 00:00:00 2001 From: aiden Date: Sun, 9 Oct 2016 23:59:03 +0330 Subject: [PATCH 07/10] GetUserProfilePhotos added --- bot.go | 30 ++++++++++++++++++++++++++++++ types.go | 12 +++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index fd1791f..961323d 100644 --- a/bot.go +++ b/bot.go @@ -769,6 +769,36 @@ func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) { return responseRecieved.Result, nil } +// Use this method to get a list of profile pictures for a user. +// +// Returns a UserProfilePhotos object. +func (b *Bot) GetUserProfilePhotos(recipient Recipient) (UserProfilePhotos, error) { + params := map[string]string{ + "user_id": recipient.Destination(), + } + responseJSON, err := sendCommand("getUserProfilePhotos", b.Token, params) + if err != nil { + return UserProfilePhotos{}, err + } + + var responseRecieved struct { + Ok bool + Result UserProfilePhotos + Description string `json:"description",omitempty` + } + + err = json.Unmarshal(responseJSON, &responseRecieved) + if err != nil { + return UserProfilePhotos{}, err + } + + if !responseRecieved.Ok { + return UserProfilePhotos{}, fmt.Errorf("telebot: getUserProfilePhotos failure %s", responseRecieved.Description) + } + + return responseRecieved.Result, nil +} + // Use this method to get information about a member of a chat. // // Returns a ChatMember object on success. diff --git a/types.go b/types.go index 890b990..67c9104 100644 --- a/types.go +++ b/types.go @@ -224,8 +224,18 @@ type MessageEntity struct { User User `json:"user",omitempty` } -// This object contains information about one member of the chat. +// This struct contains information about one member of the chat. type ChatMember struct { User User `json:"user"` Status string `json:"status"` } + +// This struct represent a user's profile pictures. +// +// Count : Total number of profile pictures the target user has +// +// Photos : Array of Array of PhotoSize , Requested profile pictures (in up to 4 sizes each) +type UserProfilePhotos struct { + Count int `json:"total_count"` + Photos [][]Photo `json:"photos"` +} From 5d1a071046b6979f1623690aa7206fb80427f551 Mon Sep 17 00:00:00 2001 From: aiden Date: Mon, 10 Oct 2016 00:12:07 +0330 Subject: [PATCH 08/10] Some changes for godoc --- bot.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bot.go b/bot.go index 961323d..b6da3ce 100644 --- a/bot.go +++ b/bot.go @@ -678,7 +678,9 @@ func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { return responseRecieved.Result, nil } -// Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). +// Use this method to get up to date information +// about the chat (current name of the user for one-on-one +// conversations, current username of a user, group or channel, etc.). // // Returns a Chat object on success. func (b *Bot) GetChat(recipient Recipient) (Chat, error) { @@ -709,9 +711,11 @@ func (b *Bot) GetChat(recipient Recipient) (Chat, error) { // Use this method to get a list of administrators in a chat. // -// On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. +// On success, returns an Array of ChatMember objects that +// contains information about all chat administrators except other bots. // -// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. +// If the chat is a group or a supergroup and +// no administrators were appointed, only the creator will be returned. func (b *Bot) GetChatAdministrators(recipient Recipient) ([]ChatMember, error) { params := map[string]string{ "chat_id": recipient.Destination(), From e5cf14aeea6b03fa41a5328ffbf95d5bb2cc3768 Mon Sep 17 00:00:00 2001 From: aiden Date: Fri, 14 Oct 2016 18:31:45 +0330 Subject: [PATCH 09/10] Method name and structs specified. --- bot.go | 12 ++++++------ types.go | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bot.go b/bot.go index b6da3ce..93a2d98 100644 --- a/bot.go +++ b/bot.go @@ -651,7 +651,7 @@ func (b *Bot) GetFile(fileID string) (File, error) { return responseRecieved.Result, nil } -// Use this method for your bot to leave a group, supergroup or channel. Returns True on success. +// LeaveChat , Use this method for your bot to leave a group, supergroup or channel. Returns True on success. func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { params := map[string]string{ "chat_id": recipient.Destination(), @@ -678,7 +678,7 @@ func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { return responseRecieved.Result, nil } -// Use this method to get up to date information +// GetChat get up to date information // about the chat (current name of the user for one-on-one // conversations, current username of a user, group or channel, etc.). // @@ -709,7 +709,7 @@ func (b *Bot) GetChat(recipient Recipient) (Chat, error) { return responseRecieved.Result, nil } -// Use this method to get a list of administrators in a chat. +// GetChatAdministrators return list of administrators in a chat. // // On success, returns an Array of ChatMember objects that // contains information about all chat administrators except other bots. @@ -743,7 +743,7 @@ func (b *Bot) GetChatAdministrators(recipient Recipient) ([]ChatMember, error) { return responseRecieved.Result, nil } -// Use this method to get the number of members in a chat. +// GetChatMembersCount return the number of members in a chat. // // Returns Int on success. func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) { @@ -773,7 +773,7 @@ func (b *Bot) GetChatMembersCount(recipient Recipient) (int, error) { return responseRecieved.Result, nil } -// Use this method to get a list of profile pictures for a user. +// GetUserProfilePhotos return list of profile pictures for a user. // // Returns a UserProfilePhotos object. func (b *Bot) GetUserProfilePhotos(recipient Recipient) (UserProfilePhotos, error) { @@ -803,7 +803,7 @@ func (b *Bot) GetUserProfilePhotos(recipient Recipient) (UserProfilePhotos, erro return responseRecieved.Result, nil } -// Use this method to get information about a member of a chat. +// GetChatMember return information about a member of a chat. // // Returns a ChatMember object on success. func (b *Bot) GetChatMember(recipient Recipient, user User) (ChatMember, error) { diff --git a/types.go b/types.go index 67c9104..d297656 100644 --- a/types.go +++ b/types.go @@ -224,12 +224,14 @@ type MessageEntity struct { User User `json:"user",omitempty` } +// ChatMember , // This struct contains information about one member of the chat. type ChatMember struct { User User `json:"user"` Status string `json:"status"` } +// UserProfilePhotos , // This struct represent a user's profile pictures. // // Count : Total number of profile pictures the target user has From 622415d1382513e2078c1e34e8246a017ca13cd8 Mon Sep 17 00:00:00 2001 From: ahmdrz Date: Sat, 15 Oct 2016 10:52:58 +0330 Subject: [PATCH 10/10] LeaveChat boolean result removed --- bot.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index 93a2d98..c5f49b0 100644 --- a/bot.go +++ b/bot.go @@ -652,13 +652,13 @@ func (b *Bot) GetFile(fileID string) (File, error) { } // LeaveChat , Use this method for your bot to leave a group, supergroup or channel. Returns True on success. -func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { +func (b *Bot) LeaveChat(recipient Recipient) error { params := map[string]string{ "chat_id": recipient.Destination(), } responseJSON, err := sendCommand("leaveChat", b.Token, params) if err != nil { - return false, err + return err } var responseRecieved struct { @@ -668,14 +668,14 @@ func (b *Bot) LeaveChat(recipient Recipient) (bool, error) { err = json.Unmarshal(responseJSON, &responseRecieved) if err != nil { - return false, err + return err } if !responseRecieved.Ok { - return false, fmt.Errorf("telebot: leaveChat failure %s", responseRecieved.Result) + return fmt.Errorf("telebot: leaveChat failure %s", responseRecieved.Result) } - return responseRecieved.Result, nil + return nil } // GetChat get up to date information