mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-02 11:42:15 +00:00
Add slack webhook integration
This commit is contained in:
parent
c109f08589
commit
1718cc052d
9 changed files with 107 additions and 5 deletions
39
internal/nzcovidbot/slack.go
Normal file
39
internal/nzcovidbot/slack.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package nzcovidbot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ashwanthkumar/slack-go-webhook"
|
||||
)
|
||||
|
||||
// Slack webhook URL
|
||||
var SlackWebhook string
|
||||
|
||||
func postToSlack() {
|
||||
if SlackWebhook == "" {
|
||||
return
|
||||
}
|
||||
|
||||
postableData := getPostableSlackData()
|
||||
if len(postableData) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
attachment1 := slack.Attachment{}
|
||||
for _, v := range postableData {
|
||||
attachment1.AddField(slack.Field{Value: v})
|
||||
}
|
||||
|
||||
payload := slack.Payload{
|
||||
Text: "New Locations of Interest!",
|
||||
Username: "NZCovidTracker",
|
||||
Channel: "#covid-19",
|
||||
IconUrl: "https://www.skids.co.nz/wp-content/uploads/2020/08/download.png",
|
||||
Attachments: []slack.Attachment{attachment1},
|
||||
}
|
||||
|
||||
err := slack.Send(SlackWebhook, "", payload)
|
||||
if len(err) > 0 {
|
||||
fmt.Printf("error: %s\n", err)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue