Update slack to push linkable attachments

This commit is contained in:
Daniel Mason 2021-09-07 13:37:11 +12:00
parent 45a6b9e9df
commit 7b654c0bf0
Signed by: idanoo
GPG key ID: 387387CDBC02F132
3 changed files with 51 additions and 24 deletions

View file

@ -7,7 +7,7 @@ import (
"github.com/ashwanthkumar/slack-go-webhook"
)
// Slack webhook URL
// Slack webhook#channel
var SlackWebhooks []string
func postToSlack() {
@ -15,29 +15,26 @@ func postToSlack() {
return
}
postableData := getPostableSlackData()
if len(postableData) == 0 {
attachmentData := getPostableSlackData()
if len(attachmentData) == 0 {
return
}
rawText := strings.Join(postableData, "\n")
attachment1 := slack.Attachment{}
attachment1.Text = &rawText
payload := slack.Payload{
Text: "New Locations of Interest!",
Username: "NZCovidTracker",
Channel: "#covid-19-locations",
IconUrl: "https://www.skids.co.nz/wp-content/uploads/2020/08/download.png",
Attachments: []slack.Attachment{attachment1},
}
for _, webhook := range SlackWebhooks {
if webhook == "" {
continue
}
err := slack.Send(webhook, "", payload)
parts := strings.Split(webhook, "!")
payload := slack.Payload{
Text: "New Locations of Interest!",
Username: "NZCovidTracker",
Channel: "#" + parts[1],
IconUrl: "https://www.skids.co.nz/wp-content/uploads/2020/08/download.png",
Attachments: attachmentData,
}
err := slack.Send(parts[0], "", payload)
if len(err) > 0 {
fmt.Print(err)
}