Skip to content

Commit 85dc8eb

Browse files
get chat admins
1 parent 25fe244 commit 85dc8eb

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

chat.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ type Chat struct {
1515
// Is this chat public?
1616
Public bool `json:"public"`
1717

18+
Group string `json:"group"`
19+
1820
// You can send this link to all your friends
1921
InviteLink string `json:"inviteLink"`
20-
}
2122

22-
func (c *Chat) Init() error {
23-
return nil
23+
Admins []Contact `json:"admins"`
2424
}
25+

client.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,36 @@ func (c *Client) GetInfo() (*BotInfo, error) {
118118
return info, nil
119119
}
120120

121+
func (c *Client) GetChatInfo(chatId string) (*Chat, error) {
122+
params := url.Values{
123+
"chatId": {chatId},
124+
}
125+
response, err := c.Do("/chats/getInfo", params, nil)
126+
if err != nil {
127+
return nil, fmt.Errorf("error while receiving information: %s", err)
128+
}
129+
130+
chat := &Chat{}
131+
if err := json.Unmarshal(response, chat); err != nil {
132+
return nil, fmt.Errorf("error while unmarshalling information: %s", err)
133+
}
134+
135+
if chat.Group != "group" {
136+
return chat, nil
137+
}
138+
139+
response, err = c.Do("/chats/getAdmins", params, nil)
140+
if err != nil {
141+
return nil, fmt.Errorf("error while receiving admins: %s", err)
142+
}
143+
144+
if err := json.Unmarshal(response, chat); err != nil {
145+
return nil, fmt.Errorf("error while unmarshalling admins: %s", err)
146+
}
147+
148+
return chat, nil
149+
}
150+
121151
func (c *Client) SendMessage(message *Message) error {
122152
params := url.Values{
123153
"chatId": []string{message.Chat.ID},
@@ -180,7 +210,7 @@ func (c *Client) SendFile(message *Message) error {
180210
params := url.Values{
181211
"chatId": {message.Chat.ID},
182212
"caption": {message.Text},
183-
"fileId": {message.FileID},
213+
"fileId": {message.FileID},
184214
}
185215

186216
response, err := c.Do("/messages/sendFile", params, nil)

message.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ type Message struct {
4242
Timestamp int `json:"timestamp"`
4343
}
4444

45+
func (m *Message) AttachFile(file *os.File) {
46+
m.File = file
47+
}
48+
4549
// Send method sends your message.
4650
// Make sure you have Text or FileID in your message.
4751
func (m *Message) Send() error {

0 commit comments

Comments
 (0)