Created
February 4, 2019 16:11
-
-
Save aeppert/bf0ce8cdfba8f4cf829d0ca88452ed44 to your computer and use it in GitHub Desktop.
Send a message to Slack
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
package main | |
import ( | |
"os" | |
"fmt" | |
"github.com/bluele/slack" | |
) | |
var ( | |
Version string | |
Build string | |
) | |
const ( | |
token = "YOUR_SLACK_TOKEN_HERE" | |
) | |
func usage() { | |
fmt.Println("usage: send_to_slack <username> <channel> <message>"); | |
} | |
func logError(arg error) { | |
fmt.Println("Error:", arg) | |
os.Exit(1) | |
} | |
func main() { | |
if len(os.Args) < 4 { | |
usage() | |
os.Exit(1) | |
} | |
api := slack.New(token) | |
channel, err := api.FindChannelByName(os.Args[2]) | |
if err != nil { | |
logError(err) | |
} | |
err = api.ChatPostMessage(channel.Id, os.Args[3], &slack.ChatPostMessageOpt{ Username: os.Args[1] }) | |
if err != nil { | |
logError(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment