Created
April 6, 2021 15:06
-
-
Save xNok/105f0c585113b38d8f93989217160e68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ConnectToSlackViaSocketmode() (*socketmode.Client, error) { | |
appToken := os.Getenv("SLACK_APP_TOKEN") | |
if appToken == "" { | |
return nil, errors.New("SLACK_APP_TOKEN must be set") | |
} | |
if !strings.HasPrefix(appToken, "xapp-") { | |
return nil, errors.New("SLACK_APP_TOKEN must have the prefix \"xapp-\".") | |
} | |
botToken := os.Getenv("SLACK_BOT_TOKEN") | |
if botToken == "" { | |
return nil, errors.New("SLACK_BOT_TOKEN must be set.") | |
} | |
if !strings.HasPrefix(botToken, "xoxb-") { | |
return nil, errors.New("SLACK_BOT_TOKEN must have the prefix \"xoxb-\".") | |
} | |
api := slack.New( | |
botToken, | |
slack.OptionDebug(true), | |
slack.OptionAppLevelToken(appToken), | |
slack.OptionLog(log.New(os.Stdout, "api: ", log.Lshortfile|log.LstdFlags)), | |
) | |
client := socketmode.New( | |
api, | |
socketmode.OptionDebug(true), | |
socketmode.OptionLog(log.New(os.Stdout, "socketmode: ", log.Lshortfile|log.LstdFlags)), | |
) | |
return client, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment