Add handler for AccountLinking process
This commit is contained in:
parent
88d6aeb77e
commit
0f9e821889
@ -20,4 +20,7 @@ const (
|
||||
OptInAction
|
||||
// ReferralAction represents ?ref parameter in m.me URLs
|
||||
ReferralAction
|
||||
// AccountLinkingAction means that the event concerns changes in account linking
|
||||
// status.
|
||||
AccountLinkingAction
|
||||
)
|
||||
|
13
message.go
13
message.go
@ -60,6 +60,19 @@ type PostBack struct {
|
||||
Referral Referral `json:"referral"`
|
||||
}
|
||||
|
||||
type AccountLinking struct {
|
||||
// Sender is who the message was sent from.
|
||||
Sender Sender `json:"-"`
|
||||
// Recipient is who the message was sent to.
|
||||
Recipient Recipient `json:"-"`
|
||||
// Time is when the message was sent.
|
||||
Time time.Time `json:"-"`
|
||||
// Status represents the new account linking status.
|
||||
Status string `json:"status"`
|
||||
// AuthorizationCode is a pass-through code set during the linking process.
|
||||
AuthorizationCode string `json:"authorization_code"`
|
||||
}
|
||||
|
||||
// Watermark is the RawWatermark timestamp rendered as a time.Time.
|
||||
func (d Delivery) Watermark() time.Time {
|
||||
return time.Unix(d.RawWatermark/int64(time.Microsecond), 0)
|
||||
|
20
messenger.go
20
messenger.go
@ -59,6 +59,10 @@ type OptInHandler func(OptIn, *Response)
|
||||
// ReferralHandler is a handler used postback callbacks.
|
||||
type ReferralHandler func(ReferralMessage, *Response)
|
||||
|
||||
// AccountLinkingHandler is a handler used to react to an account
|
||||
// being linked or unlinked.
|
||||
type AccountLinkingHandler func(AccountLinking, *Response)
|
||||
|
||||
// Messenger is the client which manages communication with the Messenger Platform API.
|
||||
type Messenger struct {
|
||||
mux *http.ServeMux
|
||||
@ -68,6 +72,7 @@ type Messenger struct {
|
||||
postBackHandlers []PostBackHandler
|
||||
optInHandlers []OptInHandler
|
||||
referralHandlers []ReferralHandler
|
||||
accountLinkingHandlers []AccountLinkingHandler
|
||||
token string
|
||||
verifyHandler func(http.ResponseWriter, *http.Request)
|
||||
verify bool
|
||||
@ -131,6 +136,11 @@ func (m *Messenger) HandleReferral(f ReferralHandler) {
|
||||
m.referralHandlers = append(m.referralHandlers, f)
|
||||
}
|
||||
|
||||
// HandleAccountLinking adds a new AccountLinkingHandler to the Messenger
|
||||
func (m *Messenger) HandleAccountLinking(f AccountLinkingHandler) {
|
||||
m.accountLinkingHandlers = append(m.accountLinkingHandlers, f)
|
||||
}
|
||||
|
||||
// Handler returns the Messenger in HTTP client form.
|
||||
func (m *Messenger) Handler() http.Handler {
|
||||
return m.mux
|
||||
@ -370,6 +380,14 @@ func (m *Messenger) dispatch(r Receive) {
|
||||
message.Time = time.Unix(info.Timestamp/int64(time.Microsecond), 0)
|
||||
f(message, resp)
|
||||
}
|
||||
case AccountLinkingAction:
|
||||
for _, f := range m.accountLinkingHandlers {
|
||||
message := *info.AccountLinking
|
||||
message.Sender = info.Sender
|
||||
message.Recipient = info.Recipient
|
||||
message.Time = time.Unix(info.Timestamp/int64(time.Microsecond), 0)
|
||||
f(message, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,6 +449,8 @@ func (m *Messenger) classify(info MessageInfo, e Entry) Action {
|
||||
return OptInAction
|
||||
} else if info.ReferralMessage != nil {
|
||||
return ReferralAction
|
||||
} else if info.AccountLinking != nil {
|
||||
return AccountLinkingAction
|
||||
}
|
||||
return UnknownAction
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ type MessageInfo struct {
|
||||
OptIn *OptIn `json:"optin"`
|
||||
|
||||
ReferralMessage *ReferralMessage `json:"referral"`
|
||||
|
||||
AccountLinking *AccountLinking `json:"account_linking"`
|
||||
}
|
||||
|
||||
type OptIn struct {
|
||||
|
Loading…
Reference in New Issue
Block a user