owncast-webhook/internal/web/controller/webhook/owncast/chat_message.go

36 lines
845 B
Go

package owncast
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
"gitnet.fr/deblan/owncast-webhook/internal/config"
"gitnet.fr/deblan/owncast-webhook/internal/store"
webhook "gitnet.fr/deblan/owncast-webhook/internal/web/webhook/owncast"
)
type Controller struct {
}
func New(e *echo.Echo) *Controller {
c := Controller{}
e.POST(fmt.Sprintf("/webhook/%s/owncast/chat_message", config.Get().Server.WebhookSecret), c.ChatMessage)
return &c
}
func (ctrl *Controller) ChatMessage(c echo.Context) error {
value := new(webhook.WebhookNewMessage)
if err := c.Bind(value); err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"status": "ko"})
}
store.GetMessageStore().Add(store.OwncastMessage{
WebhookMessage: value.EventData,
})
return c.JSON(http.StatusCreated, map[string]string{"status": "ok"})
}