From 5bdc2eb8047bae2c023b9940390d05e265c7e081 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 29 Jul 2022 15:40:30 +0300 Subject: [PATCH] Sender actions support --- actions.go | 17 +++++++++++++++++ messenger.go | 9 +++++++++ response.go | 8 ++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/actions.go b/actions.go index f478203..bc50220 100644 --- a/actions.go +++ b/actions.go @@ -24,3 +24,20 @@ const ( // status. AccountLinkingAction ) + +// SenderAction is used to send a specific action (event) to the Facebook. +// The result of sending said action is supposed to give more interactivity to the bot. +type SenderAction string + +const ( + // MarkSeen marks message as seen. + MarkSeen SenderAction = "MARK_SEEN" + // TypingOn turns on "Bot is typing..." indicator. + TypingOn SenderAction = "TYPING_ON" + // TypingOff turns off typing indicator. + TypingOff SenderAction = "TYPING_OFF" + // React to the message. + React SenderAction = "REACT" + // Unreact to the message (remove reaction). + Unreact SenderAction = "UNREACT" +) diff --git a/messenger.go b/messenger.go index 7e574df..de7b267 100644 --- a/messenger.go +++ b/messenger.go @@ -508,6 +508,15 @@ func (m *Messenger) EnableChatExtension(homeURL HomeURL) error { return checkFacebookError(resp.Body) } +func (m *Messenger) SenderAction(to Recipient, action SenderAction) (QueryResponse, error) { + response := &Response{ + token: m.token, + to: to, + sendAPIVersion: m.sendAPIVersion, + } + return response.SenderAction(action) +} + // classify determines what type of message a webhook event is. func (m *Messenger) classify(info MessageInfo) Action { if info.Message != nil { diff --git a/response.go b/response.go index d2db26c..252353a 100644 --- a/response.go +++ b/response.go @@ -352,8 +352,8 @@ func (r *Response) ListTemplate(elements *[]StructuredMessageElement, messagingT return r.DispatchMessage(&m) } -// SenderAction sends a info about sender action. -func (r *Response) SenderAction(action string) (QueryResponse, error) { +// SenderAction sends an info about sender action. +func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) { m := SendSenderAction{ Recipient: r.to, SenderAction: action, @@ -547,6 +547,6 @@ type StructuredMessageButton struct { // SendSenderAction is the information about sender action. type SendSenderAction struct { - Recipient Recipient `json:"recipient"` - SenderAction string `json:"sender_action"` + Recipient Recipient `json:"recipient"` + SenderAction SenderAction `json:"sender_action"` }