From 23ed06d035a74b1950839c571fe40fc5d48e91e1 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 21 Mar 2025 16:08:48 +0300 Subject: [PATCH 1/2] add reaction sending support for Instagram --- go.mod | 2 ++ message.go | 2 +- messenger.go | 14 ++++++++++++++ response.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) 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"` +} From 99c9a7ba008578f29bdb0c4c9e642d1c21496908 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 21 Mar 2025 16:13:25 +0300 Subject: [PATCH 2/2] remove Go version that was carelessly added by IDE --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 9085c45..18da7b6 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,5 @@ 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