Add support for multiple webhooks

This commit is contained in:
Daniel Mason 2021-09-02 14:56:36 +12:00
parent d43fe6afbe
commit b4a4ce6cb2
Signed by: idanoo
GPG key ID: 387387CDBC02F132
3 changed files with 11 additions and 9 deletions

View file

@ -1,8 +1,8 @@
SOURCE_REPO=https://github.com/minhealthnz/nz-covid-data.git // Source repo
DISCORD_WEBHOOKS= // Comma Separated!
DISCORD_WEBHOOKS= // Comma separated
SLACK_WEBHOOK=
SLACK_WEBHOOKS= // Comma separated
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=

View file

@ -21,8 +21,8 @@ func main() {
// Fetch discord webhooks
nzcovidbot.DiscordWebhooks = strings.Split(os.Getenv("DISCORD_WEBHOOKS"), ",")
// Fetch slack webhook
nzcovidbot.SlackWebhook = os.Getenv("SLACK_WEBHOOK")
// Fetch slack webhooks
nzcovidbot.SlackWebhooks = strings.Split(os.Getenv("SLACK_WEBHOOKS"), ",")
// Fetch twitter keys
nzcovidbot.TwitterCreds = nzcovidbot.TwitterCredentials{

View file

@ -8,10 +8,10 @@ import (
)
// Slack webhook URL
var SlackWebhook string
var SlackWebhooks []string
func postToSlack() {
if SlackWebhook == "" {
if len(SlackWebhooks) == 0 {
return
}
@ -32,8 +32,10 @@ func postToSlack() {
Attachments: []slack.Attachment{attachment1},
}
err := slack.Send(SlackWebhook, "", payload)
for _, webhook := range SlackWebhooks {
err := slack.Send(webhook, "", payload)
if len(err) > 0 {
fmt.Printf("error: %s\n", err)
fmt.Print(err)
}
}
}