To send a message to a channel in Slack using the Slack API in Go, you can use the github.com/slack-go/slack
package.
Here's an example code block that sends a message to a specified channel:
main.go400 chars25 lines
In this code, SLACK_TOKEN
is an environment variable that should be set to your Slack API token. The PostMessage
method is called with the channel name ("#general"
in this example) and message text. The MsgOptionText
function creates a text message with the specified text and formatting option (false
means no formatting).
The PostMessage
method returns the channel ID and timestamp of the new message, which are logged in the success message.
gistlibby LogSnag