Skip to content

Commit

Permalink
getChatAdministrators added
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdrz committed Oct 9, 2016
1 parent 9361988 commit d18a891
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit d18a891

Please sign in to comment.