-
Notifications
You must be signed in to change notification settings - Fork 1
/
openmessaging_content.go
33 lines (28 loc) · 1.21 KB
/
openmessaging_content.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package gcloudcx
import (
"encoding/json"
"github.com/gildas/go-core"
"github.com/gildas/go-errors"
)
type OpenMessageContent struct {
Type string `json:"contentType"` // Attachment, Location, QuickReply, ButtonResponse, Notification, GenericTemplate, ListTemplate, Postback, Reactions, Mention
Template *OpenMessageTemplate `json:"template,omitempty"`
Attachment *OpenMessageAttachment `json:"attachment,omitempty"`
}
// UnmarshalJSON unmarshals JSON into this
func (content *OpenMessageContent) UnmarshalJSON(payload []byte) (err error) {
type surrogate OpenMessageContent
var inner surrogate
if err = json.Unmarshal(payload, &inner); err != nil {
return errors.JSONUnmarshalError.Wrap(err)
}
*content = OpenMessageContent(inner)
// if !Contains([]string{"Attachment", "Location", "QuickReply", "ButtonResponse", "Notification", "GenericTemplate", "ListTemplate", "Postback", "Reactions", "Mention"}, content.Type) {
if !core.Contains([]string{"Attachment", "Notification"}, content.Type) {
return errors.ArgumentInvalid.With("contentType", content.Type)
}
if content.Template == nil && content.Attachment == nil {
return errors.ArgumentMissing.With("template/attachment")
}
return
}