Skip to content

Commit

Permalink
Send webhook updates as HTML
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <charlieegan3@users.noreply.github.com>
  • Loading branch information
charlieegan3 committed Jun 28, 2022
1 parent 0d13807 commit df9e76b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 4 additions & 3 deletions cmd/day.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/charlieegan3/airtable-contacts/pkg/webhook"
"github.com/gomarkdown/markdown"
"log"
"time"

Expand Down Expand Up @@ -33,7 +34,7 @@ var dayCmd = &cobra.Command{

// set the notification period
periodStart := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day()-1, 0, 0, 0, 0, time.UTC)
alert, title, message, err := specialdays.Generate(records, periodStart, 1, true)
alert, title, body, err := specialdays.Generate(records, periodStart, 1, true)
if err != nil {
log.Fatalf("failed to generate alert message: %s", err)
}
Expand All @@ -43,7 +44,7 @@ var dayCmd = &cobra.Command{
// notify via pushover
pushoverRecipient := psh.NewRecipient(viper.GetString("pushover.user_key"))
pushoverApp := psh.New(viper.GetString("pushover.app_token"))
err := pushover.Notify(pushoverApp, pushoverRecipient, title, message)
err := pushover.Notify(pushoverApp, pushoverRecipient, title, body)
if err != nil {
log.Fatalf("failed to send notification via pushover")
}
Expand All @@ -52,7 +53,7 @@ var dayCmd = &cobra.Command{
err = webhook.Send(
viper.GetString("webhook.endpoint"),
title,
message,
string(markdown.ToHTML([]byte(body), nil, nil)),
"https://airtable.com",
)
if err != nil {
Expand Down
16 changes: 9 additions & 7 deletions cmd/week.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/charlieegan3/airtable-contacts/pkg/webhook"
"github.com/gomarkdown/markdown"
"log"
"time"

Expand Down Expand Up @@ -33,9 +34,9 @@ var weekCmd = &cobra.Command{

// set the notification period
periodStart := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
alert, title, message, err := specialdays.Generate(records, periodStart, 14, false)
alert, title, body, err := specialdays.Generate(records, periodStart, 14, false)
if err != nil {
log.Fatalf("failed to generate alert message: %s", err)
log.Fatalf("failed to generate alert body: %s", err)
}

// send the alert if needed
Expand All @@ -49,17 +50,17 @@ var weekCmd = &cobra.Command{
pushoverApp,
pushoverRecipient,
title,
message,
body,
)
if err != nil {
log.Fatalf("failed to send message: %s", err)
log.Fatalf("failed to send body: %s", err)
}

// notify via webhook
err = webhook.Send(
viper.GetString("webhook.endpoint"),
title,
message,
string(markdown.ToHTML([]byte(body), nil, nil)),
"https://airtable.com",
)
if err != nil {
Expand All @@ -76,14 +77,15 @@ var weekCmd = &cobra.Command{
body,
)
if err != nil {
log.Fatalf("failed to send message: %s", err)
log.Fatalf("failed to send body: %s", err)
}

// notify via webhook
err = webhook.Send(
viper.GetString("webhook.endpoint"),
title,
body,

string(markdown.ToHTML([]byte(body), nil, nil)),
"https://airtable.com",
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/charlieegan3/special-days v0.0.0-20210701231319-175bc74510e3
github.com/disintegration/imaging v1.6.2
github.com/emersion/go-vcard v0.0.0-20210521075357-3445b9171995
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb // indirect
github.com/gregdel/pushover v1.1.0
github.com/maxatome/go-testdeep v1.10.0
github.com/mehanizm/airtable v0.2.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb h1:5b/eFaSaKPFG9ygDBaPKkydKU5nFJYk08g9jPIVogMg=
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down

0 comments on commit df9e76b

Please sign in to comment.