2021-07-07 10:05:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PayloadType string
|
|
|
|
|
|
|
|
const (
|
2023-04-25 19:59:17 +00:00
|
|
|
PayloadTypeText PayloadType = "text"
|
|
|
|
PayloadTypeMarkdown PayloadType = "markdown"
|
|
|
|
PayloadTypeNotice PayloadType = "notice"
|
2021-07-07 10:05:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Payload struct {
|
|
|
|
Type PayloadType `json:"type"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
RoomID string `json:"roomID"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Payload) Validate(defaultRoom *string) error {
|
|
|
|
if p.Type == "" {
|
|
|
|
p.Type = PayloadTypeText
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.RoomID == "" && defaultRoom != nil {
|
|
|
|
p.RoomID = *defaultRoom
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Message == "" {
|
|
|
|
return errors.New("'message' is required")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.RoomID == "" {
|
|
|
|
return errors.New("'roomID' is required")
|
|
|
|
}
|
|
|
|
|
2021-12-05 15:30:58 +00:00
|
|
|
p.RoomID = getRoom(p.RoomID)
|
2021-07-07 10:05:36 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|