mirror of
https://github.com/nikoksr/notify.git
synced 2024-11-24 08:22:18 +02:00
1.6 KiB
1.6 KiB
Slack Usage
Ensure that you have already navigated to your GOPATH and installed the following packages:
go get -u github.com/nikoksr/notify
go get github.com/slack-go/slack
- You might need this one too
Steps for Slack App
These are general and very high level instructions
- Create a new Slack App
- Give your bot/app the following OAuth permission scopes:
chat:write
,chat:write.public
- Copy your Bot User OAuth Access Token for usage below
- Copy the Channel ID of the channel you want to post a message to. You can grab the Channel ID by right clicking a channel and selecting
copy link
. Your Channel ID will be in that link. - Now you should be good to use the code below
Sample Code
package main
import (
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/slack"
)
func main() {
notifier := notify.New()
// Provide your Slack OAuth Access Token
slackService := slack.New("OAUTH_TOKEN")
// Passing a Slack channel id as receiver for our messages.
// Where to send our messages.
slackService.AddReceivers("CHANNEL_ID")
// Tell our notifier to use the Slack service. You can repeat the above process
// for as many services as you like and just tell the notifier to use them.
notifier.UseService(slackService)
// Send a message
_ = notifier.Send(
"Hello :wave:\n",
"I am a bot written in Go!",
)
// Code isn't working and need to debug? Use this code below:
// x := notifier.Send(
// "Hello :wave:\n",
// "I am a bot written in Go!",
// )
// if x != nil {
// fmt.Println(x)
// }
}