package inner
import (
"context"
"github.com/rs/zerolog/log"
"github.com/slack-go/slack"
)
// invite members to an existing channel by email
// provide a token, channel ID and emails of users to retreive and add to a channel
func main(token string, channelID string, emails []string) (interface{}, error) {
api := slack.New(token)
userIDs := []string{}
for _, email := range emails {
user, err := api.GetUserByEmail(email)
if err != nil {
return nil, err
}
userIDs = append(userIDs, user.ID)
}
// nothing to do here, return early
if len(userIDs) == 0 {
log.Info().Msg("no users to add, skipping")
return nil, nil
}
log.Info().Str("channelID", channelID).Strs("email", emails).Msg("inviting user to channel")
_, err := api.InviteUsersToConversationContext(context.Background(), channelID, userIDs...)
if err != nil {
return nil, err
}
return nil, nil
}
Submitted by sfunkhouser260 50 days ago