Merge pull request #25 from Neur0toxine/send-reactions
add reaction sending support for Instagram
This commit is contained in:
commit
20736ef44d
3 changed files with 53 additions and 1 deletions
|
@ -81,7 +81,7 @@ type IGMessageReaction struct {
|
||||||
// Mid is a message ID.
|
// Mid is a message ID.
|
||||||
Mid string `json:"mid"`
|
Mid string `json:"mid"`
|
||||||
// Action can be {react|unreact}
|
// Action can be {react|unreact}
|
||||||
Action string `json:"action"`
|
Action ReactionAction `json:"action"`
|
||||||
// Reaction is a reaction name. Optional.
|
// Reaction is a reaction name. Optional.
|
||||||
Reaction string `json:"reaction,omitempty"`
|
Reaction string `json:"reaction,omitempty"`
|
||||||
// Emoji is optional.
|
// 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)
|
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.
|
// 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 {
|
||||||
|
|
38
response.go
38
response.go
|
@ -360,6 +360,21 @@ func (r *Response) SenderAction(action SenderAction) (QueryResponse, error) {
|
||||||
return r.DispatchMessage(&m)
|
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.
|
// DispatchMessage posts the message to messenger, return the error if there's any.
|
||||||
func (r *Response) DispatchMessage(m interface{}) (QueryResponse, error) {
|
func (r *Response) DispatchMessage(m interface{}) (QueryResponse, error) {
|
||||||
var res QueryResponse
|
var res QueryResponse
|
||||||
|
@ -549,3 +564,26 @@ type SendSenderAction struct {
|
||||||
Recipient Recipient `json:"recipient"`
|
Recipient Recipient `json:"recipient"`
|
||||||
SenderAction SenderAction `json:"sender_action"`
|
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…
Add table
Reference in a new issue