1
0
mirror of synced 2024-11-22 04:46:05 +03:00

Sender actions support

This commit is contained in:
Pavel 2022-07-29 15:40:30 +03:00
parent 243bf4a2b2
commit 5bdc2eb804
3 changed files with 30 additions and 4 deletions

View File

@ -24,3 +24,20 @@ const (
// status. // status.
AccountLinkingAction 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"
)

View File

@ -508,6 +508,15 @@ func (m *Messenger) EnableChatExtension(homeURL HomeURL) error {
return checkFacebookError(resp.Body) 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. // classify determines what type of message a webhook event is.
func (m *Messenger) classify(info MessageInfo) Action { func (m *Messenger) classify(info MessageInfo) Action {
if info.Message != nil { if info.Message != nil {

View File

@ -352,8 +352,8 @@ func (r *Response) ListTemplate(elements *[]StructuredMessageElement, messagingT
return r.DispatchMessage(&m) return r.DispatchMessage(&m)
} }
// SenderAction sends a info about sender action. // SenderAction sends an info about sender action.
func (r *Response) SenderAction(action string) (QueryResponse, error) { func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) {
m := SendSenderAction{ m := SendSenderAction{
Recipient: r.to, Recipient: r.to,
SenderAction: action, SenderAction: action,
@ -547,6 +547,6 @@ type StructuredMessageButton struct {
// SendSenderAction is the information about sender action. // SendSenderAction is the information about sender action.
type SendSenderAction struct { type SendSenderAction struct {
Recipient Recipient `json:"recipient"` Recipient Recipient `json:"recipient"`
SenderAction string `json:"sender_action"` SenderAction SenderAction `json:"sender_action"`
} }