return ErrIrrelevantMessage and log http server ignored messages
parent
feb48ee4bc
commit
c0977a6b7a
7
main.go
7
main.go
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -130,14 +131,18 @@ func _newHandlerPostAPIV1EventsSlack(cfg Config) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := ParseSlack(b)
|
m, err := ParseSlack(b)
|
||||||
if err != nil {
|
if errors.Is(err, ErrIrrelevantMessage) {
|
||||||
|
return
|
||||||
|
} else if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cfg.storage.Upsert(r.Context(), m); err != nil {
|
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)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("ingested %+v", m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrIrrelevantMessage = errors.New("message isnt relevant to spoc bot vr")
|
||||||
|
)
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID string
|
ID string
|
||||||
TS uint64
|
TS uint64
|
||||||
|
|
@ -109,9 +113,9 @@ func ParseSlack(b []byte) (Message, error) {
|
||||||
|
|
||||||
if s.Event.Bot.Name != "" {
|
if s.Event.Bot.Name != "" {
|
||||||
if len(s.Event.Attachments) == 0 {
|
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: ") {
|
} 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{
|
return Message{
|
||||||
ID: fmt.Sprintf("%s/%v", s.Event.ID, s.TS),
|
ID: fmt.Sprintf("%s/%v", s.Event.ID, s.TS),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue