mirror of
https://github.com/nikoksr/notify.git
synced 2025-01-05 22:53:35 +02:00
Merge pull request #15 from GrantBirki/main
docs(usage): adding usage docs for slack
This commit is contained in:
commit
f4b9aba788
60
service/slack/usage.md
Normal file
60
service/slack/usage.md
Normal file
@ -0,0 +1,60 @@
|
||||
# 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
|
||||
|
||||
1. Create a new Slack App
|
||||
2. Give your bot/app the following OAuth permission scopes: `chat:write`, `chat:write.public`
|
||||
3. Copy your *Bot User OAuth Access Token* for usage below
|
||||
4. 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.
|
||||
5. Now you should be good to use the code below
|
||||
|
||||
## Sample Code
|
||||
|
||||
```go
|
||||
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)
|
||||
// }
|
||||
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user