-
Notifications
You must be signed in to change notification settings - Fork 8
/
message.go
129 lines (113 loc) · 3.27 KB
/
message.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package linebot
// MessageType ...
type MessageType string
// MessageType ...
const (
MessageTypeText MessageType = "text"
MessageTypeImage MessageType = "image"
MessageTypeVideo MessageType = "video"
MessageTypeAudio MessageType = "audio"
MessageTypeLocation MessageType = "location"
MessageTypeSticker MessageType = "sticker"
MessageTypeTemplate MessageType = "template"
MessageTypeImagemap MessageType = "imagemap"
)
// Message ...
type Message interface {
message()
}
// TextMessage ...
type TextMessage struct {
Type MessageType `json:"type"`
Text string `json:"text"`
}
// ImageMessage ...
type ImageMessage struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
}
// VideoMessage ...
type VideoMessage struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
}
// AudioMessage ...
type AudioMessage struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
Duration int `json:"duration"`
}
// LocationMessage ...
type LocationMessage struct {
Type MessageType `json:"type"`
Title string `json:"title"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
// StickerMessage ...
type StickerMessage struct {
Type MessageType `json:"type"`
PackageID string `json:"packageId"`
StickerID string `json:"stickerId"`
}
// Message interface
func (*TextMessage) message() {}
func (*ImageMessage) message() {}
func (*VideoMessage) message() {}
func (*AudioMessage) message() {}
func (*LocationMessage) message() {}
func (*StickerMessage) message() {}
func (*TemplateMessage) message() {}
func (*ImagemapMessage) message() {}
// NewTextMessage ...
func NewTextMessage(text string) *TextMessage {
m := new(TextMessage)
m.Type = MessageTypeText
m.Text = text
return m
}
// NewImageMessage ...
func NewImageMessage(originalContentURL, previewImageURL string) *ImageMessage {
m := new(ImageMessage)
m.Type = MessageTypeImage
m.OriginalContentURL = originalContentURL
m.PreviewImageURL = previewImageURL
return m
}
// NewVideoMessage ...
func NewVideoMessage(originalContentURL, previewImageURL string) *VideoMessage {
m := new(VideoMessage)
m.Type = MessageTypeVideo
m.OriginalContentURL = originalContentURL
m.PreviewImageURL = previewImageURL
return m
}
// NewAudioMessage ...
func NewAudioMessage(originalContentURL string, duration int) *AudioMessage {
m := new(AudioMessage)
m.Type = MessageTypeAudio
m.OriginalContentURL = originalContentURL
m.Duration = duration
return m
}
// NewLocationMessage ...
func NewLocationMessage(title, address string, latitude, longitude float64) *LocationMessage {
m := new(LocationMessage)
m.Type = MessageTypeLocation
m.Title = title
m.Address = address
m.Latitude = latitude
m.Longitude = longitude
return m
}
// NewStickerMessage ...
func NewStickerMessage(packageID, stickerID string) *StickerMessage {
m := new(StickerMessage)
m.Type = MessageTypeSticker
m.PackageID = packageID
m.StickerID = stickerID
return m
}