mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-02 11:42:15 +00:00
Update slack to push linkable attachments
This commit is contained in:
parent
45a6b9e9df
commit
7b654c0bf0
3 changed files with 51 additions and 24 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue