slack-go / slack

Slack API in Go, originally by @nlopes; Maintainers needed, contact @parsley42
https://pkg.go.dev/github.com/slack-go/slack
BSD 2-Clause "Simplified" License
4.63k stars 1.12k forks source link

Add public version postMethod for set title and other fields of user #1158

Open batazor opened 1 year ago

batazor commented 1 year ago

Description

To set user status, name and other fields in one request

kanata2 commented 1 year ago

Please give me more infomation 😢

batazor commented 1 year ago

I mean to give the possibility to edit not only the username or his status or additional fields but also the time zone, title, and phone number and preferably by calling 1 method

@kanata2 At this moment we do a fork and add a custom method that allows us to change one call to user data - conventionally something like this:

// SetUserProfile will set a profile for the provided user
func (api *Client) SetUserProfile(user string, profile *UserProfile) error {
    return api.SetUserProfileContext(context.Background(), user, profile)
}

// SetUserProfileContext will set a profile for the provided user with a custom context
func (api *Client) SetUserProfileContext(ctx context.Context, user string, profile *UserProfile) error {
    data := map[string]interface{}{
        "profile": profile,
    }

    if user != "" {
        data["user"] = user
    }

    jsonProfile, err := json.Marshal(data)
    if err != nil {
        return err
    }

    response := &userResponseFull{}
    if err = api.jsonMethod(ctx, "users.profile.set", jsonProfile, response); err != nil {
        return err
    }

    return response.Err()
}
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.