Debian Codegraph @

bots.go

raw symbols SCIP
1 package slack
2
3 import (
4 "context"
5 "net/url"
6 )
7
8 // Bot contains information about a bot
9 type Bot struct {
10 ID string `json:"id"`
11 Name string `json:"name"`
12 Deleted bool `json:"deleted"`
13 UserID string `json:"user_id"`
14 AppID string `json:"app_id"`
15 Updated JSONTime `json:"updated"`
16 Icons Icons `json:"icons"`
17 }
18
19 type botResponseFull struct {
20 Bot `json:"bot,omitempty"` // GetBotInfo
21 SlackResponse
22 }
23
24 func (api *Client) botRequest(ctx context.Context, path string, values url.Values) (*botResponseFull, error) {
25 response := &botResponseFull{}
26 err := api.postMethod(ctx, path, values, response)
27 if err != nil {
28 return nil, err
29 }
30
31 if err := response.Err(); err != nil {
32 return nil, err
33 }
34
35 return response, nil
36 }
37
38 // GetBotInfo will retrieve the complete bot information
39 func (api *Client) GetBotInfo(bot string) (*Bot, error) {
40 return api.GetBotInfoContext(context.Background(), bot)
41 }
42
43 // GetBotInfoContext will retrieve the complete bot information using a custom context
44 func (api *Client) GetBotInfoContext(ctx context.Context, bot string) (*Bot, error) {
45 values := url.Values{
46 "token": {api.token},
47 }
48
49 if bot != "" {
50 values.Add("bot", bot)
51 }
52
53 response, err := api.botRequest(ctx, "bots.info", values)
54 if err != nil {
55 return nil, err
56 }
57 return &response.Bot, nil
58 }