Skip to content

Instantly share code, notes, and snippets.

@poonai
Last active March 30, 2022 07:26
Show Gist options
  • Save poonai/bb4ea36435ade9fb825655aa6ec071cf to your computer and use it in GitHub Desktop.
Save poonai/bb4ea36435ade9fb825655aa6ec071cf to your computer and use it in GitHub Desktop.
helper method to send slack message
package x
import (
"os"
"github.com/slack-go/slack"
"go.uber.org/zap"
)
var api = slack.New(os.Getenv("SLACK_TOKEN"))
//SendSlackMsg is to send msg to slack channel
func SendSlackMsg(msg string) {
_, _, err := api.PostMessage(
os.GetEnv("SLACK_CHANNEL_ID"), // get the channel id by clicking on the slack channel on the top
slack.MsgOptionText(msg, false),
)
Logger.Error("error while sending slack alert", zap.String("err_msg", err.Error()), zap.String("msg", msg))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment