mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-02 03:32:14 +00:00
Add support for multiple webhooks
This commit is contained in:
parent
d43fe6afbe
commit
b4a4ce6cb2
3 changed files with 11 additions and 9 deletions
|
@ -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=
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
if len(err) > 0 {
|
||||
fmt.Printf("error: %s\n", err)
|
||||
for _, webhook := range SlackWebhooks {
|
||||
err := slack.Send(webhook, "", payload)
|
||||
if len(err) > 0 {
|
||||
fmt.Print(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue