return ErrIrrelevantMessage and log http server ignored messages
This commit is contained in:
7
main.go
7
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -130,14 +131,18 @@ func _newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
|
||||
}
|
||||
|
||||
m, err := ParseSlack(b)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrIrrelevantMessage) {
|
||||
return
|
||||
} else if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := cfg.storage.Upsert(r.Context(), m); err != nil {
|
||||
log.Printf("failed to ingest %+v: %v", m, err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Printf("ingested %+v", m)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrIrrelevantMessage = errors.New("message isnt relevant to spoc bot vr")
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
ID string
|
||||
TS uint64
|
||||
@@ -109,9 +113,9 @@ func ParseSlack(b []byte) (Message, error) {
|
||||
|
||||
if s.Event.Bot.Name != "" {
|
||||
if len(s.Event.Attachments) == 0 {
|
||||
return Message{}, errors.New("bot message has no attachments")
|
||||
return Message{}, ErrIrrelevantMessage
|
||||
} else if !strings.Contains(s.Event.Attachments[0].Title, ": Firing: ") {
|
||||
return Message{}, errors.New("bot message attachment is not Firing")
|
||||
return Message{}, ErrIrrelevantMessage
|
||||
}
|
||||
return Message{
|
||||
ID: fmt.Sprintf("%s/%v", s.Event.ID, s.TS),
|
||||
|
||||
Reference in New Issue
Block a user