-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_api.go
160 lines (130 loc) · 3.06 KB
/
webhook_api.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package fbmbotapi
//go:generate ffjson $GOFILE
import (
"time"
)
// ReceivedMessage ...
type ReceivedMessage struct {
Object string `json:"object"`
Entries []Entry `json:"entry"`
}
// Entry hold entry data
type Entry struct {
ID string `json:"id"`
Time int64 `json:"time"`
Messaging []Messaging `json:"messaging"`
}
// GetID returns ID
func (e Entry) GetID() interface{} {
return e.ID
}
// GetTime returns time of the message
func (e Entry) GetTime() time.Time {
return time.Unix(e.Time, 0)
}
// Messaging ...
type Messaging struct {
Sender Sender `json:"sender"`
Recipient Recipient `json:"recipient"`
Timestamp int64 `json:"timestamp"`
Message *Message `json:"message"`
Postback *Postback `json:"postback"`
Delivery *Delivery `json:"delivery"`
}
// Actor represents actor
type Actor struct {
ID string `json:"id"`
}
// GetID returns ID of the actor
func (a Actor) GetID() interface{} {
return a.ID
}
// GetFirstName returns first name
func (a Actor) GetFirstName() string {
return "First" //TODO: Make call to API
}
// GetLastName returns last name
func (a Actor) GetLastName() string {
return "Last" //TODO: Make call to API
}
// GetUserName returns username
func (a Actor) GetUserName() string {
return "Username" //TODO: Make call to API
}
// Platform returns "fbm"
func (a Actor) Platform() string {
return "fbm"
}
// Sender represents sender
type Sender struct {
Actor
}
// IsBotUser returns false
func (Actor) IsBotUser() bool {
return false
}
// GetAvatar is not supported or not implemented yet
func (Actor) GetAvatar() string {
return ""
}
// GetLanguage returns preferred language (not implemented yet)
func (Actor) GetLanguage() string {
return "" // TODO: Check if we can return actual
}
// Recipient represents recipient
type Recipient struct {
Actor
}
// Postback message
type Postback struct {
Title string `json:"title"`
Payload string `json:"payload"`
}
// Delivery message
type Delivery struct {
Watermark int64 `json:"watermark"`
MessageIDs MessageIDs `json:"mids"`
}
// MessageID defines message ID
type MessageID string
// MessageIDs defiens message IDs
type MessageIDs []MessageID
// Message defines message
type Message struct {
MID string `json:"mid"`
Seq int `json:"seq"`
MText string `json:"text"`
Attachments []Attachment `json:"attachments"`
}
// Attachment defines attachment
type Attachment struct {
Type string `json:"type"`
Payload Payload `json:"paylaod"`
}
// Payload defines payload
type Payload struct {
URL string `json:"url"`
}
// SendMessage ...
type SendMessage struct {
Recipient Recipient `json:"recipient"`
Message struct {
Text string `json:"text"`
} `json:"message"`
}
// IntID not supported
func (m Message) IntID() int64 {
panic("Not supported")
}
// StringID returns message ID as string
func (m Message) StringID() string {
return m.MID
}
// Sequence returns Seq of message
func (m Message) Sequence() int {
return m.Seq
}
// Text returns text of the message
func (m Message) Text() string {
return m.MText
}