1
0
mirror of synced 2025-03-27 10:13:53 +03:00

add reaction sending support for Instagram

This commit is contained in:
Pavel 2025-03-21 16:08:48 +03:00
parent f017927e56
commit 23ed06d035
4 changed files with 55 additions and 1 deletions

2
go.mod
View File

@ -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

View File

@ -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.

View File

@ -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 {

View File

@ -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"`
}