53 lines
1.2 KiB
Go
Raw Normal View History

2017-08-26 10:53:28 +02:00
package slack
import (
2017-12-01 23:52:25 +01:00
"context"
2017-08-26 10:53:28 +02:00
"net/url"
)
// Bot contains information about a bot
type Bot struct {
ID string `json:"id"`
Name string `json:"name"`
Deleted bool `json:"deleted"`
Icons Icons `json:"icons"`
}
type botResponseFull struct {
Bot `json:"bot,omitempty"` // GetBotInfo
SlackResponse
}
func (api *Client) botRequest(ctx context.Context, path string, values url.Values) (*botResponseFull, error) {
2017-08-26 10:53:28 +02:00
response := &botResponseFull{}
err := api.postMethod(ctx, path, values, response)
2017-08-26 10:53:28 +02:00
if err != nil {
return nil, err
}
if err := response.Err(); err != nil {
return nil, err
2017-08-26 10:53:28 +02:00
}
2017-08-26 10:53:28 +02:00
return response, nil
}
// GetBotInfo will retrieve the complete bot information
func (api *Client) GetBotInfo(bot string) (*Bot, error) {
2017-12-01 23:52:25 +01:00
return api.GetBotInfoContext(context.Background(), bot)
}
// GetBotInfoContext will retrieve the complete bot information using a custom context
func (api *Client) GetBotInfoContext(ctx context.Context, bot string) (*Bot, error) {
2017-08-26 10:53:28 +02:00
values := url.Values{
"token": {api.token},
2017-08-26 10:53:28 +02:00
"bot": {bot},
}
response, err := api.botRequest(ctx, "bots.info", values)
2017-08-26 10:53:28 +02:00
if err != nil {
return nil, err
}
return &response.Bot, nil
}