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 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_KEY=
TWITTER_CONSUMER_SECRET= TWITTER_CONSUMER_SECRET=

View file

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

View file

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