66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package chat
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"net/http"
|
||
"net/url"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
)
|
||
|
||
type GetUserChatColorParams struct {
|
||
// The ID of the user whose username color you want to get.
|
||
// To specify more than one user, include the user_id parameter for each user to get.
|
||
// For example, &user_id=1234&user_id=5678. The maximum number of IDs that you may specify is 100.
|
||
//
|
||
// The API ignores duplicate IDs and IDs that weren’t found.
|
||
UserIDs []string `url:"user_id"`
|
||
}
|
||
|
||
type GetUserChatColorResponse struct {
|
||
// The list of users and the color code they use for their name.
|
||
Data []UserChatColor `json:"data"`
|
||
}
|
||
|
||
type UserChatColor struct {
|
||
// An ID that uniquely identifies the user.
|
||
UserID string `json:"user_id"`
|
||
|
||
// The user’s login name.
|
||
UserLogin string `json:"user_login"`
|
||
|
||
// The user’s display name.
|
||
UserName string `json:"user_name"`
|
||
|
||
// The Hex color code that the user uses in chat for their name.
|
||
// If the user hasn’t specified a color in their settings, the string is empty.
|
||
Color string `json:"color"`
|
||
}
|
||
|
||
// Gets the color used for the user’s name in chat.
|
||
//
|
||
// Requires an app access token or user access token.
|
||
func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorParams) (*GetUserChatColorResponse, error) {
|
||
v, _ := query.Values(params)
|
||
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/color", RawQuery: v.Encode()})
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
res, err := c.client.Do(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer res.Body.Close()
|
||
|
||
var data GetUserChatColorResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|