Edits history of script submission #13981 for ' Create Slack Channel (slack)'

  • go
    package inner
    
    import (
    	"errors"
    
    	"github.com/rs/zerolog/log"
    	"github.com/slack-go/slack"
    )
    
    // creates a new external channel in slack and returns the channel ID
    // requires a token, channel name, and privacy setting for the channel as input
    func main(token string, channelName string, private bool) (interface{}, error) {
    	if channelName == "" {
    		return nil, errors.New("no channel name provided, skipping channel creation")
    	}
    
    	log.Info().Str("channel", channelName).Bool("private", private).Msg("creating new channel")
    
    	// setup slack api
    	api := slack.New(token)
    
    	params := slack.CreateConversationParams{
    		ChannelName: channelName,
    		IsPrivate:   private,
    	}
    
      // create channel
    	channel, err := api.CreateConversation(params)
    	if err != nil {
    		return nil, err
    	}
    
    	return channel.ID, nil
    }
    

    Submitted by sfunkhouser260 376 days ago