add reaction sending support for Instagram
This commit is contained in:
parent
f017927e56
commit
23ed06d035
2
go.mod
2
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
|
||||
|
@ -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.
|
||||
|
14
messenger.go
14
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 {
|
||||
|
38
response.go
38
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"`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user