forked from max-messenger/max-bot-api-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbots.go
More file actions
48 lines (37 loc) · 1.25 KB
/
bots.go
File metadata and controls
48 lines (37 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package maxbot
import (
"context"
"net/http"
"net/url"
jsoniter "github.com/json-iterator/go"
"github.com/max-messenger/max-bot-api-client-go/schemes"
)
type bots struct {
client *client
}
func newBots(client *client) *bots {
return &bots{client: client}
}
// GetBot returns info about current bot.
// Current bot can be identified by access token. Method returns bot identifier, name and avatar (if any).
func (a *bots) GetBot(ctx context.Context) (*schemes.BotInfo, error) {
result := new(schemes.BotInfo)
values := url.Values{}
body, err := a.client.request(ctx, http.MethodGet, pathMe, values, false, nil)
if err != nil {
return result, err
}
defer a.client.closer("getBoy body", body)
return result, jsoniter.NewDecoder(body).Decode(result)
}
// PatchBot edits current bot info. Fill only the fields you want to update. All remaining fields will stay untouched.
func (a *bots) PatchBot(ctx context.Context, patch *schemes.BotPatch) (*schemes.BotInfo, error) {
result := new(schemes.BotInfo)
values := url.Values{}
body, err := a.client.request(ctx, http.MethodPatch, pathMe, values, false, patch)
if err != nil {
return result, err
}
defer a.client.closer("patch body", body)
return result, jsoniter.NewDecoder(body).Decode(result)
}