diff --git a/go.mod b/go.mod index 18da7b6..9085c45 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/retailcrm/messenger +go 1.23.5 + require ( github.com/stretchr/testify v1.2.2 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 diff --git a/message.go b/message.go index 4d31f10..4fe9b80 100644 --- a/message.go +++ b/message.go @@ -81,7 +81,7 @@ type IGMessageReaction struct { // Mid is a message ID. Mid string `json:"mid"` // Action can be {react|unreact} - Action string `json:"action"` + Action ReactionAction `json:"action"` // Reaction is a reaction name. Optional. Reaction string `json:"reaction,omitempty"` // Emoji is optional. diff --git a/messenger.go b/messenger.go index de7b267..66e2dae 100644 --- a/messenger.go +++ b/messenger.go @@ -517,6 +517,20 @@ func (m *Messenger) SenderAction(to Recipient, action SenderAction) (QueryRespon return response.SenderAction(action) } +func (m *Messenger) InstagramReaction( + to Recipient, + mid string, + action ReactionAction, + reaction ...string, +) (QueryResponse, error) { + response := &Response{ + token: m.token, + to: to, + sendAPIVersion: m.sendAPIVersion, + } + return response.InstagramReaction(mid, action, reaction...) +} + // 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 f0c6970..430a24c 100644 --- a/response.go +++ b/response.go @@ -360,6 +360,21 @@ func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) { return r.DispatchMessage(&m) } +// InstagramReaction sends an info about Instagram reaction. +func (r *Response) InstagramReaction(mid string, action ReactionAction, reaction ...string) (QueryResponse, error) { + m := SendInstagramReaction{ + Recipient: r.to, + SenderAction: action, + Payload: SenderInstagramReactionPayload{ + MessageID: mid, + }, + } + if len(reaction) > 0 { + m.Payload.Reaction = reaction[0] + } + return r.DispatchMessage(&m) +} + // DispatchMessage posts the message to messenger, return the error if there's any. func (r *Response) DispatchMessage(m interface{}) (QueryResponse, error) { var res QueryResponse @@ -549,3 +564,26 @@ type SendSenderAction struct { Recipient Recipient `json:"recipient"` SenderAction SenderAction `json:"sender_action"` } + +// ReactionAction contains info about reaction action type. +type ReactionAction string + +const ( + // ReactionActionReact is used when user added a reaction. + ReactionActionReact ReactionAction = "react" + // ReactionActionUnReact is used when user removed a reaction. + ReactionActionUnReact ReactionAction = "unreact" +) + +// SendInstagramReaction is the information about sender action. +type SendInstagramReaction struct { + Recipient Recipient `json:"recipient"` + SenderAction ReactionAction `json:"sender_action"` + Payload SenderInstagramReactionPayload `json:"payload"` +} + +// SenderInstagramReactionPayload contains target message ID and reaction name. +type SenderInstagramReactionPayload struct { + MessageID string `json:"message_id"` + Reaction string `json:"reaction"` +}